@@ -46,7 +46,7 @@ type DockerRegistryConfig interface {
4646 Delete (storeId string ) (string , error )
4747 DeleteReg (bean * types.DockerArtifactStoreBean ) error
4848 CheckInActiveDockerAccount (storeId string ) (bool , error )
49- ValidateRegistryCredentials (bean * types.DockerArtifactStoreBean ) bool
49+ ValidateRegistryCredentials (bean * types.DockerArtifactStoreBean ) error
5050 ConfigureOCIRegistry (bean * types.DockerArtifactStoreBean , isUpdate bool , userId int32 , tx * pg.Tx ) error
5151 CreateOrUpdateOCIRegistryConfig (ociRegistryConfig * repository.OCIRegistryConfig , userId int32 , tx * pg.Tx ) error
5252 FilterOCIRegistryConfigForSpecificRepoType (ociRegistryConfigList []* repository.OCIRegistryConfig , repositoryType string ) * repository.OCIRegistryConfig
@@ -578,13 +578,8 @@ func (impl DockerRegistryConfigImpl) Update(bean *types.DockerArtifactStoreBean)
578578 bean .PluginId = existingStore .PluginId
579579
580580 store := NewDockerArtifactStore (bean , true , existingStore .CreatedOn , time .Now (), existingStore .CreatedBy , bean .User )
581- if isValid := impl .ValidateRegistryCredentials (bean ); ! isValid {
582- impl .logger .Errorw ("registry credentials validation err, SaveDockerRegistryConfig" , "err" , err , "payload" , bean )
583- err = & util.ApiError {
584- HttpStatusCode : http .StatusBadRequest ,
585- InternalMessage : "Invalid authentication credentials. Please verify." ,
586- UserMessage : "Invalid authentication credentials. Please verify." ,
587- }
581+ if err = impl .ValidateRegistryCredentials (bean ); err != nil {
582+ impl .logger .Errorw ("registry credentials validation err, SaveDockerRegistryConfig" , "err" , err )
588583 return nil , err
589584 }
590585 err = impl .dockerArtifactStoreRepository .Update (store , tx )
@@ -888,12 +883,14 @@ func (impl DockerRegistryConfigImpl) CheckInActiveDockerAccount(storeId string)
888883 return exist , nil
889884}
890885
891- func (impl DockerRegistryConfigImpl ) ValidateRegistryCredentials (bean * types.DockerArtifactStoreBean ) bool {
886+ const ociRegistryInvalidCredsMsg = "Invalid authentication credentials. Please verify."
887+
888+ func (impl DockerRegistryConfigImpl ) ValidateRegistryCredentials (bean * types.DockerArtifactStoreBean ) error {
892889 if bean .IsPublic ||
893890 bean .RegistryType == repository .REGISTRYTYPE_GCR ||
894891 bean .RegistryType == repository .REGISTRYTYPE_ARTIFACT_REGISTRY ||
895892 bean .RegistryType == repository .REGISTRYTYPE_OTHER {
896- return true
893+ return nil
897894 }
898895 request := & bean2.RegistryCredential {
899896 RegistryUrl : bean .RegistryURL ,
@@ -906,5 +903,21 @@ func (impl DockerRegistryConfigImpl) ValidateRegistryCredentials(bean *types.Doc
906903 IsPublic : bean .IsPublic ,
907904 Connection : bean .Connection ,
908905 }
909- return impl .helmAppService .ValidateOCIRegistry (context .Background (), request )
906+
907+ isLoggedIn , err := impl .helmAppService .ValidateOCIRegistry (context .Background (), request )
908+ if err != nil {
909+ impl .logger .Errorw ("error in fetching chart" , "err" , err )
910+ return util .NewApiError ().
911+ WithUserMessage ("error in validating oci registry" ).
912+ WithInternalMessage (err .Error ()).
913+ WithHttpStatusCode (http .StatusInternalServerError )
914+ }
915+ if ! isLoggedIn {
916+ return util .NewApiError ().
917+ WithUserMessage (ociRegistryInvalidCredsMsg ).
918+ WithInternalMessage (ociRegistryInvalidCredsMsg ).
919+ WithHttpStatusCode (http .StatusBadRequest )
920+ }
921+
922+ return nil
910923}
0 commit comments