diff --git a/backend/pkg/service/model.go b/backend/pkg/service/model.go index bba664b..14f4cd9 100644 --- a/backend/pkg/service/model.go +++ b/backend/pkg/service/model.go @@ -129,5 +129,6 @@ type ExceptionRequest struct { Resource string `json:"resource"` Cluster string `json:"cluster"` Source string `json:"source"` + Category string `json:"category"` Policies []ExceptionPolicy `json:"policies"` } diff --git a/backend/pkg/service/service.go b/backend/pkg/service/service.go index c9d0a69..09d3fe0 100644 --- a/backend/pkg/service/service.go +++ b/backend/pkg/service/service.go @@ -184,17 +184,24 @@ func (s *Service) CreateException(ctx context.Context, req ExceptionRequest) (*p var list *core.Paginated[core.PolicyResult] if len(req.Policies) == 0 { + var categories []string + if req.Category != "" { + categories = []string{req.Category} + } + if resource.Namespace != "" { list, err = client.ListNamespaceScopedResults(ctx, url.Values{ "resource_id": []string{req.Resource}, "status": []string{StatusFail, StatusWarn}, "sources": []string{req.Source}, + "categories": categories, }) } else { list, err = client.ListClusterScopedResults(ctx, url.Values{ "resource_id": []string{req.Resource}, "status": []string{StatusFail, StatusWarn}, "sources": []string{req.Source}, + "categories": categories, }) } if err != nil { diff --git a/frontend/modules/core/api.ts b/frontend/modules/core/api.ts index a1a5502..7f9ed6e 100644 --- a/frontend/modules/core/api.ts +++ b/frontend/modules/core/api.ts @@ -56,8 +56,8 @@ export class CoreAPI { return exec(`/api/config/${this.cluster}/resource/${id}`, { baseURL: this.baseURL, params: filter }) } - createException (id: string, source: string, policies: { name: string, rules: string[] }[]) { - return exec(`/api/config/${this.cluster}/resource/${id}/exception`, { baseURL: this.baseURL, method: "POST", body: { policies, source } }) + createException (id: string, source: string, policies: { name: string, rules: string[] }[], category?: string) { + return exec(`/api/config/${this.cluster}/resource/${id}/exception`, { baseURL: this.baseURL, method: "POST", body: { policies, source, category } }) } policySources (filter?: Filter) { diff --git a/frontend/modules/core/components/resource/ExceptionDialog.vue b/frontend/modules/core/components/resource/ExceptionDialog.vue index 5952815..0e0bd4e 100644 --- a/frontend/modules/core/components/resource/ExceptionDialog.vue +++ b/frontend/modules/core/components/resource/ExceptionDialog.vue @@ -41,6 +41,7 @@ import { parse } from "yaml"; const props = defineProps<{ source: string; resource: string; + category?: string; policies?: { name: string; rules: string[] }[]; height?: string | number; }>() @@ -60,7 +61,7 @@ const request = async () => { loading.value = true try { - const response = await callAPI((api) => api.createException(props.resource, props.source, props.policies)) + const response = await callAPI((api) => api.createException(props.resource, props.source, props.policies, props.category)) content.value = response.resource err.value = undefined diff --git a/frontend/modules/core/components/resource/Item.vue b/frontend/modules/core/components/resource/Item.vue index 7d36c53..3cb2e4b 100644 --- a/frontend/modules/core/components/resource/Item.vue +++ b/frontend/modules/core/components/resource/Item.vue @@ -12,7 +12,7 @@ @@ -48,4 +48,10 @@ const source = injectSourceContext() const showSkipped = computed(() => status.value.includes(Status.SKIP) && !!props.item?.[Status.SKIP]) const showed = computed(() => status.value.filter((s) => s !== Status.SKIP)) + +const category = computed(() => { + if (props?.filter?.categories?.length !== 1) return undefined + + return props.filter?.categories[0] +}) diff --git a/frontend/pages/source/[source]/[category].vue b/frontend/pages/source/[source]/[category].vue index dcb2f50..cb2f67a 100644 --- a/frontend/pages/source/[source]/[category].vue +++ b/frontend/pages/source/[source]/[category].vue @@ -44,7 +44,7 @@ const { data, refresh } = useAPI((api) => api.dashboard(filter.value)); watch(filter, onChange(refresh)) -provide(APIFilter, ref(filter)) +provide(APIFilter, filter) useStatusProvider(data) useSourceContext(ref(route.params.source))