Skip to content

Commit

Permalink
Merge pull request #2 from enderv/#1-secret-output
Browse files Browse the repository at this point in the history
Fixing output, adding ability to skip profile check; adding readme
  • Loading branch information
enderv authored May 4, 2018
2 parents e202a6d + a868fa3 commit c54628b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Go Based AWS SecretManager

Simple command line for fetching secrets from AWS Secrets Manager

#### Command line Arguments
Currently supported
```
-c string
Full path to credentials file (default "~\.aws\credentials")
-k Skip profile check and just use default for use when no cred file and default will work
-p string
Profile to use (default "default")
-s string
Secret To Fetch (default "secret")
-v string
Version of secret To Fetch (default "version")
```
29 changes: 22 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"encoding/json"
"errors"
"flag"
"fmt"
Expand All @@ -22,19 +23,28 @@ func main() {
sourceProfile := flag.String("p", "default", "Profile to use")
secret := flag.String("s", "secret", "Secret To Fetch")
version := flag.String("v", "version", "Version of secret To Fetch")
skipProfile := flag.Bool("k", false, "Skip profile check and just use default for use when no cred file and default will work")
credFile := flag.String("c", filepath.Join(getCredentialPath(), ".aws", "credentials"), "Full path to credentials file")
flag.Parse()
if *secret == "secret" {
fmt.Println("You must specify a secret name to fetch")
return
}
//Get Current Credentials
exists, err := checkProfileExists(credFile, sourceProfile)
if err != nil || !exists {
fmt.Println(err.Error())
return

var sess *session.Session
if *skipProfile {
//Use Default Credentials
sess = session.Must(session.NewSession())
} else {
//Get Specified Credentials
exists, err := checkProfileExists(credFile, sourceProfile)
if err != nil || !exists {
fmt.Println(err.Error())
return
}
sess = CreateSession(sourceProfile)
}
sess := CreateSession(sourceProfile)

getSecret(sess, secret, version)
}

Expand Down Expand Up @@ -130,5 +140,10 @@ func getSecret(sess *session.Session, secretName *string, secretVersion *string)
return
}

fmt.Println(result.SecretString)
// Convert structs to JSON.
data, err := json.Marshal(result)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", data)
}

0 comments on commit c54628b

Please sign in to comment.