Skip to content

Commit 0a99819

Browse files
authored
Feat: Support DFIQ objects (#140)
Corresponding PR in yeti has been merged
1 parent 570223a commit 0a99819

File tree

12 files changed

+679
-91
lines changed

12 files changed

+679
-91
lines changed

docker/dev/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ RUN apt update && apt install \
44
python3 \
55
git
66

7-
RUN npm install -g n && n 16
8-
97
ADD . /app
108
WORKDIR /app
119

src/components/EditDFIQObject.vue

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<template>
2+
<v-card>
3+
<v-card-title>{{ object.name || object.value }}</v-card-title>
4+
<v-card-subtitle>Editing DFIQ {{ object.type }}</v-card-subtitle>
5+
<v-card-text>
6+
<v-textarea class="yeti-code" label="DFIQ Yaml" auto-grow v-model="object.dfiq_yaml"></v-textarea>
7+
</v-card-text>
8+
9+
<v-card-actions>
10+
<v-btn text="Toggle full screen" color="primary" @click="toggleFullScreen"></v-btn>
11+
<v-spacer></v-spacer>
12+
<v-btn text="Cancel" color="cancel" @click="isActive.value = false"></v-btn>
13+
<v-btn text="Save" color="primary" @click="saveDFIQObject" variant="tonal"></v-btn>
14+
</v-card-actions>
15+
<v-alert v-if="errors.length > 0" type="error">
16+
Error saving DFIQ {{ object.type }}:
17+
<ul>
18+
<li v-for="error in errors">
19+
<strong>{{ error.field }}</strong
20+
>: {{ error.message }}
21+
</li>
22+
</ul>
23+
</v-alert>
24+
</v-card>
25+
</template>
26+
27+
<script lang="ts" setup>
28+
import axios from "axios";
29+
30+
import ObjectFields from "@/components/ObjectFields.vue";
31+
</script>
32+
33+
<script lang="ts">
34+
export default {
35+
components: { ObjectFields },
36+
props: {
37+
object: {
38+
type: Object,
39+
default: () => {}
40+
},
41+
isActive: {
42+
type: Object,
43+
default: () => {}
44+
}
45+
},
46+
data() {
47+
return {
48+
localObject: { ...this.object },
49+
errors: [],
50+
fullScreen: false,
51+
typeToEndpointMapping: {
52+
entity: "entities",
53+
observable: "observables",
54+
indicator: "indicators",
55+
dfiq: "dfiq"
56+
}
57+
};
58+
},
59+
mounted() {},
60+
methods: {
61+
saveDFIQObject() {
62+
let patchRequest = {
63+
dfiq_type: this.object.type,
64+
dfiq_yaml: this.object.dfiq_yaml
65+
};
66+
67+
axios
68+
.patch(`/api/v2/dfiq/${this.object.id}`, patchRequest)
69+
.then(response => {
70+
this.$eventBus.emit("displayMessage", {
71+
message: "DFIQ object succesfully updated",
72+
status: "success"
73+
});
74+
this.$emit("success", response.data);
75+
this.isActive.value = false;
76+
})
77+
.catch(error => {
78+
console.log(error);
79+
this.errors = error.response.data.detail
80+
.filter(detail => detail.loc[1] !== "type")
81+
.map(detail => {
82+
return { field: detail.loc[1], message: detail.msg };
83+
});
84+
})
85+
.finally();
86+
},
87+
toggleFullScreen() {
88+
this.fullScreen = !this.fullScreen;
89+
this.$emit("toggle-fullscreen", this.fullScreen);
90+
}
91+
}
92+
};
93+
</script>
94+
95+
<style>
96+
.yeti-code textarea {
97+
font-family: monospace;
98+
}
99+
</style>

src/components/EditObject.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import axios from "axios";
3030
import { ENTITY_TYPES } from "@/definitions/entityDefinitions.js";
3131
import { INDICATOR_TYPES } from "@/definitions/indicatorDefinitions.js";
3232
import { OBSERVABLE_TYPES } from "@/definitions/observableDefinitions.js";
33+
import { DFIQ_TYPES } from "@/definitions/dfiqDefinitions.js";
3334
import ObjectFields from "@/components/ObjectFields.vue";
3435
import { objectTypeAnnotation } from "@babel/types";
3536
</script>
@@ -55,7 +56,8 @@ export default {
5556
typeToEndpointMapping: {
5657
entity: "entities",
5758
observable: "observables",
58-
indicator: "indicators"
59+
indicator: "indicators",
60+
dfiq: "dfiq"
5961
}
6062
};
6163
},
@@ -101,7 +103,8 @@ export default {
101103
return (
102104
ENTITY_TYPES.find(t => t.type === this.object.type) ||
103105
INDICATOR_TYPES.find(t => t.type === this.object.type) ||
104-
OBSERVABLE_TYPES.find(t => t.type === this.object.type)
106+
OBSERVABLE_TYPES.find(t => t.type === this.object.type) ||
107+
DFIQ_TYPES.find(t => t.type === this.object.type)
105108
);
106109
},
107110
editableFields() {

src/components/ObjectList.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@
1616
<template v-slot:item.name="{ item }">
1717
<span class="short-links">
1818
<v-tooltip activator="parent" location="top" :open-delay="200">{{ item.name }}</v-tooltip>
19-
<router-link
20-
:to="{
21-
name: searchType === 'entities' ? 'EntityDetails' : 'IndicatorDetails',
22-
params: { id: item.id }
23-
}"
24-
>{{ item.name }}</router-link
25-
>
19+
<router-link :to="`${searchType}/${item.id}`">{{ item.name }}</router-link>
2620
</span>
2721
</template>
2822
<template v-slot:item.tags="{ item }">
@@ -37,6 +31,9 @@
3731
<template v-slot:item.relevant_tags="{ item }">
3832
<v-chip v-for="name in item.relevant_tags" :text="name" class="mr-1" size="small"></v-chip>
3933
</template>
34+
<template v-slot:item.dfiq_tags="{ item }">
35+
<v-chip v-for="name in item.dfiq_tags" :text="name" class="mr-1" size="small"></v-chip>
36+
</template>
4037
<template v-slot:item.aliases="{ item }">
4138
<v-chip v-for="value in item.aliases" :text="value" class="mr-1" size="small"></v-chip>
4239
</template>
@@ -54,6 +51,9 @@
5451
<template v-slot:item.created="{ item }">
5552
{{ moment(item.created).format("YYYY-MM-DD HH:mm:ss") }}
5653
</template>
54+
<template v-slot:item.modified="{ item }">
55+
{{ moment(item.modified).format("YYYY-MM-DD HH:mm:ss") }}
56+
</template>
5757
<template v-slot:item.last_seen="{ item }">
5858
{{ moment(item.last_seen).format("YYYY-MM-DD HH:mm:ss") }}
5959
</template>

