Skip to content

Commit 439d7a1

Browse files
committed
Provide feedback to user when prudent
1 parent 6187628 commit 439d7a1

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

cli/exec.go

+28-8
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ func ConfigureExecCommand(app *kingpin.Application, a *AwsVault) {
108108
StringVar(&input.ProfileName)
109109

110110
cmd.Arg("cmd", "Command to execute, defaults to $SHELL").
111-
Default(os.Getenv("SHELL")).
112111
StringVar(&input.Command)
113112

114113
cmd.Arg("args", "Command arguments").
@@ -200,14 +199,15 @@ func updateEnvForAwsVault(env environ, profileName string, region string) enviro
200199
}
201200

202201
func execEc2Server(input ExecCommandInput, config *vault.Config, credsProvider aws.CredentialsProvider) error {
202+
fmt.Fprintf(os.Stderr, "aws-vault: Starting an EC2 credential server.\n")
203203
if err := server.StartEc2CredentialsServer(context.TODO(), credsProvider, config.Region); err != nil {
204204
return fmt.Errorf("Failed to start credential server: %w", err)
205205
}
206206

207207
env := environ(os.Environ())
208208
env = updateEnvForAwsVault(env, input.ProfileName, config.Region)
209209

210-
return execCmd(input.Command, input.Args, env)
210+
return doRunCmd(input.Command, input.Args, env)
211211
}
212212

213213
func execEcsServer(input ExecCommandInput, config *vault.Config, credsProvider aws.CredentialsProvider) error {
@@ -228,7 +228,9 @@ func execEcsServer(input ExecCommandInput, config *vault.Config, credsProvider a
228228
env.Set("AWS_CONTAINER_CREDENTIALS_FULL_URI", ecsServer.BaseURL())
229229
env.Set("AWS_CONTAINER_AUTHORIZATION_TOKEN", ecsServer.AuthToken())
230230

231-
return execCmd(input.Command, input.Args, env)
231+
fmt.Fprintf(os.Stderr, "aws-vault: Starting an ECS credential server; your app's AWS sdk must support AWS_CONTAINER_CREDENTIALS_FULL_URI.\n")
232+
233+
return doRunCmd(input.Command, input.Args, env)
232234
}
233235

234236
func execCredentialHelper(input ExecCommandInput, credsProvider aws.CredentialsProvider) error {
@@ -293,10 +295,10 @@ func execEnvironment(input ExecCommandInput, config *vault.Config, credsProvider
293295
}
294296

295297
if !supportsExecSyscall() {
296-
return execCmd(input.Command, input.Args, env)
298+
return doRunCmd(input.Command, input.Args, env)
297299
}
298300

299-
return execSyscall(input.Command, input.Args, env)
301+
return doExecSyscall(input.Command, input.Args, env)
300302
}
301303

302304
// environ is a slice of strings representing the environment, in the form "key=value".
@@ -319,8 +321,21 @@ func (e *environ) Set(key, val string) {
319321
*e = append(*e, key+"="+val)
320322
}
321323

322-
func execCmd(command string, args []string, env []string) error {
323-
log.Printf("Starting child process: %s %s", command, strings.Join(args, " "))
324+
func getDefaultShell() string {
325+
command := os.Getenv("SHELL")
326+
if command == "" {
327+
command = "/bin/sh"
328+
}
329+
return command
330+
}
331+
332+
func doRunCmd(command string, args []string, env []string) error {
333+
if command == "" {
334+
command = getDefaultShell()
335+
fmt.Fprintf(os.Stderr, "aws-vault: Starting a subshell %s\n", command)
336+
}
337+
338+
log.Printf("Starting subprocess: %s %s", command, strings.Join(args, " "))
324339

325340
cmd := osexec.Command(command, args...)
326341
cmd.Stdin = os.Stdin
@@ -356,7 +371,12 @@ func supportsExecSyscall() bool {
356371
return runtime.GOOS == "linux" || runtime.GOOS == "darwin" || runtime.GOOS == "freebsd" || runtime.GOOS == "openbsd"
357372
}
358373

359-
func execSyscall(command string, args []string, env []string) error {
374+
func doExecSyscall(command string, args []string, env []string) error {
375+
if command == "" {
376+
command = getDefaultShell()
377+
fmt.Fprintf(os.Stderr, "aws-vault: Starting a subshell %s\n", command)
378+
}
379+
360380
log.Printf("Exec command %s %s", command, strings.Join(args, " "))
361381

362382
argv0, err := osexec.LookPath(command)

0 commit comments

Comments
 (0)