From 50fa9b81cebe256668cba19ae8d1320ad817788a Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Wed, 8 Feb 2023 18:47:13 +0530 Subject: [PATCH 1/8] Hide GitOps token --- pkg/gitops/GitOpsConfigService.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/gitops/GitOpsConfigService.go b/pkg/gitops/GitOpsConfigService.go index 115831c7d7..584cdeddd1 100644 --- a/pkg/gitops/GitOpsConfigService.go +++ b/pkg/gitops/GitOpsConfigService.go @@ -137,6 +137,18 @@ func (impl *GitOpsConfigServiceImpl) ValidateAndCreateGitOpsConfig(config *bean2 return detailedErrorGitOpsConfigResponse, nil } func (impl *GitOpsConfigServiceImpl) ValidateAndUpdateGitOpsConfig(config *bean2.GitOpsConfigDto) (DetailedErrorGitOpsConfigResponse, error) { + if config.Token == "" { + model, err := impl.gitOpsRepository.GetGitOpsConfigById(config.Id) + if err != nil { + impl.logger.Errorw("No matching entry found for update.", "id", config.Id) + err = &util.ApiError{ + InternalMessage: "gitops config update failed, does not exist", + UserMessage: "gitops config update failed, does not exist", + } + return DetailedErrorGitOpsConfigResponse{}, err + } + config.Token = model.Token + } detailedErrorGitOpsConfigResponse := impl.GitOpsValidateDryRun(config) if len(detailedErrorGitOpsConfigResponse.StageErrorMap) == 0 { err := impl.UpdateGitOpsConfig(config) @@ -564,7 +576,7 @@ func (impl *GitOpsConfigServiceImpl) GetAllGitOpsConfig() ([]*bean2.GitOpsConfig GitHubOrgId: model.GitHubOrgId, GitLabGroupId: model.GitLabGroupId, Username: model.Username, - Token: model.Token, + Token: "", Host: model.Host, Active: model.Active, UserId: model.CreatedBy, From 3de84e6c0eff1c292f2e36f83ed8176c6a3798b7 Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Thu, 9 Feb 2023 08:39:06 +0530 Subject: [PATCH 2/8] Git Ops Validate without token --- pkg/gitops/GitOpsConfigService.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/gitops/GitOpsConfigService.go b/pkg/gitops/GitOpsConfigService.go index 584cdeddd1..901570aa81 100644 --- a/pkg/gitops/GitOpsConfigService.go +++ b/pkg/gitops/GitOpsConfigService.go @@ -693,6 +693,18 @@ func (impl *GitOpsConfigServiceImpl) GetGitOpsConfigActive() (*bean2.GitOpsConfi } func (impl *GitOpsConfigServiceImpl) GitOpsValidateDryRun(config *bean2.GitOpsConfigDto) DetailedErrorGitOpsConfigResponse { + if config.Token == "" { + model, err := impl.gitOpsRepository.GetGitOpsConfigById(config.Id) + if err != nil { + impl.logger.Errorw("No matching entry found for update.", "id", config.Id) + err = &util.ApiError{ + InternalMessage: "gitops config update failed, does not exist", + UserMessage: "gitops config update failed, does not exist", + } + return DetailedErrorGitOpsConfigResponse{} + } + config.Token = model.Token + } detailedErrorGitOpsConfigActions := util.DetailedErrorGitOpsConfigActions{} detailedErrorGitOpsConfigActions.StageErrorMap = make(map[string]error) /*if strings.ToUpper(config.Provider) == GITHUB_PROVIDER { From e647fa7351f2c0c2e963b810cf642889221cee8d Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Fri, 10 Feb 2023 18:07:45 +0530 Subject: [PATCH 3/8] Docker and Git hide token --- pkg/pipeline/DockerRegistryConfig.go | 24 +++++++++++++++++++----- pkg/pipeline/GitRegistryConfig.go | 27 ++++++++++++++++++--------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/pkg/pipeline/DockerRegistryConfig.go b/pkg/pipeline/DockerRegistryConfig.go index bbeeb2ac4a..5bac1f3291 100644 --- a/pkg/pipeline/DockerRegistryConfig.go +++ b/pkg/pipeline/DockerRegistryConfig.go @@ -154,7 +154,7 @@ func (impl DockerRegistryConfigImpl) Create(bean *DockerArtifactStoreBean) (*Doc return bean, nil } -//list all active artifact store +// list all active artifact store func (impl DockerRegistryConfigImpl) ListAllActive() ([]DockerArtifactStoreBean, error) { impl.logger.Debug("list docker repo request") stores, err := impl.dockerArtifactStoreRepository.FindAllActiveForAutocomplete() @@ -175,7 +175,8 @@ func (impl DockerRegistryConfigImpl) ListAllActive() ([]DockerArtifactStoreBean, return storeBeans, err } -/** +/* +* this method used for getting all the docker account details */ func (impl DockerRegistryConfigImpl) FetchAllDockerAccounts() ([]DockerArtifactStoreBean, error) { @@ -194,10 +195,10 @@ func (impl DockerRegistryConfigImpl) FetchAllDockerAccounts() ([]DockerArtifactS RegistryURL: store.RegistryURL, RegistryType: store.RegistryType, AWSAccessKeyId: store.AWSAccessKeyId, - AWSSecretAccessKey: store.AWSSecretAccessKey, + AWSSecretAccessKey: "", AWSRegion: store.AWSRegion, Username: store.Username, - Password: store.Password, + Password: "", IsDefault: store.IsDefault, Connection: store.Connection, Cert: store.Cert, @@ -216,7 +217,8 @@ func (impl DockerRegistryConfigImpl) FetchAllDockerAccounts() ([]DockerArtifactS return storeBeans, err } -/** +/* +* this method used for getting all the docker account details */ func (impl DockerRegistryConfigImpl) FetchOneDockerAccount(storeId string) (*DockerArtifactStoreBean, error) { @@ -275,6 +277,18 @@ func (impl DockerRegistryConfigImpl) Update(bean *DockerArtifactStoreBean) (*Doc defer tx.Rollback() // 3- update docker_registry_config + if bean.Password == "" { + bean.Password = existingStore.Password + } + + if bean.AWSSecretAccessKey == "" { + bean.AWSSecretAccessKey = existingStore.AWSSecretAccessKey + } + + if bean.Cert == "" { + bean.Cert = existingStore.Cert + } + store := &repository.DockerArtifactStore{ Id: bean.Id, PluginId: existingStore.PluginId, diff --git a/pkg/pipeline/GitRegistryConfig.go b/pkg/pipeline/GitRegistryConfig.go index e210915fc7..5914111cee 100644 --- a/pkg/pipeline/GitRegistryConfig.go +++ b/pkg/pipeline/GitRegistryConfig.go @@ -126,7 +126,7 @@ func (impl GitRegistryConfigImpl) Create(request *GitRegistry) (*GitRegistry, er return request, nil } -//get all active git providers +// get all active git providers func (impl GitRegistryConfigImpl) GetAll() ([]GitRegistry, error) { impl.logger.Debug("get all provider request") providers, err := impl.gitProviderRepo.FindAllActiveForAutocomplete() @@ -162,10 +162,10 @@ func (impl GitRegistryConfigImpl) FetchAllGitProviders() ([]GitRegistry, error) Name: provider.Name, Url: provider.Url, UserName: provider.UserName, - Password: provider.Password, + Password: "", AuthMode: provider.AuthMode, - AccessToken: provider.AccessToken, - SshPrivateKey: provider.SshPrivateKey, + AccessToken: "", + SshPrivateKey: "", Active: provider.Active, UserId: provider.CreatedBy, GitHostId: provider.GitHostId, @@ -226,6 +226,15 @@ func (impl GitRegistryConfigImpl) Update(request *GitRegistry) (*GitRegistry, er } return nil, err0 } + if request.Password == "" { + request.Password = existingProvider.Password + } + if request.SshPrivateKey == "" { + request.SshPrivateKey = existingProvider.SshPrivateKey + } + if request.AccessToken == "" { + request.AccessToken = existingProvider.AccessToken + } provider := &repository.GitProvider{ Name: request.Name, Url: request.Url, @@ -264,19 +273,19 @@ func (impl GitRegistryConfigImpl) Update(request *GitRegistry) (*GitRegistry, er return request, nil } -func (impl GitRegistryConfigImpl) Delete(request *GitRegistry) error{ +func (impl GitRegistryConfigImpl) Delete(request *GitRegistry) error { providerId := strconv.Itoa(request.Id) gitProviderConfig, err := impl.gitProviderRepo.FindOne(providerId) - if err != nil{ - impl.logger.Errorw("No matching entry found for delete.", "id", request.Id, "err",err) + if err != nil { + impl.logger.Errorw("No matching entry found for delete.", "id", request.Id, "err", err) return err } deleteReq := gitProviderConfig deleteReq.UpdatedOn = time.Now() deleteReq.UpdatedBy = request.UserId err = impl.gitProviderRepo.MarkProviderDeleted(&deleteReq) - if err != nil{ - impl.logger.Errorw("err in deleting git account", "id", request.Id,"err",err) + if err != nil { + impl.logger.Errorw("err in deleting git account", "id", request.Id, "err", err) return err } deleteReq.Active = false From 3593a580ff3b004745b2b6170042e6309f57b8ff Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Mon, 13 Feb 2023 20:33:58 +0530 Subject: [PATCH 4/8] SSO Login Token Hide --- pkg/sso/SSOLoginService.go | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/pkg/sso/SSOLoginService.go b/pkg/sso/SSOLoginService.go index 97b01f51b0..5d04bf3635 100644 --- a/pkg/sso/SSOLoginService.go +++ b/pkg/sso/SSOLoginService.go @@ -47,6 +47,21 @@ type SSOLoginServiceImpl struct { userAuthOidcHelper auth.UserAuthOidcHelper } +type Configs struct { + Issuer string `json:"issuer"` + ClientID string `json:"clientID"` + ClientSecret string `json:"clientSecret"` + RedirectURI string `json:"redirectURI"` + HostedDomains []string `json:"hostedDomains"` +} + +type Config struct { + Id string `json:"id"` + Type string `json:"type"` + Name string `json:"name"` + Config Configs `json:"config"` +} + func NewSSOLoginServiceImpl( logger *zap.SugaredLogger, ssoLoginRepository SSOLoginRepository, @@ -160,9 +175,22 @@ func (impl SSOLoginServiceImpl) UpdateSSOLogin(request *bean.SSOLoginDto) (*bean } } } + configString := string(configDataByte) + var configData Config + err = json.Unmarshal([]byte(configString), &configData) + var modelConfigData Config + err = json.Unmarshal([]byte(model.Config), &modelConfigData) + if configData.Config.ClientID == "" { + configData.Config.ClientID = modelConfigData.Config.ClientID + } + if configData.Config.ClientSecret == "" { + configData.Config.ClientSecret = modelConfigData.Config.ClientSecret + } + newConfigString, _ := json.Marshal(configData) + updatedConfig := string(newConfigString) model.Label = request.Label model.Url = request.Url - model.Config = string(configDataByte) + model.Config = updatedConfig model.Active = true model.UpdatedBy = request.UserId model.UpdatedOn = time.Now() @@ -322,8 +350,13 @@ func (impl SSOLoginServiceImpl) GetByName(name string) (*bean.SSOLoginDto, error if err == pg.ErrNoRows { return nil, nil } + var configData Config + err = json.Unmarshal([]byte(model.Config), &configData) + configData.Config.ClientID = "" + configData.Config.ClientSecret = "" + configString, _ := json.Marshal(configData) var config json.RawMessage - err = json.Unmarshal([]byte(model.Config), &config) + err = json.Unmarshal(configString, &config) if err != nil { impl.logger.Warnw("error while Unmarshal", "error", err) } From 0c08901d441ef9f5521928b9ef5a504d1f895d6a Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Wed, 15 Feb 2023 11:26:08 +0530 Subject: [PATCH 5/8] restore-deleted-reg --- api/restHandler/DockerRegRestHandler.go | 18 ++++ .../DockerArtifactStoreRepository.go | 21 +++++ pkg/pipeline/DockerRegistryConfig.go | 94 +++++++++++++++++++ 3 files changed, 133 insertions(+) diff --git a/api/restHandler/DockerRegRestHandler.go b/api/restHandler/DockerRegRestHandler.go index a3780e3409..1f5f9238de 100644 --- a/api/restHandler/DockerRegRestHandler.go +++ b/api/restHandler/DockerRegRestHandler.go @@ -113,6 +113,24 @@ func (impl DockerRegRestHandlerImpl) SaveDockerRegistryConfig(w http.ResponseWri return } //RBAC enforcer Ends + exist, err := impl.dockerRegistryConfig.CheckInActiveDockerAccount(bean.Id) + + if err != nil { + impl.logger.Errorw("service err, SaveDockerRegistryConfig", "err", err, "payload", bean) + common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) + return + } + + if exist { + res, err := impl.dockerRegistryConfig.UpdateInactive(&bean) + if err != nil { + impl.logger.Errorw("service err, UpdateDockerRegistryConfig", "err", err, "payload", bean) + common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) + return + } + common.WriteJsonResp(w, err, res, http.StatusOK) + return + } res, err := impl.dockerRegistryConfig.Create(&bean) if err != nil { diff --git a/internal/sql/repository/dockerRegistry/DockerArtifactStoreRepository.go b/internal/sql/repository/dockerRegistry/DockerArtifactStoreRepository.go index b5c2b8b3f4..071ed394cd 100644 --- a/internal/sql/repository/dockerRegistry/DockerArtifactStoreRepository.go +++ b/internal/sql/repository/dockerRegistry/DockerArtifactStoreRepository.go @@ -69,9 +69,11 @@ type DockerArtifactStoreRepository interface { FindAllActiveForAutocomplete() ([]DockerArtifactStore, error) FindAll() ([]DockerArtifactStore, error) FindOne(storeId string) (*DockerArtifactStore, error) + FindOneInactive(storeId string) (*DockerArtifactStore, error) Update(artifactStore *DockerArtifactStore, tx *pg.Tx) error Delete(storeId string) error MarkRegistryDeleted(artifactStore *DockerArtifactStore) error + FindInactive(storeId string) (bool, error) } type DockerArtifactStoreRepositoryImpl struct { dbConnection *pg.DB @@ -137,6 +139,16 @@ func (impl DockerArtifactStoreRepositoryImpl) FindOne(storeId string) (*DockerAr return &provider, err } +func (impl DockerArtifactStoreRepositoryImpl) FindOneInactive(storeId string) (*DockerArtifactStore, error) { + var provider DockerArtifactStore + err := impl.dbConnection.Model(&provider). + Column("docker_artifact_store.*", "IpsConfig"). + Where("docker_artifact_store.id = ?", storeId). + Where("active = ?", false). + Select() + return &provider, err +} + func (impl DockerArtifactStoreRepositoryImpl) Update(artifactStore *DockerArtifactStore, tx *pg.Tx) error { //TODO check for unique default //there can be only one default @@ -170,3 +182,12 @@ func (impl DockerArtifactStoreRepositoryImpl) MarkRegistryDeleted(deleteReq *Doc deleteReq.Active = false return impl.dbConnection.Update(deleteReq) } + +func (impl DockerArtifactStoreRepositoryImpl) FindInactive(storeId string) (bool, error) { + var provider DockerArtifactStore + exist, err := impl.dbConnection.Model(&provider). + Where("docker_artifact_store.id = ?", storeId). + Where("active = ?", false). + Exists() + return exist, err +} diff --git a/pkg/pipeline/DockerRegistryConfig.go b/pkg/pipeline/DockerRegistryConfig.go index 5bac1f3291..adadcf4814 100644 --- a/pkg/pipeline/DockerRegistryConfig.go +++ b/pkg/pipeline/DockerRegistryConfig.go @@ -34,8 +34,10 @@ type DockerRegistryConfig interface { FetchAllDockerAccounts() ([]DockerArtifactStoreBean, error) FetchOneDockerAccount(storeId string) (*DockerArtifactStoreBean, error) Update(bean *DockerArtifactStoreBean) (*DockerArtifactStoreBean, error) + UpdateInactive(bean *DockerArtifactStoreBean) (*DockerArtifactStoreBean, error) Delete(storeId string) (string, error) DeleteReg(bean *DockerArtifactStoreBean) error + CheckInActiveDockerAccount(storeId string) (bool, error) } type DockerArtifactStoreBean struct { @@ -350,6 +352,89 @@ func (impl DockerRegistryConfigImpl) Update(bean *DockerArtifactStoreBean) (*Doc return bean, nil } +func (impl DockerRegistryConfigImpl) UpdateInactive(bean *DockerArtifactStoreBean) (*DockerArtifactStoreBean, error) { + impl.logger.Debugw("docker registry update request", "request", bean) + + // 1- find by id, if err - return error + existingStore, err0 := impl.dockerArtifactStoreRepository.FindOneInactive(bean.Id) + if err0 != nil { + impl.logger.Errorw("no matching entry found of update ..", "err", err0) + return nil, err0 + } + + // 2- initiate DB transaction + dbConnection := impl.dockerArtifactStoreRepository.GetConnection() + tx, err := dbConnection.Begin() + if err != nil { + impl.logger.Errorw("error in initiating db tx", "err", err) + return nil, err + } + // Rollback tx on error. + defer tx.Rollback() + + // 3- update docker_registry_config + + store := &repository.DockerArtifactStore{ + Id: bean.Id, + PluginId: existingStore.PluginId, + RegistryURL: bean.RegistryURL, + RegistryType: bean.RegistryType, + AWSAccessKeyId: bean.AWSAccessKeyId, + AWSSecretAccessKey: bean.AWSSecretAccessKey, + AWSRegion: bean.AWSRegion, + Username: bean.Username, + Password: bean.Password, + IsDefault: bean.IsDefault, + Connection: bean.Connection, + Cert: bean.Cert, + Active: true, // later it will change + AuditLog: sql.AuditLog{CreatedBy: bean.User, CreatedOn: time.Now(), UpdatedOn: time.Now(), UpdatedBy: bean.User}, + } + err = impl.dockerArtifactStoreRepository.Update(store, tx) + if err != nil { + impl.logger.Errorw("error in updating registry config in db", "config", store, "err", err) + err = &util.ApiError{ + Code: constants.DockerRegUpdateFailedInDb, + InternalMessage: "docker registry failed to update in db", + UserMessage: "docker registry failed to update in db", + } + return nil, err + } + impl.logger.Infow("updated repository ", "repository", store) + bean.Id = store.Id + + // 4- update imagePullSecretConfig for this docker registry + dockerRegistryIpsConfig := bean.DockerRegistryIpsConfig + ipsConfig := &repository.DockerRegistryIpsConfig{ + Id: existingStore.IpsConfig.Id, + DockerArtifactStoreId: store.Id, + CredentialType: dockerRegistryIpsConfig.CredentialType, + CredentialValue: dockerRegistryIpsConfig.CredentialValue, + AppliedClusterIdsCsv: dockerRegistryIpsConfig.AppliedClusterIdsCsv, + IgnoredClusterIdsCsv: dockerRegistryIpsConfig.IgnoredClusterIdsCsv, + } + err = impl.dockerRegistryIpsConfigRepository.Update(ipsConfig, tx) + if err != nil { + impl.logger.Errorw("error in updating registry config ips", "ipsConfig", ipsConfig, "err", err) + err = &util.ApiError{ + Code: constants.DockerRegUpdateFailedInDb, + InternalMessage: "docker registry ips config failed to update in db", + UserMessage: "docker registry ips config failed to update in db", + } + return nil, err + } + impl.logger.Infow("updated ips config for this docker repository ", "ipsConfig", ipsConfig) + + // 5- now commit transaction + err = tx.Commit() + if err != nil { + impl.logger.Errorw("error in committing transaction", "err", err) + return nil, err + } + + return bean, nil +} + func (impl DockerRegistryConfigImpl) Delete(storeId string) (string, error) { impl.logger.Debugw("docker registry update request", "request", storeId) @@ -384,3 +469,12 @@ func (impl DockerRegistryConfigImpl) DeleteReg(bean *DockerArtifactStoreBean) er } return nil } + +func (impl DockerRegistryConfigImpl) CheckInActiveDockerAccount(storeId string) (bool, error) { + exist, err := impl.dockerArtifactStoreRepository.FindInactive(storeId) + if err != nil { + impl.logger.Errorw("err in deleting docker registry", "id", storeId, "err", err) + return false, err + } + return exist, nil +} From 7756dde964b4ee6a3907e4add133c8c8cd9c1a92 Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Wed, 15 Feb 2023 11:48:27 +0530 Subject: [PATCH 6/8] create-with-deleted-name --- pkg/gitops/GitOpsConfigService.go | 26 +--------------------- pkg/pipeline/GitRegistryConfig.go | 15 +++---------- pkg/sso/SSOLoginService.go | 37 ++----------------------------- 3 files changed, 6 insertions(+), 72 deletions(-) diff --git a/pkg/gitops/GitOpsConfigService.go b/pkg/gitops/GitOpsConfigService.go index 901570aa81..115831c7d7 100644 --- a/pkg/gitops/GitOpsConfigService.go +++ b/pkg/gitops/GitOpsConfigService.go @@ -137,18 +137,6 @@ func (impl *GitOpsConfigServiceImpl) ValidateAndCreateGitOpsConfig(config *bean2 return detailedErrorGitOpsConfigResponse, nil } func (impl *GitOpsConfigServiceImpl) ValidateAndUpdateGitOpsConfig(config *bean2.GitOpsConfigDto) (DetailedErrorGitOpsConfigResponse, error) { - if config.Token == "" { - model, err := impl.gitOpsRepository.GetGitOpsConfigById(config.Id) - if err != nil { - impl.logger.Errorw("No matching entry found for update.", "id", config.Id) - err = &util.ApiError{ - InternalMessage: "gitops config update failed, does not exist", - UserMessage: "gitops config update failed, does not exist", - } - return DetailedErrorGitOpsConfigResponse{}, err - } - config.Token = model.Token - } detailedErrorGitOpsConfigResponse := impl.GitOpsValidateDryRun(config) if len(detailedErrorGitOpsConfigResponse.StageErrorMap) == 0 { err := impl.UpdateGitOpsConfig(config) @@ -576,7 +564,7 @@ func (impl *GitOpsConfigServiceImpl) GetAllGitOpsConfig() ([]*bean2.GitOpsConfig GitHubOrgId: model.GitHubOrgId, GitLabGroupId: model.GitLabGroupId, Username: model.Username, - Token: "", + Token: model.Token, Host: model.Host, Active: model.Active, UserId: model.CreatedBy, @@ -693,18 +681,6 @@ func (impl *GitOpsConfigServiceImpl) GetGitOpsConfigActive() (*bean2.GitOpsConfi } func (impl *GitOpsConfigServiceImpl) GitOpsValidateDryRun(config *bean2.GitOpsConfigDto) DetailedErrorGitOpsConfigResponse { - if config.Token == "" { - model, err := impl.gitOpsRepository.GetGitOpsConfigById(config.Id) - if err != nil { - impl.logger.Errorw("No matching entry found for update.", "id", config.Id) - err = &util.ApiError{ - InternalMessage: "gitops config update failed, does not exist", - UserMessage: "gitops config update failed, does not exist", - } - return DetailedErrorGitOpsConfigResponse{} - } - config.Token = model.Token - } detailedErrorGitOpsConfigActions := util.DetailedErrorGitOpsConfigActions{} detailedErrorGitOpsConfigActions.StageErrorMap = make(map[string]error) /*if strings.ToUpper(config.Provider) == GITHUB_PROVIDER { diff --git a/pkg/pipeline/GitRegistryConfig.go b/pkg/pipeline/GitRegistryConfig.go index 5914111cee..6eda9b8fe8 100644 --- a/pkg/pipeline/GitRegistryConfig.go +++ b/pkg/pipeline/GitRegistryConfig.go @@ -162,10 +162,10 @@ func (impl GitRegistryConfigImpl) FetchAllGitProviders() ([]GitRegistry, error) Name: provider.Name, Url: provider.Url, UserName: provider.UserName, - Password: "", + Password: provider.Password, AuthMode: provider.AuthMode, - AccessToken: "", - SshPrivateKey: "", + AccessToken: provider.AccessToken, + SshPrivateKey: provider.SshPrivateKey, Active: provider.Active, UserId: provider.CreatedBy, GitHostId: provider.GitHostId, @@ -226,15 +226,6 @@ func (impl GitRegistryConfigImpl) Update(request *GitRegistry) (*GitRegistry, er } return nil, err0 } - if request.Password == "" { - request.Password = existingProvider.Password - } - if request.SshPrivateKey == "" { - request.SshPrivateKey = existingProvider.SshPrivateKey - } - if request.AccessToken == "" { - request.AccessToken = existingProvider.AccessToken - } provider := &repository.GitProvider{ Name: request.Name, Url: request.Url, diff --git a/pkg/sso/SSOLoginService.go b/pkg/sso/SSOLoginService.go index 5d04bf3635..97b01f51b0 100644 --- a/pkg/sso/SSOLoginService.go +++ b/pkg/sso/SSOLoginService.go @@ -47,21 +47,6 @@ type SSOLoginServiceImpl struct { userAuthOidcHelper auth.UserAuthOidcHelper } -type Configs struct { - Issuer string `json:"issuer"` - ClientID string `json:"clientID"` - ClientSecret string `json:"clientSecret"` - RedirectURI string `json:"redirectURI"` - HostedDomains []string `json:"hostedDomains"` -} - -type Config struct { - Id string `json:"id"` - Type string `json:"type"` - Name string `json:"name"` - Config Configs `json:"config"` -} - func NewSSOLoginServiceImpl( logger *zap.SugaredLogger, ssoLoginRepository SSOLoginRepository, @@ -175,22 +160,9 @@ func (impl SSOLoginServiceImpl) UpdateSSOLogin(request *bean.SSOLoginDto) (*bean } } } - configString := string(configDataByte) - var configData Config - err = json.Unmarshal([]byte(configString), &configData) - var modelConfigData Config - err = json.Unmarshal([]byte(model.Config), &modelConfigData) - if configData.Config.ClientID == "" { - configData.Config.ClientID = modelConfigData.Config.ClientID - } - if configData.Config.ClientSecret == "" { - configData.Config.ClientSecret = modelConfigData.Config.ClientSecret - } - newConfigString, _ := json.Marshal(configData) - updatedConfig := string(newConfigString) model.Label = request.Label model.Url = request.Url - model.Config = updatedConfig + model.Config = string(configDataByte) model.Active = true model.UpdatedBy = request.UserId model.UpdatedOn = time.Now() @@ -350,13 +322,8 @@ func (impl SSOLoginServiceImpl) GetByName(name string) (*bean.SSOLoginDto, error if err == pg.ErrNoRows { return nil, nil } - var configData Config - err = json.Unmarshal([]byte(model.Config), &configData) - configData.Config.ClientID = "" - configData.Config.ClientSecret = "" - configString, _ := json.Marshal(configData) var config json.RawMessage - err = json.Unmarshal(configString, &config) + err = json.Unmarshal([]byte(model.Config), &config) if err != nil { impl.logger.Warnw("error while Unmarshal", "error", err) } From 741e577eeba3f82c788b0fd6273a3bd29e7a4297 Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Sun, 19 Feb 2023 18:21:28 +0530 Subject: [PATCH 7/8] new-docker-artifact-dupl --- pkg/pipeline/DockerRegistryConfig.go | 76 ++++++++++------------------ 1 file changed, 28 insertions(+), 48 deletions(-) diff --git a/pkg/pipeline/DockerRegistryConfig.go b/pkg/pipeline/DockerRegistryConfig.go index adadcf4814..df46599ba4 100644 --- a/pkg/pipeline/DockerRegistryConfig.go +++ b/pkg/pipeline/DockerRegistryConfig.go @@ -81,6 +81,25 @@ func NewDockerRegistryConfigImpl(logger *zap.SugaredLogger, dockerArtifactStoreR } } +func NewDockerArtifactStore(bean *DockerArtifactStoreBean, isActive bool, createdOn time.Time, updatedOn time.Time, createdBy int32, updateBy int32) *repository.DockerArtifactStore { + return &repository.DockerArtifactStore{ + Id: bean.Id, + PluginId: bean.PluginId, + RegistryURL: bean.RegistryURL, + RegistryType: bean.RegistryType, + AWSAccessKeyId: bean.AWSAccessKeyId, + AWSSecretAccessKey: bean.AWSSecretAccessKey, + AWSRegion: bean.AWSRegion, + Username: bean.Username, + Password: bean.Password, + IsDefault: bean.IsDefault, + Connection: bean.Connection, + Cert: bean.Cert, + Active: isActive, + AuditLog: sql.AuditLog{CreatedBy: createdBy, CreatedOn: createdOn, UpdatedOn: updatedOn, UpdatedBy: updateBy}, + } +} + func (impl DockerRegistryConfigImpl) Create(bean *DockerArtifactStoreBean) (*DockerArtifactStoreBean, error) { impl.logger.Debugw("docker registry create request", "request", bean) @@ -95,22 +114,7 @@ func (impl DockerRegistryConfigImpl) Create(bean *DockerArtifactStoreBean) (*Doc defer tx.Rollback() // 2- insert docker_registry_config - store := &repository.DockerArtifactStore{ - Id: bean.Id, - PluginId: bean.PluginId, - RegistryURL: bean.RegistryURL, - RegistryType: bean.RegistryType, - AWSAccessKeyId: bean.AWSAccessKeyId, - AWSSecretAccessKey: bean.AWSSecretAccessKey, - AWSRegion: bean.AWSRegion, - Username: bean.Username, - Password: bean.Password, - IsDefault: bean.IsDefault, - Connection: bean.Connection, - Cert: bean.Cert, - Active: true, - AuditLog: sql.AuditLog{CreatedBy: bean.User, CreatedOn: time.Now(), UpdatedOn: time.Now(), UpdatedBy: bean.User}, - } + store := NewDockerArtifactStore(bean, true, time.Now(), time.Now(), bean.User, bean.User) err = impl.dockerArtifactStoreRepository.Save(store, tx) if err != nil { impl.logger.Errorw("error in saving registry config", "config", store, "err", err) @@ -291,22 +295,10 @@ func (impl DockerRegistryConfigImpl) Update(bean *DockerArtifactStoreBean) (*Doc bean.Cert = existingStore.Cert } - store := &repository.DockerArtifactStore{ - Id: bean.Id, - PluginId: existingStore.PluginId, - RegistryURL: bean.RegistryURL, - RegistryType: bean.RegistryType, - AWSAccessKeyId: bean.AWSAccessKeyId, - AWSSecretAccessKey: bean.AWSSecretAccessKey, - AWSRegion: bean.AWSRegion, - Username: bean.Username, - Password: bean.Password, - IsDefault: bean.IsDefault, - Connection: bean.Connection, - Cert: bean.Cert, - Active: true, // later it will change - AuditLog: sql.AuditLog{CreatedBy: existingStore.CreatedBy, CreatedOn: existingStore.CreatedOn, UpdatedOn: time.Now(), UpdatedBy: bean.User}, - } + bean.PluginId = existingStore.PluginId + + store := NewDockerArtifactStore(bean, true, existingStore.CreatedOn, time.Now(), existingStore.CreatedBy, bean.User) + err = impl.dockerArtifactStoreRepository.Update(store, tx) if err != nil { impl.logger.Errorw("error in updating registry config in db", "config", store, "err", err) @@ -374,22 +366,10 @@ func (impl DockerRegistryConfigImpl) UpdateInactive(bean *DockerArtifactStoreBea // 3- update docker_registry_config - store := &repository.DockerArtifactStore{ - Id: bean.Id, - PluginId: existingStore.PluginId, - RegistryURL: bean.RegistryURL, - RegistryType: bean.RegistryType, - AWSAccessKeyId: bean.AWSAccessKeyId, - AWSSecretAccessKey: bean.AWSSecretAccessKey, - AWSRegion: bean.AWSRegion, - Username: bean.Username, - Password: bean.Password, - IsDefault: bean.IsDefault, - Connection: bean.Connection, - Cert: bean.Cert, - Active: true, // later it will change - AuditLog: sql.AuditLog{CreatedBy: bean.User, CreatedOn: time.Now(), UpdatedOn: time.Now(), UpdatedBy: bean.User}, - } + bean.PluginId = existingStore.PluginId + + store := NewDockerArtifactStore(bean, true, existingStore.CreatedOn, time.Now(), bean.User, bean.User) + err = impl.dockerArtifactStoreRepository.Update(store, tx) if err != nil { impl.logger.Errorw("error in updating registry config in db", "config", store, "err", err) From 2eedf498a163e26c719fcb45925a754593fc414e Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Wed, 22 Feb 2023 19:14:12 +0530 Subject: [PATCH 8/8] change user message --- pkg/pipeline/DockerRegistryConfig.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/pipeline/DockerRegistryConfig.go b/pkg/pipeline/DockerRegistryConfig.go index df46599ba4..40232c6033 100644 --- a/pkg/pipeline/DockerRegistryConfig.go +++ b/pkg/pipeline/DockerRegistryConfig.go @@ -121,7 +121,7 @@ func (impl DockerRegistryConfigImpl) Create(bean *DockerArtifactStoreBean) (*Doc err = &util.ApiError{ Code: constants.DockerRegCreateFailedInDb, InternalMessage: "docker registry failed to create in db", - UserMessage: fmt.Sprintf("requested by %d", bean.User), + UserMessage: fmt.Sprintf("Container registry [%s] already exists.", bean.Id), } return nil, err } @@ -143,7 +143,7 @@ func (impl DockerRegistryConfigImpl) Create(bean *DockerArtifactStoreBean) (*Doc err = &util.ApiError{ Code: constants.DockerRegCreateFailedInDb, InternalMessage: "docker registry ips config to create in db", - UserMessage: fmt.Sprintf("requested by %d", bean.User), + UserMessage: fmt.Sprintf("Container registry [%s] already exists.", bean.Id), } return nil, err }