Skip to content

Commit

Permalink
Merge pull request #11 from pratishshr/region-flag
Browse files Browse the repository at this point in the history
Add region flag
  • Loading branch information
pratishshr authored Oct 3, 2019
2 parents 8c9302f + f2bff48 commit ef29217
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
10 changes: 8 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: &region,
},
}

app.Commands = []cli.Command{
Expand All @@ -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
},
Expand All @@ -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
},
Expand Down
4 changes: 2 additions & 2 deletions cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
8 changes: 6 additions & 2 deletions internal/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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)
}

0 comments on commit ef29217

Please sign in to comment.