Skip to content

Commit

Permalink
fix issue with comments
Browse files Browse the repository at this point in the history
Signed-off-by: stonezdj <[email protected]>
  • Loading branch information
stonezdj committed May 23, 2024
1 parent 18eaa4b commit 8bd2b1c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
8 changes: 4 additions & 4 deletions src/pkg/scan/sbom/dao/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (suite *ReportTestSuite) SetupTest() {
ArtifactID: 111,
RegistrationUUID: "ruuid",
MimeType: v1.MimeTypeSBOMReport,
Report: `{"sbom_digest": "sha256:abc"}`,
ReportSummary: `{"sbom_digest": "sha256:abc"}`,
}
suite.create(sbomReport)
}
Expand Down Expand Up @@ -76,7 +76,7 @@ func (suite *ReportTestSuite) TestReportUpdateReportData() {
l, err := suite.dao.List(orm.Context(), q.New(q.KeyWords{"uuid": "uuid"}))
suite.Require().NoError(err)
suite.Require().Equal(1, len(l))
suite.Equal("{}", l[0].Report)
suite.Equal("{}", l[0].ReportSummary)

err = suite.dao.UpdateReportData(orm.Context(), "uuid", "{\"a\": 900}")
suite.Require().NoError(err)
Expand All @@ -88,7 +88,7 @@ func (suite *ReportTestSuite) TestUpdate() {
ArtifactID: 111,
RegistrationUUID: "ruuid",
MimeType: v1.MimeTypeSBOMReport,
Report: `{"sbom_digest": "sha256:abc"}`,
ReportSummary: `{"sbom_digest": "sha256:abc"}`,
}, "report")
suite.Require().NoError(err)
query1 := &q.Query{
Expand All @@ -102,7 +102,7 @@ func (suite *ReportTestSuite) TestUpdate() {
}
l, err := suite.dao.List(orm.Context(), query1)
suite.Require().Equal(1, len(l))
suite.Equal(l[0].Report, `{"sbom_digest": "sha256:abc"}`)
suite.Equal(l[0].ReportSummary, `{"sbom_digest": "sha256:abc"}`)
}

// TestReportList tests list reports with query parameters.
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/scan/sbom/model/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Report struct {
RegistrationUUID string `orm:"column(registration_uuid)"`
MimeType string `orm:"column(mime_type)"`
MediaType string `orm:"column(media_type)"`
Report string `orm:"column(report);type(json)"`
ReportSummary string `orm:"column(report);type(json)"`
}

// TableName for sbom report
Expand Down
50 changes: 25 additions & 25 deletions src/pkg/scan/sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,6 @@ func (h *scanHandler) RequestParameters() map[string]interface{} {
return map[string]interface{}{"sbom_media_types": []string{sbomMediaTypeSpdx}}
}

// URLParameter defines the parameters for scan report url
func (h *scanHandler) URLParameter(_ *v1.ScanRequest) (string, error) {
return fmt.Sprintf("sbom_media_type=%s", url.QueryEscape(sbomMediaTypeSpdx)), nil
}

// RequiredPermissions defines the permission used by the scan robot account
func (h *scanHandler) RequiredPermissions() []*types.Policy {
return []*types.Policy{
{
Resource: rbac.ResourceRepository,
Action: rbac.ActionPull,
},
{
Resource: rbac.ResourceRepository,
Action: rbac.ActionScannerPull,
},
{
Resource: rbac.ResourceRepository,
Action: rbac.ActionPush,
},
}
}

