Skip to content

Commit

Permalink
Fix server controls workload logic
Browse files Browse the repository at this point in the history
  • Loading branch information
noboruma committed Sep 25, 2023
1 parent e7df629 commit a076bea
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions deepfence_worker/controls/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ func RegisterControl[T ctl.StartVulnerabilityScanRequest | ctl.StartSecretScanRe
func ApplyControl(ctx context.Context, req ctl.Action) error {
controls_guard.RLock()
defer controls_guard.RUnlock()
log.Info().Msgf("apply control req: %+v", req)
return controls[ctl.ActionID(req.ID)](ctx, []byte(req.RequestPayload))
f, has := controls[ctl.ActionID(req.ID)]
if has {
log.Info().Msgf("apply control req: %+v", req)
return f(ctx, []byte(req.RequestPayload))
}
log.Warn().Msgf("apply control req: %+v not implemented", req)
return nil
}

func init() {
Expand Down
2 changes: 2 additions & 0 deletions deepfence_worker/tasks/malwarescan/malwarescan.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ func NewMalwareScanner(ingest chan *kgo.Record) MalwareScan {
}

func (s MalwareScan) StopMalwareScan(ctx context.Context, task *asynq.Task) error {
defer cronjobs.ScanWorkloadAllocator.Free()

var params utils.MalwareScanParameters

log.Info().Msgf("StopMalwareScan, payload: %s ", string(task.Payload()))
Expand Down
2 changes: 2 additions & 0 deletions deepfence_worker/tasks/sbom/generate_sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func NewSbomGenerator(ingest chan *kgo.Record) SbomGenerator {
}

func StopVulnerabilityScan(ctx context.Context, task *asynq.Task) error {
defer cronjobs.ScanWorkloadAllocator.Free()

log.Info().Msgf("StopVulnerabilityScan, payload: %s ", string(task.Payload()))
var params utils.SbomParameters
if err := json.Unmarshal(task.Payload(), &params); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions deepfence_worker/tasks/secretscan/secretscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func NewSecretScanner(ingest chan *kgo.Record) SecretScan {
}

func (s SecretScan) StopSecretScan(ctx context.Context, task *asynq.Task) error {
defer cronjobs.ScanWorkloadAllocator.Free()

var params utils.SecretScanParameters

log.Info().Msgf("StopSecretScan, payload: %s ", string(task.Payload()))
Expand Down

0 comments on commit a076bea

Please sign in to comment.