diff --git a/cli/cli.go b/cli/cli.go index 232f583..cc76fd2 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -19,6 +19,7 @@ type Info struct { func Initialize(info *Info) error { var secretName string var env string + var region string app := cli.NewApp() app.Name = info.Name @@ -42,6 +43,11 @@ func Initialize(info *Info) error { Usage: "Environment to use the secret name from", Destination: &env, }, + cli.StringFlag{ + Name: "region, r", + Usage: "AWS Region", + Destination: ®ion, + }, } app.Commands = []cli.Command{ @@ -59,7 +65,7 @@ func Initialize(info *Info) error { Usage: "List environment variables stored in Secrets Manager", Flags: flags, Action: func(ctx *cli.Context) error { - List(secretName, env) + List(secretName, env, region) return nil }, @@ -70,7 +76,7 @@ func Initialize(info *Info) error { ArgsUsage: "[command]", Flags: flags, Action: func(ctx *cli.Context) error { - Run(secretName, ctx.Args().Get(0), env) + Run(secretName, ctx.Args().Get(0), env, region) return nil }, diff --git a/cli/list.go b/cli/list.go index f3385d4..c254348 100644 --- a/cli/list.go +++ b/cli/list.go @@ -7,8 +7,8 @@ import ( ) // List all environment from Secrets Manager -func List(secretName string, env string) { - for key, value := range secrets.GetSecrets(secretName, env) { +func List(secretName string, env string, region string) { + for key, value := range secrets.GetSecrets(secretName, env, region) { fmt.Println(key + "=" + value) } } diff --git a/cli/run.go b/cli/run.go index e5c6cbe..cb5d7cb 100644 --- a/cli/run.go +++ b/cli/run.go @@ -7,10 +7,10 @@ import ( ) // Run given command with the secrets from given Secret Manager. -func Run(secretName string, command string, env string) { +func Run(secretName string, command string, env string, region string) { if command == "" { exit.Error("Command to run is not specified. Add command as 'envault run [command]'") } - shell.Execute(command, secrets.GetSecrets(secretName, env)) + shell.Execute(command, secrets.GetSecrets(secretName, env, region)) } diff --git a/internal/secrets/secrets.go b/internal/secrets/secrets.go index c39ee6b..486e199 100644 --- a/internal/secrets/secrets.go +++ b/internal/secrets/secrets.go @@ -7,7 +7,7 @@ import ( ) // GetSecrets sets appropriate config and fetches secrets from aws. -func GetSecrets(secretName string, env string) map[string]string { +func GetSecrets(secretName string, env string, region string) map[string]string { conf := config.GetConfig() if secretName == "" && env == "" { @@ -22,5 +22,9 @@ func GetSecrets(secretName string, env string) map[string]string { secretName = conf.Environments[env] } - return aws.GetSecrets(conf.Profile, conf.Region, secretName) + if region == "" { + region = conf.Region + } + + return aws.GetSecrets(conf.Profile, region, secretName) }