main
vue 97 lines 2.44 KB
Raw
1 <template>
2 <n-spin :show="loading">
3 <div class="flex min-h-52 flex-col gap-2 py-0.5">
4 <template v-if="list.length">
5 <CardEntity
6 v-for="item of list"
7 :key="item.name"
8 embedded
9 clickable
10 hoverable
11 :highlighted="item.name === selected?.name"
12 size="small"
13 @click="setItem(item)"
14 >
15 <template #header>
16 {{ item.name }}
17 </template>
18 <template #default>
19 {{ item.description }}
20 </template>
21 </CardEntity>
22 </template>
23 <template v-else>
24 <n-empty v-if="!loading" description="No items found" class="h-48 justify-center" />
25 </template>
26 </div>
27 </n-spin>
28 </template>
29
30 <script setup lang="ts">
31 import type { MatchingParameter } from "@/types/artifacts"
32 import _uniq from "lodash/uniqBy"
33 import { NEmpty, NSpin, useMessage } from "naive-ui"
34 import { onBeforeMount, ref } from "vue"
35 import Api from "@/api"
36 import CardEntity from "@/components/common/cards/CardEntity.vue"
37 import { getOS } from "@/utils"
38
39 const { techniqueId, parametersList, osList } = defineProps<{
40 techniqueId: string
41 parametersList?: MatchingParameter[] | null
42 osList: string[]
43 }>()
44
45 const emit = defineEmits<{
46 (e: "loaded", value: MatchingParameter[]): void
47 }>()
48
49 const selected = defineModel<MatchingParameter | null>("selected", { default: null })
50
51 const message = useMessage()
52 const loading = ref(false)
53 const list = ref<MatchingParameter[]>([])
54
55 async function getList() {
56 loading.value = true
57
58 try {
59 const proms = []
60 for (const os of osList) {
61 if (getOS(os) === "Linux") {
62 proms.push(Api.artifacts.getParameters("Linux.AttackSimulation.AtomicRedTeam", techniqueId))
63 } else if (getOS(os) === "Windows") {
64 proms.push(Api.artifacts.getParameters("Windows.AttackSimulation.AtomicRedTeam", techniqueId))
65 }
66 }
67
68 const parametersListResponse = await Promise.all(proms)
69
70 let fullList: MatchingParameter[] = []
71
72 for (const res of parametersListResponse) {
73 fullList = [...fullList, ...res.data.matching_parameters]
74 }
75
76 list.value = _uniq(fullList, "name")
77 emit("loaded", list.value)
78 } catch (err: any) {
79 // TODO-FE: remove any
80 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
81 } finally {
82 loading.value = false
83 }
84 }
85
86 function setItem(item: MatchingParameter) {
87 selected.value = selected.value?.name === item.name ? null : item
88 }
89
90 onBeforeMount(() => {
91 if (parametersList?.length) {
92 list.value = parametersList
93 } else {
94 getList()
95 }
96 })
97 </script>