Skip to content

Commit e5a7d15

Browse files
change file extension name for image detail's SBOM file; Added messages for the successful and failed case of file download in image overview page
1 parent bb8c906 commit e5a7d15

File tree

2 files changed

+92
-44
lines changed

2 files changed

+92
-44
lines changed

pkg/sbombastic-image-vulnerability-scanner/components/ImageDetails.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ export default {
880880
// Generate SBOM download
881881
const sbomData = JSON.stringify(this.sbom.spdx, null, 2);
882882
883-
this.downloadJSON(sbomData, `${ this.imageName }-sbom_${ day(new Date().getTime()).format('MMDDYYYY_HHmmss') }.json`);
883+
this.downloadJSON(sbomData, `${ this.imageName }-sbom_${ day(new Date().getTime()).format('MMDDYYYY_HHmmss') }.spdx.json`);
884884
885885
this.$store.dispatch('growl/success', {
886886
title: 'Success',

pkg/sbombastic-image-vulnerability-scanner/pages/c/_cluster/sbombastic-image-vulnerability-scanner/ImageOverview.vue

Lines changed: 91 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -376,56 +376,104 @@ export default {
376376
this.registryCrds = await this.$store.dispatch('cluster/findAll', { type: RESOURCE.REGISTRY });
377377
},
378378
methods: {
379-
downloadCSVReport(rows) {
380-
const imagesData = this.isGrouped ? rows.map((row) => row.images).flat() : rows;
381-
382-
const imageList = imagesData.map((row) => {
383-
return {
384-
'IMAGE REFERENCE': this.isGrouped ? `${ row.imageMetadata.registryURI }/${ row.imageMetadata.repository }:${ row.imageMetadata.tag }` : row.imageReference,
385-
'CVEs(Critical)': this.isGrouped ? row.scanResult.critical : row.report.summary.critical,
386-
'CVEs(High)': this.isGrouped ? row.scanResult.high : row.report.summary.high,
387-
'CVEs(Medium)': this.isGrouped ? row.scanResult.medium : row.report.summary.medium,
388-
'CVEs(Low)': this.isGrouped ? row.scanResult.low : row.report.summary.low,
389-
'CVEs(None)': this.isGrouped ? row.scanResult.unknown : row.report.summary.unknown,
390-
'IMAGE ID': row.imageMetadata.digest,
391-
REGISTRY: row.imageMetadata.registry,
392-
REPOSITORY: row.imageMetadata.repository,
393-
PLATFORM: row.imageMetadata.platform,
394-
};
395-
});
396-
const csvBlob = new Blob([Papa.unparse(imageList)], { type: 'text/csv;charset=utf-8' });
397-
398-
saveAs(csvBlob, `image-scan-report_${ day(new Date().getTime()).format('MMDDYYYY_HHmmss') }.csv`);
379+
async downloadCSVReport(rows) {
380+
try {
381+
const imagesData = this.isGrouped ? rows.map((row) => row.images).flat() : rows;
382+
383+
const imageList = imagesData.map((row) => {
384+
return {
385+
'IMAGE REFERENCE': this.isGrouped ? `${ row.imageMetadata.registryURI }/${ row.imageMetadata.repository }:${ row.imageMetadata.tag }` : row.imageReference,
386+
'CVEs(Critical)': this.isGrouped ? row.scanResult.critical : row.report.summary.critical,
387+
'CVEs(High)': this.isGrouped ? row.scanResult.high : row.report.summary.high,
388+
'CVEs(Medium)': this.isGrouped ? row.scanResult.medium : row.report.summary.medium,
389+
'CVEs(Low)': this.isGrouped ? row.scanResult.low : row.report.summary.low,
390+
'CVEs(None)': this.isGrouped ? row.scanResult.unknown : row.report.summary.unknown,
391+
'IMAGE ID': row.imageMetadata.digest,
392+
REGISTRY: row.imageMetadata.registry,
393+
REPOSITORY: row.imageMetadata.repository,
394+
PLATFORM: row.imageMetadata.platform,
395+
};
396+
});
397+
const csvBlob = new Blob([Papa.unparse(imageList)], { type: 'text/csv;charset=utf-8' });
398+
399+
await saveAs(csvBlob, `image-scan-report_${ day(new Date().getTime()).format('MMDDYYYY_HHmmss') }.csv`);
400+
this.$store.dispatch('growl/success', {
401+
title: 'Success',
402+
message: 'Image scan report downloaded successfully'
403+
}, { root: true });
404+
} catch (e) {
405+
this.$store.dispatch('growl/error', {
406+
title: 'Error',
407+
message: 'Failed to download image scan report'
408+
}, { root: true });
409+
}
410+
399411
},
400412
async downloadSbom(res) {
401-
const target = (res && res.length ? res[0] : null);
402-
const sbom = await this.$store.dispatch('cluster/find', { type: RESOURCE.SBOM, id: target.id });
403-
const spdxString = JSON.stringify(sbom.spdx, null, 2);
404-
const sbomBlob = new Blob([spdxString], { type: 'application/json;charset=utf-8' });
405-
406-
saveAs(sbomBlob, `${ sbom.metadata.name }-sbom_${ day(new Date().getTime()).format('MMDDYYYY_HHmmss') }.spdx.json`);
413+
try {
414+
const target = (res && res.length ? res[0] : null);
415+
const sbom = await this.$store.dispatch('cluster/find', { type: RESOURCE.SBOM, id: target.id });
416+
const spdxString = JSON.stringify(sbom.spdx, null, 2);
417+
const sbomBlob = new Blob([spdxString], { type: 'application/json;charset=utf-8' });
418+
419+
await saveAs(sbomBlob, `${ sbom.metadata.name }-sbom_${ day(new Date().getTime()).format('MMDDYYYY_HHmmss') }.spdx.json`);
420+
this.$store.dispatch('growl/success', {
421+
title: 'Success',
422+
message: 'SBOM downloaded successfully'
423+
}, { root: true });
424+
} catch (e) {
425+
this.$store.dispatch('growl/error', {
426+
title: 'Error',
427+
message: 'Failed to download SBOM'
428+
}, { root: true });
429+
}
430+
407431
},
408432
async downloadJson(res) {
409-
const target = (res && res.length ? res[0] : null);
410-
const vulReport = await this.$store.dispatch('cluster/find', { type: RESOURCE.VULNERABILITY_REPORT, id: target.id });
411-
const jsonBlob = new Blob([JSON.stringify(vulReport.report, null, 2)], { type: 'application/json;charset=utf-8' });
412-
413-
saveAs(jsonBlob, `${ target.id }-vulnerabilities-report_${ day(new Date().getTime()).format('MMDDYYYY_HHmmss') }.json`);
433+
try {
434+
const target = (res && res.length ? res[0] : null);
435+
const vulReport = await this.$store.dispatch('cluster/find', { type: RESOURCE.VULNERABILITY_REPORT, id: target.id });
436+
const jsonBlob = new Blob([JSON.stringify(vulReport.report, null, 2)], { type: 'application/json;charset=utf-8' });
437+
438+
await saveAs(jsonBlob, `${ target.id }-vulnerabilities-report_${ day(new Date().getTime()).format('MMDDYYYY_HHmmss') }.json`);
439+
this.$store.dispatch('growl/success', {
440+
title: 'Success',
441+
message: 'Vulnerability report downloaded successfully'
442+
}, { root: true });
443+
} catch (e) {
444+
this.$store.dispatch('growl/error', {
445+
title: 'Error',
446+
message: 'Failed to download vulnerability report'
447+
}, { root: true });
448+
}
449+
414450
},
415451
async downloadCsv(res) {
416-
const target = (res && res.length ? res[0] : null);
417-
const vulReport = await this.$store.dispatch('cluster/find', { type: RESOURCE.VULNERABILITY_REPORT, id: target.id });
418-
let vulnerabilityList = [];
419-
420-
vulReport.report.results.forEach((result) => {
421-
vulnerabilityList = vulnerabilityList.concat(result.vulnerabilities);
422-
});
423-
const csv = imageDetailsToCSV(
424-
vulnerabilityList
425-
);
426-
const csvBlob = new Blob([Papa.unparse(csv)], { type: 'text/csv;charset=utf-8' });
452+
try {
453+
const target = (res && res.length ? res[0] : null);
454+
const vulReport = await this.$store.dispatch('cluster/find', { type: RESOURCE.VULNERABILITY_REPORT, id: target.id });
455+
let vulnerabilityList = [];
456+
457+
vulReport.report.results.forEach((result) => {
458+
vulnerabilityList = vulnerabilityList.concat(result.vulnerabilities);
459+
});
460+
const csv = imageDetailsToCSV(
461+
vulnerabilityList
462+
);
463+
const csvBlob = new Blob([Papa.unparse(csv)], { type: 'text/csv;charset=utf-8' });
464+
465+
await saveAs(csvBlob, `${ target.id }-image-detail-report_${ day(new Date().getTime()).format('MMDDYYYY_HHmmss') }.csv`);
466+
this.$store.dispatch('growl/success', {
467+
title: 'Success',
468+
message: 'Image detail report downloaded successfully'
469+
}, { root: true });
470+
} catch (e) {
471+
this.$store.dispatch('growl/error', {
472+
title: 'Error',
473+
message: 'Failed to download image detail report'
474+
}, { root: true });
475+
}
427476
428-
saveAs(csvBlob, `${ target.id }-image-detail-report_${ day(new Date().getTime()).format('MMDDYYYY_HHmmss') }.csv`);
429477
},
430478
// applyFilters() {
431479
// let filtered = _.cloneDeep(this.preprocessedImagesBak);

0 commit comments

Comments
 (0)