Skip to content

Commit

Permalink
Merge pull request #12 from pratishshr/profile-flag
Browse files Browse the repository at this point in the history
Add Profile flag
  • Loading branch information
pratishshr authored Oct 3, 2019
2 parents ef29217 + b77c11f commit bd841d4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
10 changes: 8 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Initialize(info *Info) error {
var secretName string
var env string
var region string
var profile string

app := cli.NewApp()
app.Name = info.Name
Expand Down Expand Up @@ -48,6 +49,11 @@ func Initialize(info *Info) error {
Usage: "AWS Region",
Destination: &region,
},
cli.StringFlag{
Name: "profile, p",
Usage: "Profile",
Destination: &profile,
},
}

app.Commands = []cli.Command{
Expand All @@ -65,7 +71,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, region)
List(secretName, env, region, profile)

return nil
},
Expand All @@ -76,7 +82,7 @@ func Initialize(info *Info) error {
ArgsUsage: "[command]",
Flags: flags,
Action: func(ctx *cli.Context) error {
Run(secretName, ctx.Args().Get(0), env, region)
Run(secretName, ctx.Args().Get(0), env, region, profile)

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, region string) {
for key, value := range secrets.GetSecrets(secretName, env, region) {
func List(secretName string, env string, region string, profile string) {
for key, value := range secrets.GetSecrets(secretName, env, region, profile) {
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, region string) {
func Run(secretName string, command string, env string, region string, profile string) {
if command == "" {
exit.Error("Command to run is not specified. Add command as 'envault run [command]'")
}

shell.Execute(command, secrets.GetSecrets(secretName, env, region))
shell.Execute(command, secrets.GetSecrets(secretName, env, region, profile))
}
2 changes: 1 addition & 1 deletion envault.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func main() {
info := &cli.Info{
Name: "Envault",
Version: "1.1.0",
Version: "1.1.2",
Description: "Envault is a simple CLI tool to run a process with secrets from AWS Secrets Manager.",
AuthorName: "Pratish Shrestha",
AuthorEmail: "pratishshr@gmail.com",
Expand Down
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, region string) map[string]string {
func GetSecrets(secretName string, env string, region string, profile string) map[string]string {
conf := config.GetConfig()

if secretName == "" && env == "" {
Expand All @@ -26,5 +26,9 @@ func GetSecrets(secretName string, env string, region string) map[string]string
region = conf.Region
}

return aws.GetSecrets(conf.Profile, region, secretName)
if profile == "" {
profile = conf.Profile
}

return aws.GetSecrets(profile, region, secretName)
}

0 comments on commit bd841d4

Please sign in to comment.