@@ -14,39 +14,39 @@ import (
1414)
1515
1616// getGitCredsSource returns git credentials source that loads credentials from the secret or from Argo CD settings
17- func getGitCredsSource (creds string , kubeClient * kube.KubernetesClient ) (GitCredsSource , error ) {
17+ func getGitCredsSource (creds string , kubeClient * kube.KubernetesClient , wbc * WriteBackConfig ) (GitCredsSource , error ) {
1818 switch {
1919 case creds == "repocreds" :
2020 return func (app * v1alpha1.Application ) (git.Creds , error ) {
21- return getCredsFromArgoCD (app , kubeClient )
21+ return getCredsFromArgoCD (wbc , kubeClient )
2222 }, nil
2323 case strings .HasPrefix (creds , "secret:" ):
2424 return func (app * v1alpha1.Application ) (git.Creds , error ) {
25- return getCredsFromSecret (app , creds [len ("secret:" ):], kubeClient )
25+ return getCredsFromSecret (wbc , creds [len ("secret:" ):], kubeClient )
2626 }, nil
2727 }
2828 return nil , fmt .Errorf ("unexpected credentials format. Expected 'repocreds' or 'secret:<namespace>/<secret>' but got '%s'" , creds )
2929}
3030
3131// getCredsFromArgoCD loads repository credentials from Argo CD settings
32- func getCredsFromArgoCD (app * v1alpha1. Application , kubeClient * kube.KubernetesClient ) (git.Creds , error ) {
32+ func getCredsFromArgoCD (wbc * WriteBackConfig , kubeClient * kube.KubernetesClient ) (git.Creds , error ) {
3333 ctx , cancel := context .WithCancel (context .Background ())
3434 defer cancel ()
3535
3636 settingsMgr := settings .NewSettingsManager (ctx , kubeClient .Clientset , kubeClient .Namespace )
3737 argocdDB := db .NewDB (kubeClient .Namespace , settingsMgr , kubeClient .Clientset )
38- repo , err := argocdDB .GetRepository (ctx , app . Spec . Source . RepoURL )
38+ repo , err := argocdDB .GetRepository (ctx , wbc . GitRepo )
3939 if err != nil {
4040 return nil , err
4141 }
4242 if ! repo .HasCredentials () {
43- return nil , fmt .Errorf ("credentials for '%s' are not configured in Argo CD settings" , app . Spec . Source . RepoURL )
43+ return nil , fmt .Errorf ("credentials for '%s' are not configured in Argo CD settings" , wbc . GitRepo )
4444 }
4545 return repo .GetGitCreds (), nil
4646}
4747
4848// getCredsFromSecret loads repository credentials from secret
49- func getCredsFromSecret (app * v1alpha1. Application , credentialsSecret string , kubeClient * kube.KubernetesClient ) (git.Creds , error ) {
49+ func getCredsFromSecret (wbc * WriteBackConfig , credentialsSecret string , kubeClient * kube.KubernetesClient ) (git.Creds , error ) {
5050 var credentials map [string ][]byte
5151 var err error
5252 s := strings .SplitN (credentialsSecret , "/" , 2 )
@@ -59,13 +59,13 @@ func getCredsFromSecret(app *v1alpha1.Application, credentialsSecret string, kub
5959 return nil , fmt .Errorf ("secret ref must be in format 'namespace/name', but is '%s'" , credentialsSecret )
6060 }
6161
62- if ok , _ := git .IsSSHURL (app . Spec . Source . RepoURL ); ok {
62+ if ok , _ := git .IsSSHURL (wbc . GitRepo ); ok {
6363 var sshPrivateKey []byte
6464 if sshPrivateKey , ok = credentials ["sshPrivateKey" ]; ! ok {
6565 return nil , fmt .Errorf ("invalid secret %s: does not contain field sshPrivateKey" , credentialsSecret )
6666 }
6767 return git .NewSSHCreds (string (sshPrivateKey ), "" , true ), nil
68- } else if git .IsHTTPSURL (app . Spec . Source . RepoURL ) {
68+ } else if git .IsHTTPSURL (wbc . GitRepo ) {
6969 var username , password []byte
7070 if username , ok = credentials ["username" ]; ! ok {
7171 return nil , fmt .Errorf ("invalid secret %s: does not contain field username" , credentialsSecret )
0 commit comments