@@ -3,6 +3,7 @@ package command
3
3
import (
4
4
"bytes"
5
5
"fmt"
6
+ "io"
6
7
"os"
7
8
"os/exec"
8
9
"path/filepath"
@@ -11,13 +12,17 @@ import (
11
12
"syscall"
12
13
13
14
"github.com/codegangsta/cli"
15
+
14
16
prov "github.com/cyberark/summon/provider"
15
17
"github.com/cyberark/summon/secretsyml"
16
18
)
17
19
18
20
// ActionConfig is an object that holds all the info needed to run
19
21
// a Summon instance
20
22
type ActionConfig struct {
23
+ StdIn io.Reader
24
+ StdOut io.Writer
25
+ StdErr io.Writer
21
26
Args []string
22
27
Provider string
23
28
Filepath string
@@ -31,6 +36,7 @@ type ActionConfig struct {
31
36
}
32
37
33
38
const ENV_FILE_MAGIC = "@SUMMONENVFILE"
39
+ const DOCKER_OPTS_MAGIC = "@DOCKEROPTS"
34
40
const SUMMON_ENV_KEY_NAME = "SUMMON_ENV"
35
41
36
42
// Action is the runner for the main program logic
@@ -121,6 +127,9 @@ func runAction(ac *ActionConfig) error {
121
127
results := make (chan Result , len (secrets ))
122
128
var wg sync.WaitGroup
123
129
130
+ var dockerOpts []string
131
+ var dockerOptsMutex sync.Mutex
132
+
124
133
for key , spec := range secrets {
125
134
wg .Add (1 )
126
135
go func (key string , spec secretsyml.SecretSpec ) {
@@ -143,6 +152,16 @@ func runAction(ac *ActionConfig) error {
143
152
}
144
153
145
154
envvar := formatForEnv (key , value , spec , & tempFactory )
155
+
156
+ // Generate Docker options
157
+ dockerOptsMutex .Lock ()
158
+ defer dockerOptsMutex .Unlock ()
159
+ if spec .IsFile () {
160
+ fileValue := strings .SplitN (envvar , "=" , 2 )[1 ]
161
+ dockerOpts = append (dockerOpts , "-v" , fileValue + ":" + fileValue )
162
+ }
163
+ dockerOpts = append (dockerOpts , "-e" , key )
164
+
146
165
results <- Result {envvar , nil }
147
166
wg .Done ()
148
167
}(key , spec )
@@ -173,9 +192,38 @@ EnvLoop:
173
192
env = append (env , fmt .Sprintf ("%s=%s" , SUMMON_ENV_KEY_NAME , ac .Environment ))
174
193
}
175
194
195
+ // Setup Docker options
196
+ var argsWithDockerOpts []string
197
+ for _ , arg := range ac .Args {
198
+ //idx := strings.Index(arg, DOCKER_OPTS_MAGIC)
199
+ if arg == DOCKER_OPTS_MAGIC {
200
+ // Replace argument with slice of docker options
201
+ argsWithDockerOpts = append (argsWithDockerOpts , dockerOpts ... )
202
+ continue
203
+ }
204
+
205
+ //if idx >= 0 {
206
+ // // Replace argument with slice of docker options
207
+ // argsWithDockerOpts = append(
208
+ // argsWithDockerOpts,
209
+ // strings.Replace(arg, DOCKER_OPTS_MAGIC, strings.Join(dockerOpts, " "), -1),
210
+ // )
211
+ // continue
212
+ //}
213
+
214
+ argsWithDockerOpts = append (argsWithDockerOpts , arg )
215
+ }
216
+ ac .Args = argsWithDockerOpts
217
+
176
218
setupEnvFile (ac .Args , env , & tempFactory )
177
219
178
- return runSubcommand (ac .Args , append (os .Environ (), env ... ))
220
+ return runSubcommand (
221
+ ac .Args ,
222
+ append (os .Environ (), env ... ),
223
+ ac .StdIn ,
224
+ ac .StdOut ,
225
+ ac .StdErr ,
226
+ )
179
227
}
180
228
181
229
// formatForEnv returns a string in %k=%v format, where %k=namespace of the secret and
@@ -230,7 +278,7 @@ func findInParentTree(secretsFile string, leafDir string) (string, error) {
230
278
}
231
279
}
232
280
233
- // scans arguments for the magic string; if found,
281
+ // scans arguments for the envfile magic string; if found,
234
282
// creates a tempfile to which all the environment mappings are dumped
235
283
// and replaces the magic string with its path.
236
284
// Returns the path if so, returns an empty string otherwise.
0 commit comments