Skip to content

Commit

Permalink
Support Nullable resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Jogeleit committed May 12, 2021
1 parent c5e7f9e commit 1a27dc5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export default {
async plugins(): Promise<string[]> {
const { data } = await instance.get('plugins');

if (!data) return [];

return data;
},
};
2 changes: 1 addition & 1 deletion frontend/src/components/ClusterPolicyTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default Vue.extend<Data, {}, Computed, Props>({
data: () => ({ open: true, search: '', expanded: [] }),
computed: {
items(): Item[] {
return this.results.map((result: Result) => ({ ...result, id: result.policy + result.rule + result.resource.uid }));
return this.results.map((result: Result) => ({ ...result, id: result.policy + result.rule + result?.resource?.uid }));
},
headers(): DataTableHeader[] {
return [
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/PolicyStatusPerNamespace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export default Vue.extend<{ show: boolean }, {}, { renderHeight: number; height:
},
options() {
const unordnered = this.results.reduce<{ [namspace: string]: number }>((acc, item) => {
if (!item.resource) {
return acc;
}
if (!item.resource.namespace) {
return acc;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/PolicyTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default Vue.extend<Data, Methods, Computed, Props>({
data: () => ({ open: true, search: '', expanded: [] }),
computed: {
items(): Item[] {
return this.results.map((result: Result) => ({ ...result, id: result.policy + result.rule + result.resource.uid }));
return this.results.map((result: Result) => ({ ...result, id: result.policy + result.rule + result?.resource?.uid }));
},
headers(): DataTableHeader[] {
return [
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export type Result = {
severity?: string;
category?: string;
scored: boolean;
resource: Resource;
resource?: Resource;
}

export type PolicyReport = {
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/views/ClusterPolicyReport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,17 @@ export default Vue.extend<Data, Methods, Computed, {}>({
}, {}));
},
availableKinds(): string[] {
return Object.keys(this.results.reduce<{ [kind: string]: boolean }>((c, r) => ({ ...c, [r.resource.kind]: true }), {}));
return Object.keys(this.results.reduce<{ [kind: string]: boolean }>((c, r) => {
if (!r.resource) {
return c;
}
return { ...c, [r.resource.kind]: true };
}, {}));
},
filteredResults(): Result[] {
return this.results.filter((result) => {
if (this.kinds.length > 0 && !this.kinds.includes(result.resource.kind)) return false;
if (this.kinds.length > 0 && result.resource && !this.kinds.includes(result.resource.kind)) return false;
if (this.categories.length > 0 && !this.categories.includes(result.category || '')) return false;
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/views/PolicyReport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,22 @@ export default Vue.extend<Data, Methods, Computed, {}>({
}, {}));
},
availableKinds(): string[] {
return Object.keys(this.results.reduce<{ [kind: string]: boolean }>((c, r) => ({ ...c, [r.resource.kind]: true }), {}));
return Object.keys(this.results.reduce<{ [kind: string]: boolean }>((c, r) => {
if (!r.resource) {
return c;
}
return { ...c, [r.resource.kind]: true };
}, {}));
},
results(): Result[] {
return flatResults(this.policies, this.globalPolicyMap);
},
filteredResults(): Result[] {
return this.results.filter((result) => {
if (this.namespaces.length > 0 && !this.namespaces.includes(result.resource.namespace as string)) return false;
if (this.namespaces.length > 0 && result.resource && !this.namespaces.includes(result.resource.namespace as string)) return false;
if (this.kinds.length > 0 && !this.kinds.includes(result.resource.kind)) return false;
if (this.kinds.length > 0 && result.resource && !this.kinds.includes(result.resource.kind)) return false;
if (this.categories.length > 0 && !this.categories.includes(result.category || '')) return false;
Expand Down

0 comments on commit 1a27dc5

Please sign in to comment.