mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 02:05:41 +01:00
Add additional link for sboms (#20423)
artifact object's addition_links has sboms item when it support to generate sbom fixes #20346 Signed-off-by: stonezdj <stone.zhang@broadcom.com>
This commit is contained in:
parent
df5b3618c7
commit
2b4fe6ced7
@ -80,6 +80,19 @@ func (artifact *Artifact) SetAdditionLink(addition, version string) {
|
|||||||
artifact.AdditionLinks[addition] = &AdditionLink{HREF: href, Absolute: false}
|
artifact.AdditionLinks[addition] = &AdditionLink{HREF: href, Absolute: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (artifact *Artifact) SetSBOMAdditionLink(sbomDgst string, version string) {
|
||||||
|
if artifact.AdditionLinks == nil {
|
||||||
|
artifact.AdditionLinks = make(map[string]*AdditionLink)
|
||||||
|
}
|
||||||
|
addition := "sboms"
|
||||||
|
projectName, repo := utils.ParseRepository(artifact.RepositoryName)
|
||||||
|
// encode slash as %252F
|
||||||
|
repo = repository.Encode(repo)
|
||||||
|
href := fmt.Sprintf("/api/%s/projects/%s/repositories/%s/artifacts/%s/additions/%s", version, projectName, repo, sbomDgst, addition)
|
||||||
|
|
||||||
|
artifact.AdditionLinks[addition] = &AdditionLink{HREF: href, Absolute: false}
|
||||||
|
}
|
||||||
|
|
||||||
// AdditionLink is a link via that the addition can be fetched
|
// AdditionLink is a link via that the addition can be fetched
|
||||||
type AdditionLink struct {
|
type AdditionLink struct {
|
||||||
HREF string `json:"href"`
|
HREF string `json:"href"`
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
vulnerabilitiesAddition = "vulnerabilities"
|
vulnerabilitiesAddition = "vulnerabilities"
|
||||||
|
sbomAddition = "sbom"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewScanReportAssembler returns vul assembler
|
// NewScanReportAssembler returns vul assembler
|
||||||
@ -38,7 +39,6 @@ func NewScanReportAssembler(option *model.OverviewOptions, mimeTypes []string) *
|
|||||||
scanChecker: scan.NewChecker(),
|
scanChecker: scan.NewChecker(),
|
||||||
scanCtl: scan.DefaultController,
|
scanCtl: scan.DefaultController,
|
||||||
mimeTypes: mimeTypes,
|
mimeTypes: mimeTypes,
|
||||||
executionMgr: task.ExecMgr,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +88,9 @@ func (assembler *ScanReportAssembler) Assemble(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set sbom additional link if it is supported, use the empty digest
|
||||||
|
artifact.SetSBOMAdditionLink("", version)
|
||||||
if assembler.overviewOption.WithSBOM {
|
if assembler.overviewOption.WithSBOM {
|
||||||
overview, err := assembler.scanCtl.GetSummary(ctx, &artifact.Artifact, []string{v1.MimeTypeSBOMReport})
|
overview, err := assembler.scanCtl.GetSummary(ctx, &artifact.Artifact, []string{v1.MimeTypeSBOMReport})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -125,6 +128,10 @@ func (assembler *ScanReportAssembler) Assemble(ctx context.Context) error {
|
|||||||
sbomModel.ReportID: overview[sbomModel.ReportID],
|
sbomModel.ReportID: overview[sbomModel.ReportID],
|
||||||
sbomModel.Scanner: overview[sbomModel.Scanner],
|
sbomModel.Scanner: overview[sbomModel.Scanner],
|
||||||
}
|
}
|
||||||
|
if sbomDgst, ok := overview[sbomModel.SBOMDigest].(string); ok {
|
||||||
|
// set additional link for sbom digest
|
||||||
|
artifact.SetSBOMAdditionLink(sbomDgst, version)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -51,7 +51,7 @@ func (suite *VulAssemblerTestSuite) TestScannable() {
|
|||||||
var artifact model.Artifact
|
var artifact model.Artifact
|
||||||
|
|
||||||
suite.Nil(assembler.WithArtifacts(&artifact).Assemble(context.TODO()))
|
suite.Nil(assembler.WithArtifacts(&artifact).Assemble(context.TODO()))
|
||||||
suite.Len(artifact.AdditionLinks, 1)
|
suite.Len(artifact.AdditionLinks, 2)
|
||||||
suite.Equal(artifact.ScanOverview, summary)
|
suite.Equal(artifact.ScanOverview, summary)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user