Skip to content

Commit

Permalink
add type for scanner metadata (goharbor#20108)
Browse files Browse the repository at this point in the history
Signed-off-by: wang yan <[email protected]>
  • Loading branch information
wy65701436 authored Mar 25, 2024
1 parent fa01cc5 commit 2eb5464
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/v2.0/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8450,6 +8450,12 @@ definitions:
ScannerCapability:
type: object
properties:
type:
type: string
description: |
Specify the type of scanner capability, like vulnerability or sbom
x-omitempty: false
example: "sbom"
consumes_mime_types:
type: array
items:
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/scan/rest/v1/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (suite *ClientTestSuite) TestClientMetadata() {
require.NotNil(suite.T(), m)

assert.Equal(suite.T(), m.Scanner.Name, "Trivy")
assert.Equal(suite.T(), m.Capabilities[0].Type, "sbom")
}

// TestClientSubmitScan tests the scan submission of client
Expand Down Expand Up @@ -119,6 +120,7 @@ func (mh *mockHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Version: "0.1.0",
},
Capabilities: []*ScannerCapability{{
Type: "sbom",
ConsumesMimeTypes: []string{
MimeTypeOCIArtifact,
MimeTypeDockerArtifact,
Expand Down
3 changes: 3 additions & 0 deletions src/pkg/scan/rest/v1/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ type Scanner struct {
// report MIME types. For example, a scanner capable of analyzing Docker images and producing
// a vulnerabilities report recognizable by Harbor web console might be represented with the
// following capability:
// - type: vulnerability
// - consumes MIME types:
// -- application/vnd.oci.image.manifest.v1+json
// -- application/vnd.docker.distribution.manifest.v2+json
// - produces MIME types
// -- application/vnd.scanner.adapter.vuln.report.harbor+json; version=1.0
// -- application/vnd.scanner.adapter.vuln.report.raw
type ScannerCapability struct {
// The type of the scanner capability, vulnerability or sbom
Type string `json:"type"`
// The set of MIME types of the artifacts supported by the scanner to produce the reports
// specified in the "produces_mime_types". A given mime type should only be present in one
// capability item.
Expand Down
1 change: 1 addition & 0 deletions src/server/v2.0/handler/model/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (s *ScannerMetadata) ToSwagger(_ context.Context) *models.ScannerAdapterMet
var capabilities []*models.ScannerCapability
for _, c := range s.Capabilities {
capabilities = append(capabilities, &models.ScannerCapability{
Type: c.Type,
ConsumesMimeTypes: c.ConsumesMimeTypes,
ProducesMimeTypes: c.ProducesMimeTypes,
})
Expand Down

0 comments on commit 2eb5464

Please sign in to comment.