@@ -50,6 +50,7 @@ import (
50
50
"github.com/devtron-labs/devtron/pkg/workflow/cd"
51
51
bean4 "github.com/devtron-labs/devtron/pkg/workflow/cd/bean"
52
52
bean2 "github.com/devtron-labs/devtron/pkg/workflow/dag/bean"
53
+ "github.com/devtron-labs/devtron/pkg/workflow/dag/helper"
53
54
error2 "github.com/devtron-labs/devtron/util/error"
54
55
util2 "github.com/devtron-labs/devtron/util/event"
55
56
"strings"
@@ -710,6 +711,22 @@ func (impl *WorkflowDagExecutorImpl) UpdateCiWorkflowForCiSuccess(request *bean2
710
711
return nil
711
712
}
712
713
714
+ func (impl * WorkflowDagExecutorImpl ) isImageScanningPluginConfiguredInCiPipeline (ciPipelineId int ) (bool , error ) {
715
+ var isScanPluginConfigured bool
716
+ var err error
717
+ plugin , err := impl .globalPluginRepository .GetPluginByName (bean3 .VULNERABILITY_SCANNING_PLUGIN )
718
+ if err != nil || len (plugin ) == 0 {
719
+ impl .logger .Errorw ("error in getting image scanning plugin" , "err" , err )
720
+ return isScanPluginConfigured , err
721
+ }
722
+ isScanPluginConfigured , err = impl .pipelineStageRepository .CheckPluginExistsInCiPipeline (ciPipelineId , string (repository4 .PIPELINE_STAGE_TYPE_POST_CI ), plugin [0 ].Id )
723
+ if err != nil {
724
+ impl .logger .Errorw ("error in getting ci pipelineModal plugin" , "err" , err , "ciPipelineId" , ciPipelineId , "pluginId" , plugin [0 ].Id )
725
+ return isScanPluginConfigured , err
726
+ }
727
+ return isScanPluginConfigured , nil
728
+ }
729
+
713
730
func (impl * WorkflowDagExecutorImpl ) HandleCiSuccessEvent (triggerContext triggerBean.TriggerContext , ciPipelineId int , request * bean2.CiArtifactWebhookRequest , imagePushedAt time.Time ) (id int , err error ) {
714
731
impl .logger .Infow ("webhook for artifact save" , "req" , request )
715
732
pipelineModal , err := impl .ciPipelineRepository .FindByCiAndAppDetailsById (ciPipelineId )
@@ -720,45 +737,25 @@ func (impl *WorkflowDagExecutorImpl) HandleCiSuccessEvent(triggerContext trigger
720
737
if request .PipelineName == "" {
721
738
request .PipelineName = pipelineModal .Name
722
739
}
723
- materialJson , err := request .MaterialInfo . MarshalJSON ( )
740
+ materialJson , err := helper . GetMaterialInfoJson ( request .MaterialInfo )
724
741
if err != nil {
725
- impl .logger .Errorw ("unable to marshal material metadata" , "err" , err )
742
+ impl .logger .Errorw ("unable to get materialJson" , "materialInfo" , request . MaterialInfo , "err" , err )
726
743
return 0 , err
727
744
}
728
- dst := new (bytes.Buffer )
729
- err = json .Compact (dst , materialJson )
730
- if err != nil {
731
- return 0 , err
732
- }
733
- materialJson = dst .Bytes ()
734
745
createdOn := time .Now ()
735
746
updatedOn := time .Now ()
736
747
if ! imagePushedAt .IsZero () {
737
748
createdOn = imagePushedAt
738
749
}
739
- buildArtifact := & repository.CiArtifact {
740
- Image : request .Image ,
741
- ImageDigest : request .ImageDigest ,
742
- MaterialInfo : string (materialJson ),
743
- DataSource : request .DataSource ,
744
- PipelineId : pipelineModal .Id ,
745
- WorkflowId : request .WorkflowId ,
746
- ScanEnabled : pipelineModal .ScanEnabled ,
747
- IsArtifactUploaded : request .IsArtifactUploaded , // for backward compatibility
748
- Scanned : false ,
749
- AuditLog : sql.AuditLog {CreatedBy : request .UserId , UpdatedBy : request .UserId , CreatedOn : createdOn , UpdatedOn : updatedOn },
750
- }
751
- plugin , err := impl .globalPluginRepository .GetPluginByName (bean3 .VULNERABILITY_SCANNING_PLUGIN )
752
- if err != nil || len (plugin ) == 0 {
753
- impl .logger .Errorw ("error in getting image scanning plugin" , "err" , err )
754
- return 0 , err
755
- }
756
- isScanPluginConfigured , err := impl .pipelineStageRepository .CheckPluginExistsInCiPipeline (pipelineModal .Id , string (repository4 .PIPELINE_STAGE_TYPE_POST_CI ), plugin [0 ].Id )
750
+ buildArtifact := helper .GetBuildArtifact (request , pipelineModal .Id , materialJson , createdOn , updatedOn )
751
+
752
+ isScanPluginConfigured , err := impl .isImageScanningPluginConfiguredInCiPipeline (pipelineModal .Id )
757
753
if err != nil {
758
- impl .logger .Errorw ("error in getting ci pipelineModal plugin " , "err " , err , "pipelineId " , pipelineModal . Id , "pluginId" , plugin [ 0 ]. Id )
754
+ impl .logger .Errorw ("error in checking isImageScanningPluginConfiguredInCiPipeline " , "ciPipelineId " , ciPipelineId , "err " , err )
759
755
return 0 , err
760
756
}
761
- if pipelineModal .ScanEnabled || isScanPluginConfigured {
757
+
758
+ if request .IsScanEnabled || isScanPluginConfigured {
762
759
buildArtifact .Scanned = true
763
760
buildArtifact .ScanEnabled = true
764
761
}
@@ -815,11 +812,11 @@ func (impl *WorkflowDagExecutorImpl) HandleCiSuccessEvent(triggerContext trigger
815
812
PipelineId : ci .Id ,
816
813
ParentCiArtifact : buildArtifact .Id ,
817
814
IsArtifactUploaded : request .IsArtifactUploaded , // for backward compatibility
818
- ScanEnabled : ci . ScanEnabled ,
815
+ ScanEnabled : request . IsScanEnabled ,
819
816
Scanned : false ,
820
817
AuditLog : sql.AuditLog {CreatedBy : request .UserId , UpdatedBy : request .UserId , CreatedOn : time .Now (), UpdatedOn : time .Now ()},
821
818
}
822
- if ci . ScanEnabled {
819
+ if request . IsScanEnabled {
823
820
ciArtifact .Scanned = true
824
821
}
825
822
ciArtifactArr = append (ciArtifactArr , ciArtifact )
0 commit comments