From 62ea0427af981988d9087928ee158ecf22713e2c Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Wed, 12 Jul 2023 23:48:37 +0530 Subject: [PATCH 1/2] wip --- pkg/attributes/AttributesService.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/attributes/AttributesService.go b/pkg/attributes/AttributesService.go index ed3dae7e9d1..fe0b29ddc6c 100644 --- a/pkg/attributes/AttributesService.go +++ b/pkg/attributes/AttributesService.go @@ -240,20 +240,10 @@ func (impl AttributesServiceImpl) UpdateKeyValueByOne(key string) error { } func (impl AttributesServiceImpl) AddDeploymentEnforcementConfig(request *AttributesDto) (*AttributesDto, error) { - model, err := impl.attributesRepository.FindByKey(ENFORCE_DEPLOYMENT_TYPE_CONFIG) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in fetching deploymentEnforcementConfig from db", "error", err, "key", request.Key) - return request, err - } - dbConnection := impl.attributesRepository.GetConnection() - tx, terr := dbConnection.Begin() - if terr != nil { - return request, terr - } newConfig := make(map[string]map[string]bool) - err = json.Unmarshal([]byte(request.Value), &newConfig) - if err != nil { - return request, err + attributesErr := json.Unmarshal([]byte(request.Value), &newConfig) + if attributesErr != nil { + return request, attributesErr } for environmentId, envConfig := range newConfig { AllowedDeploymentAppTypes := 0 @@ -267,6 +257,16 @@ func (impl AttributesServiceImpl) AddDeploymentEnforcementConfig(request *Attrib "at least one deployment app type should be allowed", environmentId)) } } + model, err := impl.attributesRepository.FindByKey(ENFORCE_DEPLOYMENT_TYPE_CONFIG) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("error in fetching deploymentEnforcementConfig from db", "error", err, "key", request.Key) + return request, err + } + dbConnection := impl.attributesRepository.GetConnection() + tx, terr := dbConnection.Begin() + if terr != nil { + return request, terr + } // Rollback tx on error. defer tx.Rollback() if err == pg.ErrNoRows { From 27a58e3d335b915f199f45b6dd83cbd395ffe03f Mon Sep 17 00:00:00 2001 From: ayushmaheshwari Date: Thu, 13 Jul 2023 00:00:37 +0530 Subject: [PATCH 2/2] wip --- pkg/attributes/AttributesService.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/attributes/AttributesService.go b/pkg/attributes/AttributesService.go index fe0b29ddc6c..1f7b24403b6 100644 --- a/pkg/attributes/AttributesService.go +++ b/pkg/attributes/AttributesService.go @@ -257,11 +257,6 @@ func (impl AttributesServiceImpl) AddDeploymentEnforcementConfig(request *Attrib "at least one deployment app type should be allowed", environmentId)) } } - model, err := impl.attributesRepository.FindByKey(ENFORCE_DEPLOYMENT_TYPE_CONFIG) - if err != nil && err != pg.ErrNoRows { - impl.logger.Errorw("error in fetching deploymentEnforcementConfig from db", "error", err, "key", request.Key) - return request, err - } dbConnection := impl.attributesRepository.GetConnection() tx, terr := dbConnection.Begin() if terr != nil { @@ -269,6 +264,12 @@ func (impl AttributesServiceImpl) AddDeploymentEnforcementConfig(request *Attrib } // Rollback tx on error. defer tx.Rollback() + + model, err := impl.attributesRepository.FindByKey(ENFORCE_DEPLOYMENT_TYPE_CONFIG) + if err != nil && err != pg.ErrNoRows { + impl.logger.Errorw("error in fetching deploymentEnforcementConfig from db", "error", err, "key", request.Key) + return request, err + } if err == pg.ErrNoRows { model := &repository.Attributes{ Key: ENFORCE_DEPLOYMENT_TYPE_CONFIG,