Skip to content

Commit

Permalink
Seperate the vendor type sbom from image_scan
Browse files Browse the repository at this point in the history
  fixes goharbor#20495

Signed-off-by: stonezdj <[email protected]>
  • Loading branch information
stonezdj committed May 28, 2024
1 parent 1f0c828 commit 45ea2cb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/controller/scan/base_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ func (bc *basicController) Scan(ctx context.Context, artifact *ar.Artifact, opti
if op := operator.FromContext(ctx); op != "" {
extraAttrs["operator"] = op
}
executionID, err := bc.execMgr.Create(ctx, job.ImageScanJobVendorType, artifact.ID, task.ExecutionTriggerManual, extraAttrs)
vendorType := handler.JobVendorType()
executionID, err := bc.execMgr.Create(ctx, vendorType, artifact.ID, task.ExecutionTriggerManual, extraAttrs)
if err != nil {
return err
}
Expand Down Expand Up @@ -960,9 +961,9 @@ func (bc *basicController) launchScanJob(ctx context.Context, param *launchScanJ
params[sca.JobParameterRequest] = sJSON
params[sca.JobParameterMimes] = mimes
params[sca.JobParameterRobot] = robotJSON

vendorType := handler.JobVendorType()
j := &task.Job{
Name: job.ImageScanJobVendorType,
Name: vendorType,
Metadata: &job.Metadata{
JobKind: job.KindGeneric,
},
Expand Down
3 changes: 3 additions & 0 deletions src/jobservice/job/known_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (

// ImageScanJobVendorType is name of scan job it will be used as key to register to job service.
ImageScanJobVendorType = "IMAGE_SCAN"
// SBOMJobVendorType is name of SBOM job it will be used as key to register to job service.
SBOMJobVendorType = "SBOM"
// GarbageCollectionVendorType job name
GarbageCollectionVendorType = "GARBAGE_COLLECTION"
// ReplicationVendorType : the name of the replication job in job service
Expand Down Expand Up @@ -52,6 +54,7 @@ var (
// executionSweeperCount stores the count for execution retained
executionSweeperCount = map[string]int64{
ImageScanJobVendorType: 1,
SBOMJobVendorType: 1,
ScanAllVendorType: 1,
PurgeAuditVendorType: 10,
ExecSweepVendorType: 10,
Expand Down
1 change: 1 addition & 0 deletions src/jobservice/runtime/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ func (bs *Bootstrap) loadAndRunRedisWorkerPool(
job.SampleJob: (*sample.Job)(nil),
// Functional jobs
job.ImageScanJobVendorType: (*scan.Job)(nil),
job.SBOMJobVendorType: (*scan.Job)(nil),
job.PurgeAuditVendorType: (*purge.Job)(nil),
job.GarbageCollectionVendorType: (*gc.GarbageCollector)(nil),
job.ReplicationVendorType: (*replication.Replication)(nil),
Expand Down
2 changes: 2 additions & 0 deletions src/pkg/scan/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type Handler interface {
// PostScan defines the operation after scan
PostScan(ctx job.Context, sr *v1.ScanRequest, rp *scan.Report, rawReport string, startTime time.Time, robot *model.Robot) (string, error)
ReportHandler
// JobVendorType returns the job vendor type
JobVendorType() string
}

// ReportHandler handler for scan report, it could be sbom report or vulnerability report
Expand Down
4 changes: 4 additions & 0 deletions src/pkg/scan/sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,7 @@ func (h *scanHandler) GetSummary(ctx context.Context, art *artifact.Artifact, mi
err = json.Unmarshal([]byte(reportContent), &result)
return result, err
}

func (h *scanHandler) JobVendorType() string {
return job.SBOMJobVendorType
}
4 changes: 4 additions & 0 deletions src/pkg/scan/vulnerability/vul.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,7 @@ func (h *scanHandler) GetSummary(ctx context.Context, ar *artifact.Artifact, mim

return summaries, nil
}

func (h *scanHandler) JobVendorType() string {
return job.ImageScanJobVendorType
}

0 comments on commit 45ea2cb

Please sign in to comment.