@@ -46,7 +46,7 @@ type DockerRegistryConfig interface {
46
46
Delete (storeId string ) (string , error )
47
47
DeleteReg (bean * types.DockerArtifactStoreBean ) error
48
48
CheckInActiveDockerAccount (storeId string ) (bool , error )
49
- ValidateRegistryCredentials (bean * types.DockerArtifactStoreBean ) bool
49
+ ValidateRegistryCredentials (bean * types.DockerArtifactStoreBean ) error
50
50
ConfigureOCIRegistry (bean * types.DockerArtifactStoreBean , isUpdate bool , userId int32 , tx * pg.Tx ) error
51
51
CreateOrUpdateOCIRegistryConfig (ociRegistryConfig * repository.OCIRegistryConfig , userId int32 , tx * pg.Tx ) error
52
52
FilterOCIRegistryConfigForSpecificRepoType (ociRegistryConfigList []* repository.OCIRegistryConfig , repositoryType string ) * repository.OCIRegistryConfig
@@ -578,13 +578,8 @@ func (impl DockerRegistryConfigImpl) Update(bean *types.DockerArtifactStoreBean)
578
578
bean .PluginId = existingStore .PluginId
579
579
580
580
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 )
588
583
return nil , err
589
584
}
590
585
err = impl .dockerArtifactStoreRepository .Update (store , tx )
@@ -888,12 +883,14 @@ func (impl DockerRegistryConfigImpl) CheckInActiveDockerAccount(storeId string)
888
883
return exist , nil
889
884
}
890
885
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 {
892
889
if bean .IsPublic ||
893
890
bean .RegistryType == repository .REGISTRYTYPE_GCR ||
894
891
bean .RegistryType == repository .REGISTRYTYPE_ARTIFACT_REGISTRY ||
895
892
bean .RegistryType == repository .REGISTRYTYPE_OTHER {
896
- return true
893
+ return nil
897
894
}
898
895
request := & bean2.RegistryCredential {
899
896
RegistryUrl : bean .RegistryURL ,
@@ -906,5 +903,21 @@ func (impl DockerRegistryConfigImpl) ValidateRegistryCredentials(bean *types.Doc
906
903
IsPublic : bean .IsPublic ,
907
904
Connection : bean .Connection ,
908
905
}
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
910
923
}
0 commit comments