add type for scanner metadata (#20108)

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2024-03-25 15:02:39 +08:00 committed by GitHub
parent fa01cc5e48
commit 2eb5464603
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 0 deletions

View File

@ -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:

View File

@ -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
@ -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,

View File

@ -37,6 +37,7 @@ 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
@ -44,6 +45,8 @@ type Scanner struct {
// -- 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.

View File

@ -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,
})