Skip to content

Commit

Permalink
support category exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
  • Loading branch information
Frank Jogeleit committed Mar 25, 2024
1 parent 786e88e commit fc25d5f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions backend/pkg/service/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
7 changes: 7 additions & 0 deletions backend/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions frontend/modules/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export class CoreAPI {
return exec<ResourceDetails>(`/api/config/${this.cluster}/resource/${id}`, { baseURL: this.baseURL, params: filter })
}

createException (id: string, source: string, policies: { name: string, rules: string[] }[]) {
return exec<ExceptionResponse>(`/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<ExceptionResponse>(`/api/config/${this.cluster}/resource/${id}/exception`, { baseURL: this.baseURL, method: "POST", body: { policies, source, category } })
}

policySources (filter?: Filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}>()
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion frontend/modules/core/components/resource/Item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<template v-slot:append>
<ResultChip v-for="status in showed" :key="status" class="ml-2" :status="status" :count="item[status]" :tooltip="`${status} results`" />

<exception-dialog v-if="source && exceptions" :resource="item.id" :source="source" :height="32" />
<exception-dialog v-if="source && exceptions" :resource="item.id" :source="source" :category="category" :height="32" />
</template>
</v-list-item>
<resource-source-results v-if="open" :id="item.id" :filter="filter" />
Expand Down Expand Up @@ -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]
})
</script>
2 changes: 1 addition & 1 deletion frontend/pages/source/[source]/[category].vue
Original file line number Diff line number Diff line change
Expand Up @@ -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))
</script>

0 comments on commit fc25d5f

Please sign in to comment.