Fix and Should to display Unsupported if no SBOM accessories found (#20426)

Should this be Unsupported either for SBOM

Signed-off-by: xuelichao <xuel@vmware.com>
Co-authored-by: Shengwen YU <yshengwen@vmware.com>
This commit is contained in:
Lichao Xue 2024-05-16 17:40:42 +08:00 committed by GitHub
parent 8ccf98a2ac
commit 840d4085f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 69 additions and 14 deletions

View File

@ -451,18 +451,22 @@
</clr-dg-cell>
<clr-dg-cell>
<div class="cell">
<span *ngIf="!hasScannerSupportSBOM">
<span *ngIf="!hasSbom(artifact)">
{{ 'ARTIFACT.SBOM_UNSUPPORTED' | translate }}
</span>
<hbr-sbom-bar
(submitStopFinish)="submitSbomStopFinish($event)"
(scanFinished)="sbomFinished($event)"
*ngIf="hasScannerSupportSBOM"
[inputScanner]="projectScanner"
*ngIf="hasSbom(artifact)"
[inputScanner]="
handleSbomOverview(artifact.sbom_overview)
?.scanner
"
(submitFinish)="submitSbomFinish($event)"
[projectName]="projectName"
[projectId]="projectId"
[repoName]="repoName"
[accessories]="artifact?.accessories"
[artifactDigest]="artifact?.digest"
[sbomDigest]="artifact?.sbomDigest"
[sbomOverview]="artifact?.sbom_overview">

View File

@ -161,9 +161,6 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
get generateSbomBtnState(): ClrLoadingState {
return this.artifactListPageService.getSbomBtnState();
}
get projectScanner(): Scanner {
return this.artifactListPageService.getProjectScanner();
}
onSendingScanCommand: boolean;
onSendingStopScanCommand: boolean = false;
@ -935,6 +932,14 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
return null;
}
handleSbomOverview(sbomOverview: any): any {
if (sbomOverview) {
const keys = Object.keys(sbomOverview) ?? [];
return keys.length > 0 ? sbomOverview[keys[0]] : null;
}
return null;
}
goIntoIndexArtifact(artifact: Artifact) {
let depth: string = '';
if (this.depth) {
@ -992,6 +997,9 @@ export class ArtifactListTabComponent implements OnInit, OnDestroy {
this.selectedRow[i].sbomDigest =
artifact.sbom_overview.sbom_digest;
}
if (artifact.accessories !== undefined) {
this.selectedRow[i].accessories = artifact.accessories;
}
this.selectedRow.splice(i, 1);
break;
}

View File

@ -22,6 +22,7 @@
<hbr-sbom-tip-histogram
[scanner]="getScanner()"
[artifactDigest]="artifactDigest"
[accessories]="accessories"
[sbomSummary]="sbomOverview"
[sbomDigest]="sbomDigest"></hbr-sbom-tip-histogram>
</div>

View File

@ -10,6 +10,7 @@ import { SbomTipHistogramComponent } from './sbom-tip-histogram/sbom-tip-histogr
import { SBOMOverview } from './sbom-overview';
import { of, timer } from 'rxjs';
import { ArtifactService, ScanService } from 'ng-swagger-gen/services';
import { AccessoryType } from '../artifact';
describe('ResultSbomComponent (inline template)', () => {
let component: ResultSbomComponent;
@ -165,6 +166,13 @@ describe('ResultSbomComponent (inline template)', () => {
it('should show summary bar chart if status is COMPLETED', () => {
component.sbomOverview.scan_status = SBOM_SCAN_STATUS.SUCCESS;
component.sbomDigest = mockedSbomDigest;
component.accessories = [
{
type: AccessoryType.SBOM,
digest: mockedSbomDigest,
},
];
fixture.detectChanges();
fixture.whenStable().then(() => {

View File

@ -23,7 +23,7 @@ import {
HarborEvent,
} from '../../../../../services/event-service/event.service';
import { ScanService } from '../../../../../../../ng-swagger-gen/services/scan.service';
import { ScanType } from 'ng-swagger-gen/models';
import { Accessory, ScanType } from 'ng-swagger-gen/models';
import { ScanTypes } from '../../../../../shared/entities/shared.const';
import { SBOMOverview } from './sbom-overview';
import { Scanner } from '../../../../left-side-nav/interrogation-services/scanner/scanner';
@ -43,6 +43,7 @@ export class ResultSbomComponent implements OnInit, OnDestroy {
@Input() artifactDigest: string = '';
@Input() sbomDigest: string = '';
@Input() sbomOverview: SBOMOverview;
@Input() accessories: Accessory[] = [];
onSubmitting: boolean = false;
onStopping: boolean = false;
retryCounter: number = 0;

View File

@ -1,7 +1,7 @@
<div class="tip-wrapper width-215">
<clr-tooltip>
<div clrTooltipTrigger class="tip-block">
<div *ngIf="!noSbom" class="circle-block">
<div *ngIf="showSbomDetailLink()" class="circle-block">
<a
href="javascript:void(0)"
class="digest margin-left-5"
@ -11,10 +11,15 @@
>
</div>
<div
*ngIf="noSbom"
*ngIf="showNoSbom()"
class="pl-1 margin-left-5 tip-wrapper bar-block-none shadow-none width-150">
{{ 'SBOM.NO_SBOM' | translate }}
</div>
<div
*ngIf="!showSbomDetailLink() && !showNoSbom()"
class="pl-1 margin-left-5 tip-wrapper bar-block-none shadow-none width-150">
{{ 'SBOM.COMPLETED,' | translate }}
</div>
</div>
<clr-tooltip-content
class="w-800"
@ -23,15 +28,18 @@
*clrIfOpen>
<div class="bar-tooltip-font-larger">
<div
*ngIf="!noSbom"
*ngIf="showSbomDetailLink()"
class="level-border clr-display-inline-block margin-right-5">
<div>
{{ 'SBOM.PACKAGES' | translate }}
</div>
</div>
<ng-container *ngIf="noSbom">
<ng-container *ngIf="showNoSbom()">
<span>{{ 'SBOM.NO_SBOM' | translate }}</span>
</ng-container>
<ng-container *ngIf="!showSbomDetailLink() && !showNoSbom()">
<span>{{ 'SBOM.COMPLETED' | translate }}</span>
</ng-container>
</div>
<hr />
<div *ngIf="scanner">

View File

@ -75,7 +75,7 @@ describe('SbomTipHistogramComponent', () => {
fixture.whenStable().then(() => {
expect(component).toBeTruthy();
expect(component.isLimitedSuccess()).toBeFalsy();
expect(component.noSbom).toBeTruthy();
expect(component.showNoSbom()).toBeTruthy();
expect(component.isThemeLight()).toBeFalsy();
expect(component.duration()).toBe('0');
expect(component.completePercent).toBe('0%');

View File

@ -10,6 +10,8 @@ import {
import { HAS_STYLE_MODE, StyleMode } from '../../../../../../services/theme';
import { ScanTypes } from '../../../../../../shared/entities/shared.const';
import { Scanner } from '../../../../../left-side-nav/interrogation-services/scanner/scanner';
import { Accessory } from 'ng-swagger-gen/models';
import { AccessoryType } from '../../artifact';
const MIN = 60;
const MIN_STR = 'min ';
@ -28,6 +30,7 @@ export class SbomTipHistogramComponent {
};
@Input() artifactDigest: string = '';
@Input() sbomDigest: string = '';
@Input() accessories: Accessory[] = [];
constructor(
private translate: TranslateService,
private activatedRoute: ActivatedRoute,
@ -50,6 +53,14 @@ export class SbomTipHistogramComponent {
return '0';
}
public getSbomAccessories(): Accessory[] {
return (
this.accessories.filter(
accessory => accessory.type === AccessoryType.SBOM
) ?? []
);
}
public get completePercent(): string {
return this.sbomSummary.scan_status === SBOM_SCAN_STATUS.SUCCESS
? `100%`
@ -67,8 +78,12 @@ export class SbomTipHistogramComponent {
: new Date();
}
get noSbom(): boolean {
return this.sbomDigest === undefined || this.sbomDigest === '';
showSbomDetailLink(): boolean {
return this.sbomDigest && this.getSbomAccessories.length > 0;
}
showNoSbom(): boolean {
return !this.sbomDigest && this.getSbomAccessories.length === 0;
}
isThemeLight() {

View File

@ -217,6 +217,7 @@ export class ResultBarChartComponent implements OnInit, OnDestroy {
repositoryName: dbEncodeURIComponent(this.repoName),
reference: this.artifactDigest,
withScanOverview: true,
withAccessory: true,
XAcceptVulnerabilities: DEFAULT_SUPPORTED_MIME_TYPES,
})
.subscribe(

View File

@ -1058,6 +1058,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",

View File

@ -1059,6 +1059,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM ",
"DOWNLOAD": "Download SBOM",

View File

@ -1057,6 +1057,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",

View File

@ -1057,6 +1057,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",

View File

@ -1056,6 +1056,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",

View File

@ -1055,6 +1055,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",

View File

@ -1058,6 +1058,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",

View File

@ -1056,6 +1056,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",

View File

@ -1055,6 +1055,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",