Skip to content

Commit 64f31bb

Browse files
authored
chore: refactoring image tagging reader service (#6063)
* chore: refactoring image tagging reader service * added licencing comment * moved method GetImageTaggingServiceConfig in read service * moved ImageTaggingService.go * fix: TestImageTaggingService unit test cases * added mock file * fix: TestImageTaggingService unit test cases
1 parent 2895460 commit 64f31bb

File tree

18 files changed

+1227
-195
lines changed

18 files changed

+1227
-195
lines changed

Wire.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ import (
122122
"github.com/devtron-labs/devtron/pkg/asyncProvider"
123123
"github.com/devtron-labs/devtron/pkg/attributes"
124124
"github.com/devtron-labs/devtron/pkg/build"
125+
"github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging"
125126
pipeline6 "github.com/devtron-labs/devtron/pkg/build/pipeline"
126127
"github.com/devtron-labs/devtron/pkg/bulkAction"
127128
"github.com/devtron-labs/devtron/pkg/chart"
@@ -209,7 +210,7 @@ func InitializeApp() (*App, error) {
209210
fluxApplication.FluxApplicationWireSet,
210211
eventProcessor.EventProcessorWireSet,
211212
workflow3.WorkflowWireSet,
212-
213+
imageTagging.WireSet,
213214
devtronResource.DevtronResourceWireSet,
214215
// -------wireset end ----------
215216
// -------
@@ -446,8 +447,8 @@ func InitializeApp() (*App, error) {
446447
// session.NewK8sClient,
447448
repository8.NewImageTaggingRepositoryImpl,
448449
wire.Bind(new(repository8.ImageTaggingRepository), new(*repository8.ImageTaggingRepositoryImpl)),
449-
pipeline.NewImageTaggingServiceImpl,
450-
wire.Bind(new(pipeline.ImageTaggingService), new(*pipeline.ImageTaggingServiceImpl)),
450+
imageTagging.NewImageTaggingServiceImpl,
451+
wire.Bind(new(imageTagging.ImageTaggingService), new(*imageTagging.ImageTaggingServiceImpl)),
451452
argocdServer.NewVersionServiceImpl,
452453
wire.Bind(new(argocdServer.VersionService), new(*argocdServer.VersionServiceImpl)),
453454

api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"encoding/json"
2222
"errors"
2323
"fmt"
24+
"github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging"
2425
"github.com/devtron-labs/devtron/internal/sql/constants"
2526
bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
2627
"golang.org/x/exp/maps"
@@ -1110,7 +1111,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetBuildHistory(w http.ResponseWri
11101111
common.WriteJsonResp(w, err, resp, http.StatusInternalServerError)
11111112
return
11121113
}
1113-
appTags, err := handler.imageTaggingService.GetUniqueTagsByAppId(ciPipeline.AppId)
1114+
appTags, err := handler.imageTaggingReadService.GetUniqueTagsByAppId(ciPipeline.AppId)
11141115
if err != nil {
11151116
handler.Logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", ciPipeline.AppId)
11161117
common.WriteJsonResp(w, err, resp, http.StatusInternalServerError)
@@ -1120,7 +1121,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetBuildHistory(w http.ResponseWri
11201121

11211122
prodEnvExists, err := handler.imageTaggingService.GetProdEnvFromParentAndLinkedWorkflow(ciPipeline.Id)
11221123
resp.TagsEditable = prodEnvExists && triggerAccess
1123-
resp.HideImageTaggingHardDelete = handler.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete
1124+
resp.HideImageTaggingHardDelete = handler.imageTaggingService.IsHardDeleteHidden()
11241125
if err != nil {
11251126
handler.Logger.Errorw("service err, GetProdEnvFromParentAndLinkedWorkflow", "err", err, "ciPipelineId", ciPipeline.Id)
11261127
common.WriteJsonResp(w, err, resp, http.StatusInternalServerError)
@@ -2072,11 +2073,11 @@ func (handler *PipelineConfigRestHandlerImpl) CreateUpdateImageTagging(w http.Re
20722073
return
20732074
}
20742075
req.ExternalCi = externalCi
2075-
//pass it to service layer
2076+
// pass it to the service layer
20762077
resp, err := handler.imageTaggingService.CreateOrUpdateImageTagging(ciPipelineId, appId, artifactId, int(userId), req)
20772078
if err != nil {
2078-
if err.Error() == pipeline.DuplicateTagsInAppError {
2079-
appReleaseTags, err1 := handler.imageTaggingService.GetUniqueTagsByAppId(appId)
2079+
if err.Error() == imageTagging.DuplicateTagsInAppError {
2080+
appReleaseTags, err1 := handler.imageTaggingReadService.GetUniqueTagsByAppId(appId)
20802081
if err1 != nil {
20812082
handler.Logger.Errorw("error occurred in getting unique tags in app", "err", err1, "appId", appId)
20822083
err = err1
@@ -2112,7 +2113,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetImageTaggingData(w http.Respons
21122113

21132114
externalCi, ciPipelineId, appId, err := handler.extractCipipelineMetaForImageTags(artifactId)
21142115
if err != nil {
2115-
handler.Logger.Errorw("error occurred in fetching extractCipipelineMetaForImageTags by artifact Id ", "err", err, "artifactId", artifactId)
2116+
handler.Logger.Errorw("error occurred in fetching extract ci pipeline metadata for ImageTags by artifact id", "err", err, "artifactId", artifactId)
21162117
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusInternalServerError)
21172118
return
21182119
}

api/restHandler/app/pipeline/configure/DeploymentPipelineRestHandler.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetArtifactsByCDPipeline(w http.Re
13531353
return
13541354
}
13551355

1356-
appTags, err := handler.imageTaggingService.GetUniqueTagsByAppId(pipeline.AppId)
1356+
appTags, err := handler.imageTaggingReadService.GetUniqueTagsByAppId(pipeline.AppId)
13571357
if err != nil {
13581358
handler.Logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", pipeline.AppId)
13591359
common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError)
@@ -1364,7 +1364,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetArtifactsByCDPipeline(w http.Re
13641364

13651365
prodEnvExists, err := handler.imageTaggingService.GetProdEnvByCdPipelineId(pipeline.Id)
13661366
ciArtifactResponse.TagsEditable = prodEnvExists && triggerAccess
1367-
ciArtifactResponse.HideImageTaggingHardDelete = handler.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete
1367+
ciArtifactResponse.HideImageTaggingHardDelete = handler.imageTaggingService.IsHardDeleteHidden()
13681368
if err != nil {
13691369
handler.Logger.Errorw("service err, GetProdEnvByCdPipelineId", "err", err, "cdPipelineId", pipeline.Id)
13701370
common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError)
@@ -1597,7 +1597,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetArtifactsForRollback(w http.Res
15971597
common.WriteJsonResp(w, err, "unable to fetch artifacts", http.StatusInternalServerError)
15981598
return
15991599
}
1600-
appTags, err := handler.imageTaggingService.GetUniqueTagsByAppId(app.Id)
1600+
appTags, err := handler.imageTaggingReadService.GetUniqueTagsByAppId(app.Id)
16011601
if err != nil {
16021602
handler.Logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", app.Id)
16031603
common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError)
@@ -1608,7 +1608,7 @@ func (handler *PipelineConfigRestHandlerImpl) GetArtifactsForRollback(w http.Res
16081608

16091609
prodEnvExists, err := handler.imageTaggingService.GetProdEnvByCdPipelineId(cdPipelineId)
16101610
ciArtifactResponse.TagsEditable = prodEnvExists && triggerAccess
1611-
ciArtifactResponse.HideImageTaggingHardDelete = handler.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete
1611+
ciArtifactResponse.HideImageTaggingHardDelete = handler.imageTaggingService.IsHardDeleteHidden()
16121612
if err != nil {
16131613
handler.Logger.Errorw("service err, GetProdEnvByCdPipelineId", "err", err, "cdPipelineId", app.Id)
16141614
common.WriteJsonResp(w, err, ciArtifactResponse, http.StatusInternalServerError)
@@ -1723,7 +1723,7 @@ func (handler *PipelineConfigRestHandlerImpl) ListDeploymentHistory(w http.Respo
17231723
return
17241724
}
17251725

1726-
appTags, err := handler.imageTaggingService.GetUniqueTagsByAppId(appId)
1726+
appTags, err := handler.imageTaggingReadService.GetUniqueTagsByAppId(appId)
17271727
if err != nil {
17281728
handler.Logger.Errorw("service err, GetTagsByAppId", "err", err, "appId", appId)
17291729
common.WriteJsonResp(w, err, resp, http.StatusInternalServerError)
@@ -1733,7 +1733,7 @@ func (handler *PipelineConfigRestHandlerImpl) ListDeploymentHistory(w http.Respo
17331733

17341734
prodEnvExists, err := handler.imageTaggingService.GetProdEnvByCdPipelineId(pipelineId)
17351735
resp.TagsEdiatable = prodEnvExists
1736-
resp.HideImageTaggingHardDelete = handler.imageTaggingService.GetImageTaggingServiceConfig().HideImageTaggingHardDelete
1736+
resp.HideImageTaggingHardDelete = handler.imageTaggingService.IsHardDeleteHidden()
17371737
if err != nil {
17381738
handler.Logger.Errorw("service err, GetProdEnvFromParentAndLinkedWorkflow", "err", err, "cdPipelineId", pipelineId)
17391739
common.WriteJsonResp(w, err, resp, http.StatusInternalServerError)

api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121
"context"
2222
"encoding/json"
2323
"fmt"
24-
"github.com/devtron-labs/devtron/pkg/build/git/gitProvider/read"
24+
"github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging"
25+
imageTaggingRead "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read"
26+
gitProviderRead "github.com/devtron-labs/devtron/pkg/build/git/gitProvider/read"
2527
bean3 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
2628
"github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig"
2729
"github.com/devtron-labs/devtron/pkg/deployment/manifest/deployedAppMetrics"
@@ -121,9 +123,10 @@ type PipelineConfigRestHandlerImpl struct {
121123
materialRepository pipelineConfig.MaterialRepository
122124
policyService security2.PolicyService
123125
scanResultRepository security.ImageScanResultRepository
124-
gitProviderReadService read.GitProviderReadService
126+
gitProviderReadService gitProviderRead.GitProviderReadService
125127
argoUserService argo.ArgoUserService
126-
imageTaggingService pipeline.ImageTaggingService
128+
imageTaggingReadService imageTaggingRead.ImageTaggingReadService
129+
imageTaggingService imageTagging.ImageTaggingService
127130
deploymentTemplateService generateManifest.DeploymentTemplateService
128131
pipelineRestHandlerEnvConfig *PipelineRestHandlerEnvConfig
129132
ciArtifactRepository repository.CiArtifactRepository
@@ -143,7 +146,8 @@ func NewPipelineRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger
143146
ciHandler pipeline.CiHandler,
144147
validator *validator.Validate,
145148
gitSensorClient gitSensor.Client,
146-
ciPipelineRepository pipelineConfig.CiPipelineRepository, pipelineRepository pipelineConfig.PipelineRepository,
149+
ciPipelineRepository pipelineConfig.CiPipelineRepository,
150+
pipelineRepository pipelineConfig.PipelineRepository,
147151
enforcerUtil rbac.EnforcerUtil,
148152
dockerRegistryConfig pipeline.DockerRegistryConfig,
149153
cdHandler pipeline.CdHandler,
@@ -153,12 +157,13 @@ func NewPipelineRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger
153157
materialRepository pipelineConfig.MaterialRepository, policyService security2.PolicyService,
154158
scanResultRepository security.ImageScanResultRepository,
155159
argoUserService argo.ArgoUserService, ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository,
156-
imageTaggingService pipeline.ImageTaggingService,
160+
imageTaggingReadService imageTaggingRead.ImageTaggingReadService,
161+
imageTaggingService imageTagging.ImageTaggingService,
157162
ciArtifactRepository repository.CiArtifactRepository,
158163
deployedAppMetricsService deployedAppMetrics.DeployedAppMetricsService,
159164
chartRefService chartRef.ChartRefService,
160165
ciCdPipelineOrchestrator pipeline.CiCdPipelineOrchestrator,
161-
gitProviderReadService read.GitProviderReadService) *PipelineConfigRestHandlerImpl {
166+
gitProviderReadService gitProviderRead.GitProviderReadService) *PipelineConfigRestHandlerImpl {
162167
envConfig := &PipelineRestHandlerEnvConfig{}
163168
err := env.Parse(envConfig)
164169
if err != nil {
@@ -189,6 +194,7 @@ func NewPipelineRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger
189194
scanResultRepository: scanResultRepository,
190195
argoUserService: argoUserService,
191196
ciPipelineMaterialRepository: ciPipelineMaterialRepository,
197+
imageTaggingReadService: imageTaggingReadService,
192198
imageTaggingService: imageTaggingService,
193199
deploymentTemplateService: deploymentTemplateService,
194200
pipelineRestHandlerEnvConfig: envConfig,

0 commit comments

Comments
 (0)