@@ -14,39 +14,39 @@ import (
14
14
)
15
15
16
16
// 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 ) {
18
18
switch {
19
19
case creds == "repocreds" :
20
20
return func (app * v1alpha1.Application ) (git.Creds , error ) {
21
- return getCredsFromArgoCD (app , kubeClient )
21
+ return getCredsFromArgoCD (wbc , kubeClient )
22
22
}, nil
23
23
case strings .HasPrefix (creds , "secret:" ):
24
24
return func (app * v1alpha1.Application ) (git.Creds , error ) {
25
- return getCredsFromSecret (app , creds [len ("secret:" ):], kubeClient )
25
+ return getCredsFromSecret (wbc , creds [len ("secret:" ):], kubeClient )
26
26
}, nil
27
27
}
28
28
return nil , fmt .Errorf ("unexpected credentials format. Expected 'repocreds' or 'secret:<namespace>/<secret>' but got '%s'" , creds )
29
29
}
30
30
31
31
// 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 ) {
33
33
ctx , cancel := context .WithCancel (context .Background ())
34
34
defer cancel ()
35
35
36
36
settingsMgr := settings .NewSettingsManager (ctx , kubeClient .Clientset , kubeClient .Namespace )
37
37
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 )
39
39
if err != nil {
40
40
return nil , err
41
41
}
42
42
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 )
44
44
}
45
45
return repo .GetGitCreds (nil ), nil
46
46
}
47
47
48
48
// 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 ) {
50
50
var credentials map [string ][]byte
51
51
var err error
52
52
s := strings .SplitN (credentialsSecret , "/" , 2 )
@@ -59,13 +59,13 @@ func getCredsFromSecret(app *v1alpha1.Application, credentialsSecret string, kub
59
59
return nil , fmt .Errorf ("secret ref must be in format 'namespace/name', but is '%s'" , credentialsSecret )
60
60
}
61
61
62
- if ok , _ := git .IsSSHURL (app . Spec . Source . RepoURL ); ok {
62
+ if ok , _ := git .IsSSHURL (wbc . GitRepo ); ok {
63
63
var sshPrivateKey []byte
64
64
if sshPrivateKey , ok = credentials ["sshPrivateKey" ]; ! ok {
65
65
return nil , fmt .Errorf ("invalid secret %s: does not contain field sshPrivateKey" , credentialsSecret )
66
66
}
67
67
return git .NewSSHCreds (string (sshPrivateKey ), "" , true ), nil
68
- } else if git .IsHTTPSURL (app . Spec . Source . RepoURL ) {
68
+ } else if git .IsHTTPSURL (wbc . GitRepo ) {
69
69
var username , password []byte
70
70
if username , ok = credentials ["username" ]; ! ok {
71
71
return nil , fmt .Errorf ("invalid secret %s: does not contain field username" , credentialsSecret )
0 commit comments