From 04ab16131600676b06094aab0977e217375af8bd Mon Sep 17 00:00:00 2001 From: gnmahanth Date: Wed, 18 Oct 2023 13:33:42 +0000 Subject: [PATCH] fix scan params decode order --- .../tasks/malwarescan/malwarescan.go | 2 +- deepfence_worker/tasks/sbom/generate_sbom.go | 22 +++++++++---------- deepfence_worker/tasks/sbom/scan_sbom.go | 5 +++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/deepfence_worker/tasks/malwarescan/malwarescan.go b/deepfence_worker/tasks/malwarescan/malwarescan.go index 50830d7970..95a36d55f0 100644 --- a/deepfence_worker/tasks/malwarescan/malwarescan.go +++ b/deepfence_worker/tasks/malwarescan/malwarescan.go @@ -91,7 +91,7 @@ func (s MalwareScan) StartMalwareScan(ctx context.Context, task *asynq.Task) err } log.Info().Msgf("message tenant id %s", string(tenantID)) - log.Info().Msgf(" payload: %s ", string(task.Payload())) + log.Info().Msgf("payload: %s ", string(task.Payload())) var params utils.MalwareScanParameters diff --git a/deepfence_worker/tasks/sbom/generate_sbom.go b/deepfence_worker/tasks/sbom/generate_sbom.go index 31263f515e..5d9eb90feb 100644 --- a/deepfence_worker/tasks/sbom/generate_sbom.go +++ b/deepfence_worker/tasks/sbom/generate_sbom.go @@ -84,6 +84,12 @@ func (s SbomGenerator) GenerateSbom(ctx context.Context, task *asynq.Task) error {Key: "namespace", Value: []byte(tenantID)}, } + log.Info().Msgf("payload: %s ", string(task.Payload())) + + if err := json.Unmarshal(task.Payload(), ¶ms); err != nil { + return err + } + res, scanCtx := tasks.StartStatusReporter(params.ScanId, func(status tasks.ScanStatus) error { sb, err := json.Marshal(status) @@ -105,17 +111,6 @@ func (s SbomGenerator) GenerateSbom(ctx context.Context, task *asynq.Task) error time.Minute*20, ) - worker, err := directory.Worker(ctx) - if err != nil { - return err - } - - log.Info().Msgf("payload: %s ", string(task.Payload())) - - if err := json.Unmarshal(task.Payload(), ¶ms); err != nil { - return err - } - log.Info().Msgf("Adding scan id to map:%s", params.ScanId) scanMap.Store(params.ScanId, scanCtx) defer func() { @@ -130,6 +125,11 @@ func (s SbomGenerator) GenerateSbom(ctx context.Context, task *asynq.Task) error return err } + worker, err := directory.Worker(ctx) + if err != nil { + return err + } + // get registry credentials authFile, creds, err := workerUtils.GetConfigFileFromRegistry(ctx, params.RegistryId) if err != nil { diff --git a/deepfence_worker/tasks/sbom/scan_sbom.go b/deepfence_worker/tasks/sbom/scan_sbom.go index 7a2c89471b..d89ddfbad9 100644 --- a/deepfence_worker/tasks/sbom/scan_sbom.go +++ b/deepfence_worker/tasks/sbom/scan_sbom.go @@ -99,6 +99,8 @@ func (s SbomParser) ScanSBOM(ctx context.Context, task *asynq.Task) error { {Key: "namespace", Value: []byte(tenantID)}, } + log.Info().Msgf("payload: %s ", string(task.Payload())) + var params utils.SbomParameters if err := json.Unmarshal(task.Payload(), ¶ms); err != nil { @@ -126,6 +128,7 @@ func (s SbomParser) ScanSBOM(ctx context.Context, task *asynq.Task) error { }, time.Minute*20, ) + log.Info().Msgf("Adding scan id to map:%s", params.ScanId) scanMap.Store(params.ScanId, scanCtx) defer func() { @@ -135,8 +138,6 @@ func (s SbomParser) ScanSBOM(ctx context.Context, task *asynq.Task) error { close(res) }() - log.Info().Msgf("payload: %s ", string(task.Payload())) - // send inprogress status mc, err := directory.MinioClient(ctx)