@@ -35,6 +35,7 @@ type Config struct {
35
35
VaultToken string
36
36
VaultPath string
37
37
VaultRenewal time.Duration
38
+ VaultConfig string
38
39
}
39
40
40
41
// App stores application state
@@ -52,19 +53,6 @@ func Initialise(c Config) (app *App, err error) {
52
53
53
54
app .config = c
54
55
55
- var authMethod transport.AuthMethod
56
- if c .SSH {
57
- authMethod , err = ssh .NewSSHAgentAuth ("git" )
58
- if err != nil {
59
- return nil , errors .Wrap (err , "failed to set up SSH authentication" )
60
- }
61
- } else if c .Target .User != "" {
62
- authMethod = & http.BasicAuth {
63
- Username : c .Target .User ,
64
- Password : c .Target .Pass ,
65
- }
66
- }
67
-
68
56
var secretStore secret.Store
69
57
if c .VaultAddress != "" {
70
58
zap .L ().Debug ("connecting to vault" ,
@@ -83,6 +71,18 @@ func Initialise(c Config) (app *App, err error) {
83
71
}
84
72
}
85
73
74
+ secretConfig , err := secretStore .GetSecretsForTarget (c .VaultConfig )
75
+ if err != nil {
76
+ zap .L ().Info ("could not read additional config from vault" , zap .String ("path" , c .VaultConfig ))
77
+ err = nil
78
+ }
79
+ zap .L ().Debug ("read configuration secrets from secret store" , zap .Strings ("keys" , getKeys (secretConfig )))
80
+
81
+ authMethod , err := getAuthMethod (c , secretConfig )
82
+ if err != nil {
83
+ return nil , errors .Wrap (err , "failed to create an authentication method from the given config" )
84
+ }
85
+
86
86
app .secrets = secretStore
87
87
88
88
app .bus = make (chan task.ExecutionTask , 100 )
@@ -143,3 +143,39 @@ func (app *App) Start(ctx context.Context) error {
143
143
144
144
return g .Wait ()
145
145
}
146
+
147
+ func getAuthMethod (c Config , secretConfig map [string ]string ) (transport.AuthMethod , error ) {
148
+ if c .SSH {
149
+ authMethod , err := ssh .NewSSHAgentAuth ("git" )
150
+ if err != nil {
151
+ return nil , errors .Wrap (err , "failed to set up SSH authentication" )
152
+ }
153
+ return authMethod , nil
154
+ }
155
+
156
+ if c .Target .User != "" && c .Target .Pass != "" {
157
+ return & http.BasicAuth {
158
+ Username : c .Target .User ,
159
+ Password : c .Target .Pass ,
160
+ }, nil
161
+ }
162
+
163
+ user , userok := secretConfig ["GIT_USERNAME" ]
164
+ pass , passok := secretConfig ["GIT_PASSWORD" ]
165
+ if userok && passok {
166
+ return & http.BasicAuth {
167
+ Username : user ,
168
+ Password : pass ,
169
+ }, nil
170
+ }
171
+
172
+ return nil , nil
173
+ }
174
+
175
+ func getKeys (m map [string ]string ) []string {
176
+ keys := make ([]string , 0 , len (m ))
177
+ for k := range m {
178
+ keys = append (keys , k )
179
+ }
180
+ return keys
181
+ }
0 commit comments