Skip to content

Commit

Permalink
Fix and Should to display Unsupported if no SBOM accessories found (#…
Browse files Browse the repository at this point in the history
…20426)

Should this be Unsupported either for SBOM

Signed-off-by: xuelichao <xuel@vmware.com>
Co-authored-by: Shengwen YU <yshengwen@vmware.com>
  • Loading branch information
xuelichao and zyyw committed May 16, 2024
1 parent 8ccf98a commit 840d408
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<hbr-sbom-tip-histogram
[scanner]="getScanner()"
[artifactDigest]="artifactDigest"
[accessories]="accessories"
[sbomSummary]="sbomOverview"
[sbomDigest]="sbomDigest"></hbr-sbom-tip-histogram>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand All @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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%');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ';
Expand All @@ -28,6 +30,7 @@ export class SbomTipHistogramComponent {
};
@Input() artifactDigest: string = '';
@Input() sbomDigest: string = '';
@Input() accessories: Accessory[] = [];
constructor(
private translate: TranslateService,
private activatedRoute: ActivatedRoute,
Expand All @@ -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%`
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/portal/src/i18n/lang/de-de-lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",
Expand Down
1 change: 1 addition & 0 deletions src/portal/src/i18n/lang/en-us-lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM ",
"DOWNLOAD": "Download SBOM",
Expand Down
1 change: 1 addition & 0 deletions src/portal/src/i18n/lang/es-es-lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",
Expand Down
1 change: 1 addition & 0 deletions src/portal/src/i18n/lang/fr-fr-lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",
Expand Down
1 change: 1 addition & 0 deletions src/portal/src/i18n/lang/ko-kr-lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",
Expand Down
1 change: 1 addition & 0 deletions src/portal/src/i18n/lang/pt-br-lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",
Expand Down
1 change: 1 addition & 0 deletions src/portal/src/i18n/lang/tr-tr-lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",
Expand Down
1 change: 1 addition & 0 deletions src/portal/src/i18n/lang/zh-cn-lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",
Expand Down
1 change: 1 addition & 0 deletions src/portal/src/i18n/lang/zh-tw-lang.json
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,7 @@
},
"NO_SBOM": "No SBOM",
"PACKAGES": "SBOM",
"COMPLETED": "Completed",
"REPORTED_BY": "Reported by {{scanner}}",
"GENERATE": "Generate SBOM",
"DOWNLOAD": "Download SBOM",
Expand Down

0 comments on commit 840d408

Please sign in to comment.