Skip to content

Commit

Permalink
Merge pull request #42 from Versent/add_option_to_output_secret_witho…
Browse files Browse the repository at this point in the history
…ut_newline

Added option to print secret with no newline fixes #41.
  • Loading branch information
wolfeidau authored Aug 8, 2016
2 parents e28b5c9 + fb34fbc commit 1dac6fb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/unicreds/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ var (
cmdSetupRead = cmdSetup.Flag("read", "Dynamo read capacity.").Default("4").Int64()
cmdSetupWrite = cmdSetup.Flag("write", "Dynamo write capacity.").Default("4").Int64()

cmdGet = app.Command("get", "Get a credential from the store.")
cmdGetName = cmdGet.Arg("credential", "The name of the credential to get.").Required().String()
cmdGet = app.Command("get", "Get a credential from the store.")
cmdGetName = cmdGet.Arg("credential", "The name of the credential to get.").Required().String()
cmdGetNoLine = cmdGet.Flag("noline", "Leave off the newline when emitting secret").Short('n').Bool()

cmdGetAll = app.Command("getall", "Get latest credentials from the store.")
cmdGetAllVersions = cmdGetAll.Flag("all", "List all versions").Bool()
Expand Down Expand Up @@ -93,7 +94,7 @@ func main() {
log.WithFields(log.Fields{"name": *cmdGetName, "secret": cred.Secret, "status": "success"}).Info(cred.Secret)
} else {
// Or just print, out of backwards compatibility
fmt.Println(cred.Secret)
printSecret(cred.Secret, *cmdGetNoLine)
}

case cmdPut.FullCommand():
Expand Down Expand Up @@ -179,6 +180,15 @@ func printFatalError(err error) {
os.Exit(1)
}

func printSecret(secret string, noline bool) {
log.WithField("noline", noline).Debug("print secret")
if noline {
fmt.Printf(secret)
} else {
fmt.Println(secret)
}
}

func printEncryptionContext(encContext *unicreds.EncryptionContextValue) {
if encContext == nil || len(*encContext) == 0 {
return
Expand Down

0 comments on commit 1dac6fb

Please sign in to comment.