Skip to content

Commit 127584b

Browse files
committed
some minor refactoring
1 parent 4036b8d commit 127584b

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

pkg/pipeline/PipelineStageService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ func (impl *PipelineStageServiceImpl) IsScanPluginConfiguredAtPipelineStage(pipe
21802180
return false, nil
21812181
}
21822182
isScanPluginConfigured, err := impl.pipelineStageRepository.CheckIfPluginExistsInPipelineStage(pipelineId, pipelineStage, plugin[0].Id)
2183-
if err != nil && !util.IsErrNoRows(err) {
2183+
if err != nil {
21842184
impl.logger.Errorw("error in getting ci pipeline plugin", "err", err, "pipelineId", pipelineId, "pluginId", plugin[0].Id)
21852185
return false, err
21862186
}

pkg/security/ImageScanService.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package security
1919
import (
2020
"context"
2121
securityBean "github.com/devtron-labs/devtron/internal/sql/repository/security/bean"
22-
"github.com/devtron-labs/devtron/internal/util"
2322
"github.com/devtron-labs/devtron/pkg/cluster/environment"
2423
"github.com/devtron-labs/devtron/pkg/cluster/environment/bean"
2524
bean2 "github.com/devtron-labs/devtron/pkg/deployment/trigger/devtronApps/bean"
@@ -651,7 +650,7 @@ func (impl ImageScanServiceImpl) updateCount(severity securityBean.Severity, cri
651650
func (impl ImageScanServiceImpl) IsImageScanExecutionCompleted(image, imageDigest string) (bool, error) {
652651
var isScanningCompleted bool
653652
allScanHistoryMappings, err := impl.scanToolExecutionHistoryMappingRepository.FetchScanHistoryMappingsUsingImageAndImageDigest(image, imageDigest)
654-
if err != nil && !util.IsErrNoRows(err) {
653+
if err != nil {
655654
impl.Logger.Errorw("error in fetching all scan execution history mapping", "image", image, "imageDigest", imageDigest, "err", err)
656655
return false, err
657656
}

pkg/workflow/dag/WorkflowDagExecutor.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,11 @@ func (impl *WorkflowDagExecutorImpl) HandlePreStageSuccessEvent(triggerContext t
573573
scanEnabled, scanned := ciArtifact.ScanEnabled, ciArtifact.Scanned
574574
isScanPluginConfigured, isScanningDoneViaPlugin, err := impl.isArtifactScannedByPluginForPipeline(ciArtifact, cdStageCompleteEvent.CdPipelineId, repository4.PIPELINE_STAGE_TYPE_PRE_CD, bean2.ImageScanningPluginToCheckInPipelineStageStep)
575575
if err != nil {
576-
impl.logger.Errorw("error in handling scanning event for ci artifact", "ciArtifact", ciArtifact, "err", err)
576+
impl.logger.Errorw("error in checking if artifact scanned by plugin for a pipeline or not", "ciArtifact", ciArtifact, "err", err)
577577
return err
578578
}
579-
if isScanPluginConfigured {
580-
ciArtifact.ScanEnabled = true
581-
}
582-
if isScanningDoneViaPlugin {
583-
ciArtifact.Scanned = true
584-
}
579+
helper.UpdateScanStatusInCiArtifact(ciArtifact, isScanPluginConfigured, isScanningDoneViaPlugin)
580+
585581
// if ciArtifact scanEnabled and scanned state changed from above func then update ciArtifact
586582
if scanEnabled != ciArtifact.ScanEnabled || scanned != ciArtifact.Scanned {
587583
err = impl.ciArtifactRepository.Update(ciArtifact)
@@ -686,15 +682,11 @@ func (impl *WorkflowDagExecutorImpl) HandlePostStageSuccessEvent(triggerContext
686682
scanEnabled, scanned := ciArtifact.ScanEnabled, ciArtifact.Scanned
687683
isScanPluginConfigured, isScanningDoneViaPlugin, err := impl.isArtifactScannedByPluginForPipeline(ciArtifact, cdPipelineId, repository4.PIPELINE_STAGE_TYPE_POST_CD, bean2.ImageScanningPluginToCheckInPipelineStageStep)
688684
if err != nil {
689-
impl.logger.Errorw("error in handling scanning event for ci artifact", "ciArtifact", ciArtifact, "err", err)
685+
impl.logger.Errorw("error in checking if artifact scanned by plugin for a pipeline or not", "ciArtifact", ciArtifact, "err", err)
690686
return err
691687
}
692-
if isScanPluginConfigured {
693-
ciArtifact.ScanEnabled = true
694-
}
695-
if isScanningDoneViaPlugin {
696-
ciArtifact.Scanned = true
697-
}
688+
helper.UpdateScanStatusInCiArtifact(ciArtifact, isScanPluginConfigured, isScanningDoneViaPlugin)
689+
698690
// if ciArtifact scanEnabled and scanned state changed from above func then update ciArtifact
699691
if scanEnabled != ciArtifact.ScanEnabled || scanned != ciArtifact.Scanned {
700692
err = impl.ciArtifactRepository.Update(ciArtifact)
@@ -814,15 +806,10 @@ func (impl *WorkflowDagExecutorImpl) HandleCiSuccessEvent(triggerContext trigger
814806
} else {
815807
isScanPluginConfigured, isScanningDoneViaPlugin, err := impl.isArtifactScannedByPluginForPipeline(buildArtifact, pipelineModal.Id, pipelineStage, bean2.ImageScanningPluginToCheckInPipelineStageStep)
816808
if err != nil {
817-
impl.logger.Errorw("error in handling scanning event for this ci artifact", "ciArtifact", buildArtifact, "err", err)
809+
impl.logger.Errorw("error in checking if artifact scanned by plugin for a pipeline or not", "ciArtifact", buildArtifact, "err", err)
818810
return 0, err
819811
}
820-
if isScanPluginConfigured {
821-
buildArtifact.ScanEnabled = true
822-
}
823-
if isScanningDoneViaPlugin {
824-
buildArtifact.Scanned = true
825-
}
812+
helper.UpdateScanStatusInCiArtifact(buildArtifact, isScanPluginConfigured, isScanningDoneViaPlugin)
826813
}
827814

828815
if err = impl.ciArtifactRepository.Save(buildArtifact); err != nil {

pkg/workflow/dag/helper/helper.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package helper
33
import (
44
"bytes"
55
"encoding/json"
6+
"github.com/devtron-labs/devtron/internal/sql/repository"
67
)
78

89
func GetMaterialInfoJson(materialInfo json.RawMessage) ([]byte, error) {
@@ -19,3 +20,12 @@ func GetMaterialInfoJson(materialInfo json.RawMessage) ([]byte, error) {
1920
matJson = dst.Bytes()
2021
return matJson, nil
2122
}
23+
24+
func UpdateScanStatusInCiArtifact(ciArtifact *repository.CiArtifact, isScanPluginConfigured, isScanningDoneViaPlugin bool) {
25+
if isScanPluginConfigured {
26+
ciArtifact.ScanEnabled = true
27+
}
28+
if isScanningDoneViaPlugin {
29+
ciArtifact.Scanned = true
30+
}
31+
}

0 commit comments

Comments
 (0)