Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Rename VulnerabilityScanResult to VulnerabilityReportData #625

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/scanner-aqua/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func run() error {

// scan scans the specified image reference. Firstly, attempt to download a vulnerability
// report with Aqua REST API call. If the report is not found, execute the `scannercli scan` command.
func scan(opt options, imageRef string) (report v1alpha1.VulnerabilityScanResult, err error) {
func scan(opt options, imageRef string) (report v1alpha1.VulnerabilityReportData, err error) {
clientset := client.NewClient(opt.baseURL, client.Authorization{
Basic: &opt.credentials,
})
Expand Down
2 changes: 1 addition & 1 deletion itest/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (b *VulnerabilityReportBuilder) Build() *v1alpha1.VulnerabilityReport {
starboard.LabelResourceNamespace: b.namespace,
},
},
Report: v1alpha1.VulnerabilityScanResult{
Report: v1alpha1.VulnerabilityReportData{
UpdateTimestamp: metav1.NewTime(time.Now()),
Scanner: trivyScanner,
Registry: v1alpha1.Registry{
Expand Down
2 changes: 1 addition & 1 deletion itest/matcher/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestVulnerabilityReportMatcher(t *testing.T) {
},
},
},
Report: v1alpha1.VulnerabilityScanResult{
Report: v1alpha1.VulnerabilityReportData{
Scanner: v1alpha1.Scanner{
Name: "Trivy",
Vendor: "Aqua Security",
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/aquasecurity/v1alpha1/vulnerability_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ type VulnerabilityReport struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Report VulnerabilityScanResult `json:"report"`
Report VulnerabilityReportData `json:"report"`
}

// VulnerabilityScanResult is the spec for the vulnerability scan result.
// VulnerabilityReportData is the spec for the vulnerability scan result.
//
// The spec follows the Pluggable Scanners API defined for Harbor.
// @see https://github.com/goharbor/pluggable-scanner-spec/blob/master/api/spec/scanner-adapter-openapi-v1.0.yaml
type VulnerabilityScanResult struct {
type VulnerabilityReportData struct {
UpdateTimestamp metav1.Time `json:"updateTimestamp"`
Scanner Scanner `json:"scanner"`
Registry Registry `json:"registry"`
Expand Down
56 changes: 28 additions & 28 deletions pkg/apis/aquasecurity/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/plugin/aqua/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ func (s *plugin) newScanJobContainer(ctx starboard.PluginContext, podContainer c
}, nil
}

func (s *plugin) ParseVulnerabilityReportData(_ starboard.PluginContext, _ string, logsReader io.ReadCloser) (v1alpha1.VulnerabilityScanResult, error) {
var report v1alpha1.VulnerabilityScanResult
func (s *plugin) ParseVulnerabilityReportData(_ starboard.PluginContext, _ string, logsReader io.ReadCloser) (v1alpha1.VulnerabilityReportData, error) {
var report v1alpha1.VulnerabilityReportData
err := json.NewDecoder(logsReader).Decode(&report)
return report, err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/plugin/aqua/scanner/api/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func NewScanner(version string, clientset client.Clientset) *Scanner {
}
}

func (s *Scanner) Scan(imageRef string) (v1alpha1.VulnerabilityScanResult, error) {
func (s *Scanner) Scan(imageRef string) (v1alpha1.VulnerabilityReportData, error) {
registries, err := s.clientset.Registries().List()
if err != nil {
return v1alpha1.VulnerabilityScanResult{}, err
return v1alpha1.VulnerabilityReportData{}, err
}

var registryName string
Expand All @@ -49,18 +49,18 @@ func (s *Scanner) Scan(imageRef string) (v1alpha1.VulnerabilityScanResult, error

reference, err := name.ParseReference(imageRef)
if err != nil {
return v1alpha1.VulnerabilityScanResult{}, err
return v1alpha1.VulnerabilityReportData{}, err
}

vulnerabilities, err := s.clientset.Images().Vulnerabilities(registryName, reference.Context().RepositoryStr(), reference.Identifier())
if err != nil {
return v1alpha1.VulnerabilityScanResult{}, err
return v1alpha1.VulnerabilityReportData{}, err
}

return s.convert(reference, vulnerabilities)
}

func (s *Scanner) convert(ref name.Reference, response client.VulnerabilitiesResponse) (v1alpha1.VulnerabilityScanResult, error) {
func (s *Scanner) convert(ref name.Reference, response client.VulnerabilitiesResponse) (v1alpha1.VulnerabilityReportData, error) {
items := make([]v1alpha1.Vulnerability, 0)

for _, result := range response.Results {
Expand All @@ -85,7 +85,7 @@ func (s *Scanner) convert(ref name.Reference, response client.VulnerabilitiesRes
artifact.Digest = t.DigestStr()
}

return v1alpha1.VulnerabilityScanResult{
return v1alpha1.VulnerabilityReportData{
UpdateTimestamp: metav1.NewTime(time.Now()),
Scanner: v1alpha1.Scanner{
Name: "Aqua CSP",
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugin/aqua/scanner/cli/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewScanner(version string, baseURL string, credentials client.UsernameAndPa
}
}

func (s *Scanner) Scan(imageRef string) (report v1alpha1.VulnerabilityScanResult, err error) {
func (s *Scanner) Scan(imageRef string) (report v1alpha1.VulnerabilityReportData, err error) {
args := []string{
"scan",
"--checkonly",
Expand Down Expand Up @@ -57,7 +57,7 @@ func (s *Scanner) Scan(imageRef string) (report v1alpha1.VulnerabilityScanResult
return s.convert(imageRef, aquaReport)
}

func (s *Scanner) convert(imageRef string, aquaReport ScanReport) (report v1alpha1.VulnerabilityScanResult, err error) {
func (s *Scanner) convert(imageRef string, aquaReport ScanReport) (report v1alpha1.VulnerabilityReportData, err error) {
items := make([]v1alpha1.Vulnerability, 0)

for _, resourceScan := range aquaReport.Resources {
Expand Down Expand Up @@ -98,7 +98,7 @@ func (s *Scanner) convert(imageRef string, aquaReport ScanReport) (report v1alph
artifact.Digest = t.DigestStr()
}

report = v1alpha1.VulnerabilityScanResult{
report = v1alpha1.VulnerabilityReportData{
UpdateTimestamp: metav1.NewTime(time.Now()),
Scanner: v1alpha1.Scanner{
Name: "Aqua CSP",
Expand Down
14 changes: 7 additions & 7 deletions pkg/plugin/trivy/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,16 +769,16 @@ func (p *plugin) appendTrivyInsecureEnv(config Config, image string, env []corev
return env, nil
}

func (p *plugin) ParseVulnerabilityReportData(ctx starboard.PluginContext, imageRef string, logsReader io.ReadCloser) (v1alpha1.VulnerabilityScanResult, error) {
func (p *plugin) ParseVulnerabilityReportData(ctx starboard.PluginContext, imageRef string, logsReader io.ReadCloser) (v1alpha1.VulnerabilityReportData, error) {
config, err := p.newConfigFrom(ctx)
if err != nil {
return v1alpha1.VulnerabilityScanResult{}, err
return v1alpha1.VulnerabilityReportData{}, err
}

var reports []ScanReport
err = json.NewDecoder(logsReader).Decode(&reports)
if err != nil {
return v1alpha1.VulnerabilityScanResult{}, err
return v1alpha1.VulnerabilityReportData{}, err
}
vulnerabilities := make([]v1alpha1.Vulnerability, 0)

Expand All @@ -800,20 +800,20 @@ func (p *plugin) ParseVulnerabilityReportData(ctx starboard.PluginContext, image

registry, artifact, err := p.parseImageRef(imageRef)
if err != nil {
return v1alpha1.VulnerabilityScanResult{}, err
return v1alpha1.VulnerabilityReportData{}, err
}

trivyImageRef, err := config.GetImageRef()
if err != nil {
return v1alpha1.VulnerabilityScanResult{}, err
return v1alpha1.VulnerabilityReportData{}, err
}

version, err := starboard.GetVersionFromImageRef(trivyImageRef)
if err != nil {
return v1alpha1.VulnerabilityScanResult{}, err
return v1alpha1.VulnerabilityReportData{}, err
}

return v1alpha1.VulnerabilityScanResult{
return v1alpha1.VulnerabilityReportData{
UpdateTimestamp: metav1.NewTime(p.clock.Now()),
Scanner: v1alpha1.Scanner{
Name: "Trivy",
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugin/trivy/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ var (
]
}]`

sampleReport = v1alpha1.VulnerabilityScanResult{
sampleReport = v1alpha1.VulnerabilityReportData{
UpdateTimestamp: metav1.NewTime(fixedTime),
Scanner: v1alpha1.Scanner{
Name: "Trivy",
Expand Down Expand Up @@ -1644,7 +1644,7 @@ func TestScanner_ParseVulnerabilityReportData(t *testing.T) {
imageRef string
input string
expectedError error
expectedReport v1alpha1.VulnerabilityScanResult
expectedReport v1alpha1.VulnerabilityReportData
}{
{
name: "Should convert vulnerability report in JSON format when input is quiet",
Expand All @@ -1658,7 +1658,7 @@ func TestScanner_ParseVulnerabilityReportData(t *testing.T) {
imageRef: "core.harbor.domain/library/nginx@sha256:d20aa6d1cae56fd17cd458f4807e0de462caf2336f0b70b5eeb69fcaaf30dd9c",
input: `null`,
expectedError: nil,
expectedReport: v1alpha1.VulnerabilityScanResult{
expectedReport: v1alpha1.VulnerabilityReportData{
UpdateTimestamp: metav1.NewTime(fixedTime),
Scanner: v1alpha1.Scanner{
Name: "Trivy",
Expand Down
2 changes: 1 addition & 1 deletion pkg/report/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (h *workloadReporter) RetrieveData(workload kube.Object) (templates.Workloa
return templates.WorkloadReport{}, err
}

vulnsReports := map[string]v1alpha1.VulnerabilityScanResult{}
vulnsReports := map[string]v1alpha1.VulnerabilityReportData{}
for _, vulnerabilityReport := range vulnerabilityReports {
containerName, ok := vulnerabilityReport.Labels[starboard.LabelContainerName]
if !ok {
Expand Down
8 changes: 4 additions & 4 deletions pkg/report/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Test_topNVulnerabilitiesByScore(t *testing.T) {
name: "Should return top 5 vulnerabilities with count",
reports: []v1alpha1.VulnerabilityReport{
{
Report: v1alpha1.VulnerabilityScanResult{
Report: v1alpha1.VulnerabilityReportData{
Vulnerabilities: []v1alpha1.Vulnerability{
{
VulnerabilityID: "CVE-2019-1549",
Expand All @@ -43,7 +43,7 @@ func Test_topNVulnerabilitiesByScore(t *testing.T) {
},
},
{
Report: v1alpha1.VulnerabilityScanResult{
Report: v1alpha1.VulnerabilityReportData{
Vulnerabilities: []v1alpha1.Vulnerability{
{
VulnerabilityID: "CVE-2019-1548",
Expand Down Expand Up @@ -131,7 +131,7 @@ func Test_topNVulnerabilitiesByScore(t *testing.T) {
name: "Should return 2 vulnerabilities with count when some input has nil scores",
reports: []v1alpha1.VulnerabilityReport{
{
Report: v1alpha1.VulnerabilityScanResult{
Report: v1alpha1.VulnerabilityReportData{
Vulnerabilities: []v1alpha1.Vulnerability{
{
VulnerabilityID: "CVE-2019-1549",
Expand All @@ -155,7 +155,7 @@ func Test_topNVulnerabilitiesByScore(t *testing.T) {
},
},
{
Report: v1alpha1.VulnerabilityScanResult{
Report: v1alpha1.VulnerabilityReportData{
Vulnerabilities: []v1alpha1.Vulnerability{
{
VulnerabilityID: "CVE-2019-1548",
Expand Down
2 changes: 1 addition & 1 deletion pkg/report/templates/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type WorkloadReport struct {
GeneratedAt time.Time

// FIXME Do not use map as the order of iteration is unpredictable.
VulnsReports map[string]v1alpha1.VulnerabilityScanResult
VulnsReports map[string]v1alpha1.VulnerabilityReportData
ConfigAuditReport *v1alpha1.ConfigAuditReport
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/vulnerabilityreport/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ReportBuilder struct {
owner metav1.Object
container string
hash string
result v1alpha1.VulnerabilityScanResult
data v1alpha1.VulnerabilityReportData
}

func NewReportBuilder(scheme *runtime.Scheme) *ReportBuilder {
Expand All @@ -51,8 +51,8 @@ func (b *ReportBuilder) PodSpecHash(hash string) *ReportBuilder {
return b
}

func (b *ReportBuilder) Data(result v1alpha1.VulnerabilityScanResult) *ReportBuilder {
b.result = result
func (b *ReportBuilder) Data(data v1alpha1.VulnerabilityReportData) *ReportBuilder {
b.data = data
return b
}

Expand Down Expand Up @@ -93,7 +93,7 @@ func (b *ReportBuilder) Get() (v1alpha1.VulnerabilityReport, error) {
Namespace: b.owner.GetNamespace(),
Labels: labels,
},
Report: b.result,
Report: b.data,
}
err = controllerutil.SetControllerReference(b.owner, &report, b.scheme)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/vulnerabilityreport/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestBuilder(t *testing.T) {
}).
Container("my-container").
PodSpecHash("xyz").
Data(v1alpha1.VulnerabilityScanResult{}).
Data(v1alpha1.VulnerabilityReportData{}).
Get()

g.Expect(err).ToNot(gomega.HaveOccurred())
Expand All @@ -49,6 +49,6 @@ func TestBuilder(t *testing.T) {
starboard.LabelPodSpecHash: "xyz",
},
},
Report: v1alpha1.VulnerabilityScanResult{},
Report: v1alpha1.VulnerabilityReportData{},
}))
}
6 changes: 3 additions & 3 deletions pkg/vulnerabilityreport/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestNewReadWriter(t *testing.T) {
starboard.LabelContainerName: "my-container-01",
},
},
Report: v1alpha1.VulnerabilityScanResult{},
Report: v1alpha1.VulnerabilityReportData{},
}, &v1alpha1.VulnerabilityReport{
ObjectMeta: metav1.ObjectMeta{
Namespace: "my-namespace",
Expand All @@ -225,7 +225,7 @@ func TestNewReadWriter(t *testing.T) {
starboard.LabelContainerName: "my-container-02",
},
},
Report: v1alpha1.VulnerabilityScanResult{},
Report: v1alpha1.VulnerabilityReportData{},
}, &v1alpha1.VulnerabilityReport{
ObjectMeta: metav1.ObjectMeta{
Namespace: "my-namespace",
Expand All @@ -237,7 +237,7 @@ func TestNewReadWriter(t *testing.T) {
starboard.LabelContainerName: "my-sts-container",
},
},
Report: v1alpha1.VulnerabilityScanResult{},
Report: v1alpha1.VulnerabilityReportData{},
}).Build()

readWriter := vulnerabilityreport.NewReadWriter(client)
Expand Down
Loading