From 9c9bb114bfc037fc33bdd230bc405cc79f1fc518 Mon Sep 17 00:00:00 2001 From: Ash-exp Date: Wed, 3 Jan 2024 17:44:05 +0530 Subject: [PATCH] updated ArtifactsSourceType const --- api/router/pubsub/CiEventHandler.go | 2 ++ .../sql/repository/AppListingRepository.go | 2 +- .../sql/repository/CiArtifactRepository.go | 19 ++++++++++--------- pkg/deploymentGroup/DeploymentGroupService.go | 2 +- pkg/pipeline/PipelineBuilder.go | 2 +- pkg/pipeline/WorkflowDagExecutor.go | 12 ++++++------ wire_gen.go | 2 +- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/api/router/pubsub/CiEventHandler.go b/api/router/pubsub/CiEventHandler.go index cc3c727ca8e..53f95fc9387 100644 --- a/api/router/pubsub/CiEventHandler.go +++ b/api/router/pubsub/CiEventHandler.go @@ -242,6 +242,7 @@ func (impl *CiEventHandlerImpl) BuildCiArtifactRequest(event CiCompleteEvent) (* PluginRegistryArtifactDetails: event.PluginRegistryArtifactDetails, PluginArtifactStage: event.PluginArtifactStage, } + // if DataSource is empty, repository.WEBHOOK is considered as default if request.DataSource == "" { request.DataSource = repository.WEBHOOK } @@ -334,6 +335,7 @@ func (impl *CiEventHandlerImpl) BuildCiArtifactRequestForWebhook(event CiComplet WorkflowId: event.WorkflowId, IsArtifactUploaded: event.IsArtifactUploaded, } + // if DataSource is empty, repository.WEBHOOK is considered as default if request.DataSource == "" { request.DataSource = repository.WEBHOOK } diff --git a/internal/sql/repository/AppListingRepository.go b/internal/sql/repository/AppListingRepository.go index a629b07a02a..ecff1f94c22 100644 --- a/internal/sql/repository/AppListingRepository.go +++ b/internal/sql/repository/AppListingRepository.go @@ -429,7 +429,7 @@ func parseMaterialInfo(materialInfo string, source string) (json.RawMessage, err fmt.Printf("PARSEMATERIALINFO_MATERIAL_RECOVER, materialInfo: %s, source: %s, err: %s \n", materialInfo, source, r) } }() - if source != GOCD && source != CI_RUNNER && source != WEBHOOK && source != DEPRICATED_EXT { + if source != GOCD && source != CI_RUNNER && source != WEBHOOK && source != EXT { return nil, fmt.Errorf("datasource: %s not supported", source) } if materialInfo == "" { diff --git a/internal/sql/repository/CiArtifactRepository.go b/internal/sql/repository/CiArtifactRepository.go index 03994a9edc7..76fefa7ebed 100644 --- a/internal/sql/repository/CiArtifactRepository.go +++ b/internal/sql/repository/CiArtifactRepository.go @@ -40,13 +40,14 @@ const ( // List of possible DataSource Type for an artifact const ( - CI_RUNNER ArtifactsSourceType = "CI-RUNNER" - WEBHOOK ArtifactsSourceType = "EXTERNAL" // Currently in use instead of DEPRICATED_EXT - PRE_CD ArtifactsSourceType = "pre_cd" - POST_CD ArtifactsSourceType = "post_cd" - POST_CI ArtifactsSourceType = "post_ci" - GOCD ArtifactsSourceType = "GOCD" - DEPRICATED_EXT ArtifactsSourceType = "ext" // For backward compatibility + CI_RUNNER ArtifactsSourceType = "CI-RUNNER" + WEBHOOK ArtifactsSourceType = "EXTERNAL" // Currently in use instead of EXT + PRE_CD ArtifactsSourceType = "pre_cd" + POST_CD ArtifactsSourceType = "post_cd" + POST_CI ArtifactsSourceType = "post_ci" + GOCD ArtifactsSourceType = "GOCD" + // deprecated; Handled for backward compatibility + EXT ArtifactsSourceType = "ext" // PRE_CI is not a valid DataSource for an artifact ) @@ -495,7 +496,7 @@ func (impl CiArtifactRepositoryImpl) GetArtifactsByCDPipelineAndRunnerType(cdPip // return map of gitUrl:hash func (info *CiArtifact) ParseMaterialInfo() (map[string]string, error) { - if info.DataSource != GOCD && info.DataSource != CI_RUNNER && info.DataSource != WEBHOOK && info.DataSource != DEPRICATED_EXT { + if info.DataSource != GOCD && info.DataSource != CI_RUNNER && info.DataSource != WEBHOOK && info.DataSource != EXT { return nil, fmt.Errorf("datasource: %s not supported", info.DataSource) } var ciMaterials []*CiMaterialInfo @@ -606,7 +607,7 @@ func (impl CiArtifactRepositoryImpl) GetArtifactsByCDPipelineV2(cdPipelineId int } func GetCiMaterialInfo(materialInfo string, source string) ([]CiMaterialInfo, error) { - if source != GOCD && source != CI_RUNNER && source != WEBHOOK && source != POST_CI && source != PRE_CD && source != POST_CD && source != DEPRICATED_EXT { + if source != GOCD && source != CI_RUNNER && source != WEBHOOK && source != POST_CI && source != PRE_CD && source != POST_CD && source != EXT { return nil, fmt.Errorf("datasource: %s not supported", source) } var ciMaterials []CiMaterialInfo diff --git a/pkg/deploymentGroup/DeploymentGroupService.go b/pkg/deploymentGroup/DeploymentGroupService.go index 34eaaf70e26..3ceb1357a29 100644 --- a/pkg/deploymentGroup/DeploymentGroupService.go +++ b/pkg/deploymentGroup/DeploymentGroupService.go @@ -610,7 +610,7 @@ func (impl *DeploymentGroupServiceImpl) GetArtifactsByCiPipeline(ciPipelineId in } func (impl *DeploymentGroupServiceImpl) parseMaterialInfo(materialInfo json.RawMessage, source string) (json.RawMessage, error) { - if source != repository.GOCD && source != repository.CI_RUNNER && source != repository.WEBHOOK && source != repository.DEPRICATED_EXT { + if source != repository.GOCD && source != repository.CI_RUNNER && source != repository.WEBHOOK && source != repository.EXT { return nil, fmt.Errorf("datasource: %s not supported", source) } var ciMaterials []repository.CiMaterialInfo diff --git a/pkg/pipeline/PipelineBuilder.go b/pkg/pipeline/PipelineBuilder.go index d9af26d2f37..06dc8d03bc0 100644 --- a/pkg/pipeline/PipelineBuilder.go +++ b/pkg/pipeline/PipelineBuilder.go @@ -253,7 +253,7 @@ type ConfigMapSecretsResponse struct { } func parseMaterialInfo(materialInfo json.RawMessage, source string) (json.RawMessage, error) { - if source != repository.GOCD && source != repository.CI_RUNNER && source != repository.WEBHOOK && source != repository.DEPRICATED_EXT && source != repository.PRE_CD && source != repository.POST_CD && source != repository.POST_CI { + if source != repository.GOCD && source != repository.CI_RUNNER && source != repository.WEBHOOK && source != repository.EXT && source != repository.PRE_CD && source != repository.POST_CD && source != repository.POST_CI { return nil, fmt.Errorf("datasource: %s not supported", source) } var ciMaterials []repository.CiMaterialInfo diff --git a/pkg/pipeline/WorkflowDagExecutor.go b/pkg/pipeline/WorkflowDagExecutor.go index c9dde1d0e41..29bb7f84750 100644 --- a/pkg/pipeline/WorkflowDagExecutor.go +++ b/pkg/pipeline/WorkflowDagExecutor.go @@ -920,7 +920,7 @@ func (impl *WorkflowDagExecutorImpl) HandlePreStageSuccessEvent(cdStageCompleteE return err } // Migration of deprecated DataSource Type - if ciArtifact.DataSource == repository.DEPRICATED_EXT { + if ciArtifact.DataSource == repository.EXT { migrationErr := impl.ciArtifactRepository.MigrateToWebHookDataSourceType(ciArtifact.Id) if migrationErr != nil { impl.logger.Warnw("unable to migrate deprecated DataSource", "artifactId", ciArtifact.Id) @@ -1286,7 +1286,7 @@ func (impl *WorkflowDagExecutorImpl) TriggerPostStage(cdWf *pipelineConfig.CdWor } } // Migration of deprecated DataSource Type - if cdWf.CiArtifact.DataSource == repository.DEPRICATED_EXT { + if cdWf.CiArtifact.DataSource == repository.EXT { migrationErr := impl.ciArtifactRepository.MigrateToWebHookDataSourceType(cdWf.CiArtifact.Id) if migrationErr != nil { impl.logger.Warnw("unable to migrate deprecated DataSource", "artifactId", cdWf.CiArtifact.Id) @@ -1457,7 +1457,7 @@ func (impl *WorkflowDagExecutorImpl) buildWFRequest(runner *pipelineConfig.CdWor return nil, err } // Migration of deprecated DataSource Type - if artifact.DataSource == repository.DEPRICATED_EXT { + if artifact.DataSource == repository.EXT { migrationErr := impl.ciArtifactRepository.MigrateToWebHookDataSourceType(artifact.Id) if migrationErr != nil { impl.logger.Warnw("unable to migrate deprecated DataSource", "artifactId", artifact.Id) @@ -2347,7 +2347,7 @@ func (impl *WorkflowDagExecutorImpl) ManualCdTrigger(overrideRequest *bean.Value return 0, err } // Migration of deprecated DataSource Type - if artifact.DataSource == repository.DEPRICATED_EXT { + if artifact.DataSource == repository.EXT { migrationErr := impl.ciArtifactRepository.MigrateToWebHookDataSourceType(artifact.Id) if migrationErr != nil { impl.logger.Warnw("unable to migrate deprecated DataSource", "artifactId", artifact.Id) @@ -2426,7 +2426,7 @@ func (impl *WorkflowDagExecutorImpl) ManualCdTrigger(overrideRequest *bean.Value return 0, err } // Migration of deprecated DataSource Type - if artifact.DataSource == repository.DEPRICATED_EXT { + if artifact.DataSource == repository.EXT { migrationErr := impl.ciArtifactRepository.MigrateToWebHookDataSourceType(artifact.Id) if migrationErr != nil { impl.logger.Warnw("unable to migrate deprecated DataSource", "artifactId", artifact.Id) @@ -2661,7 +2661,7 @@ func (impl *WorkflowDagExecutorImpl) subscribeTriggerBulkAction() error { return } // Migration of deprecated DataSource Type - if artifact.DataSource == repository.DEPRICATED_EXT { + if artifact.DataSource == repository.EXT { migrationErr := impl.ciArtifactRepository.MigrateToWebHookDataSourceType(artifact.Id) if migrationErr != nil { impl.logger.Warnw("unable to migrate deprecated DataSource", "artifactId", artifact.Id) diff --git a/wire_gen.go b/wire_gen.go index 6d77689ce6a..6b65601e387 100644 --- a/wire_gen.go +++ b/wire_gen.go @@ -578,7 +578,7 @@ func InitializeApp() (*App, error) { if err != nil { return nil, err } - ciEventHandlerImpl := pubsub.NewCiEventHandlerImpl(sugaredLogger, pubSubClientServiceImpl, webhookServiceImpl, ciEventConfig) + ciEventHandlerImpl := pubsub.NewCiEventHandlerImpl(sugaredLogger, pubSubClientServiceImpl, webhookServiceImpl, validate, ciEventConfig) externalCiRestHandlerImpl := restHandler.NewExternalCiRestHandlerImpl(sugaredLogger, webhookServiceImpl, ciEventHandlerImpl, validate, userServiceImpl, enforcerImpl, enforcerUtilImpl) pubSubClientRestHandlerImpl := restHandler.NewPubSubClientRestHandlerImpl(pubSubClientServiceImpl, sugaredLogger, ciCdConfig) webhookRouterImpl := router.NewWebhookRouterImpl(gitWebhookRestHandlerImpl, pipelineConfigRestHandlerImpl, externalCiRestHandlerImpl, pubSubClientRestHandlerImpl)