Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Deployment enforcement config save err #3626

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions pkg/attributes/AttributesService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -267,8 +257,19 @@ func (impl AttributesServiceImpl) AddDeploymentEnforcementConfig(request *Attrib
"at least one deployment app type should be allowed", environmentId))
}
}
dbConnection := impl.attributesRepository.GetConnection()
tx, terr := dbConnection.Begin()
if terr != nil {
return request, terr
}
// 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,
Expand Down