// PostScan defines task specific operations after the scan is complete
func (h *scanHandler) PostScan(ctx job.Context, sr *v1.ScanRequest, _ *scanModel.Report, rawReport string, startTime time.Time, robot *model.Robot) (string, error) {
sbomContent, s, err := retrieveSBOMContent(rawReport)
Expand All @@ -133,6 +110,29 @@ func (h *scanHandler) PostScan(ctx job.Context, sr *v1.ScanRequest, _ *scanModel
return h.generateReport(startTime, sr.Artifact.Repository, dgst, "Success", s)
}

// URLParameter defines the parameters for scan report url
func (h *scanHandler) URLParameter(_ *v1.ScanRequest) (string, error) {
return fmt.Sprintf("sbom_media_type=%s", url.QueryEscape(sbomMediaTypeSpdx)), nil
}

// RequiredPermissions defines the permission used by the scan robot account
func (h *scanHandler) RequiredPermissions() []*types.Policy {
return []*types.Policy{
{
Resource: rbac.ResourceRepository,
Action: rbac.ActionPull,
},
{
Resource: rbac.ResourceRepository,
Action: rbac.ActionScannerPull,
},
{
Resource: rbac.ResourceRepository,
Action: rbac.ActionPush,
},
}
}

// annotations defines the annotations for the accessory artifact
func (h *scanHandler) annotations() map[string]string {
t := time.Now().Format(time.RFC3339)
Expand Down Expand Up @@ -248,7 +248,7 @@ func (h *scanHandler) deleteSBOMAccessories(ctx context.Context, reports []*sbom
if rpt.MimeType != v1.MimeTypeSBOMReport {
continue
}
if err := h.deleteSBOMAccessory(ctx, rpt.Report); err != nil {
if err := h.deleteSBOMAccessory(ctx, rpt.ReportSummary); err != nil {
return err
}
if err := mgr.Delete(ctx, rpt.UUID); err != nil {
Expand Down Expand Up @@ -332,7 +332,7 @@ func (h *scanHandler) GetSummary(ctx context.Context, art *artifact.Artifact, mi
if len(reports) == 0 {
return map[string]interface{}{}, nil
}
reportContent := reports[0].Report
reportContent := reports[0].ReportSummary
result := map[string]interface{}{}
if len(reportContent) == 0 {
status := h.TaskMgrFunc().RetrieveStatusFromTask(ctx, reports[0].UUID)
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/scan/sbom/sbom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (suite *SBOMTestSuite) TestMakeReportPlaceHolder() {
func (suite *SBOMTestSuite) TestGetSBOMSummary() {
r := registeredScanner
rpts := []*sbomModel.Report{
{UUID: "rp-uuid-004", MimeType: v1.MimeTypeSBOMReport, Report: `{"scan_status":"Success", "sbom_digest": "sha256:1234567890"}`},
{UUID: "rp-uuid-004", MimeType: v1.MimeTypeSBOMReport, ReportSummary: `{"scan_status":"Success", "sbom_digest": "sha256:1234567890"}`},
}
mock.OnAnything(suite.scannerController, "GetRegistrationByProject").Return(r, nil)
mock.OnAnything(suite.sbomManager, "GetBy").Return(rpts, nil)
Expand Down
10 changes: 5 additions & 5 deletions src/pkg/scan/vulnerability/vul.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,6 @@ func (h *scanHandler) RequiredPermissions() []*types.Policy {
}
}

// ReportURLParameter vulnerability doesn't require any scan report parameters
func (h *scanHandler) URLParameter(_ *v1.ScanRequest) (string, error) {
return "", nil
}

// PostScan ...
func (h *scanHandler) PostScan(ctx job.Context, _ *v1.ScanRequest, origRp *scan.Report, rawReport string,
_ time.Time, _ *model.Robot) (string, error) {
Expand All @@ -262,6 +257,11 @@ func (h *scanHandler) PostScan(ctx job.Context, _ *v1.ScanRequest, origRp *scan.
return refreshedReport, err
}

// URLParameter vulnerability doesn't require any scan report parameters
func (h *scanHandler) URLParameter(_ *v1.ScanRequest) (string, error) {
return "", nil
}

func (h *scanHandler) Update(ctx context.Context, uuid string, rpt string) error {
reportMgr := h.ReportMgrFunc()
if err := reportMgr.UpdateReportData(ctx, uuid, rpt); err != nil {
Expand Down

0 comments on commit 8bd2b1c

Please sign in to comment.