src/components/RelatedObjects.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@
5757
</router-link>
5858
</span>
5959
</span>
60+
<span v-else-if="node.root_type === 'dfiq'" class="short-links">
61+
<v-icon :icon="getIconForType(node.type)" start size="small"></v-icon>
62+
<span>
63+
<v-tooltip activator="parent" location="top" :open-delay="200">{{ node.name }}</v-tooltip>
64+
<router-link :to="{ name: 'DFIQDetails', params: { id: node.id } }">
65+
{{ node.name }}
66+
</router-link>
67+
</span>
68+
</span>
6069
<span v-else>
6170
<v-chip> {{ node.name }}</v-chip>
6271
</span>
@@ -97,6 +106,7 @@ import axios from "axios";
97106
98107
import { ENTITY_TYPES } from "@/definitions/entityDefinitions.js";
99108
import { INDICATOR_TYPES } from "@/definitions/indicatorDefinitions.js";
109+
import { DFIQ_TYPES } from "@/definitions/dfiqDefinitions.js";
100110
import EditLink from "@/components/EditLink.vue";
101111
import YetiMarkdown from "@/components/YetiMarkdown.vue";
102112
</script>
@@ -135,7 +145,7 @@ export default {
135145
perPage: 20,
136146
total: 0,
137147
loading: false,
138-
objectTypes: ENTITY_TYPES.concat(INDICATOR_TYPES),
148+
objectTypes: ENTITY_TYPES.concat(INDICATOR_TYPES).concat(DFIQ_TYPES),
139149
showEditLink: false
140150
};
141151
},

0 commit comments

Comments
 (0)