Skip to content

Commit

Permalink
Merge pull request #55 from finanzcheck/master
Browse files Browse the repository at this point in the history
Implement persistent cmd flag to expand list output with values
  • Loading branch information
dfuentes authored Dec 22, 2017
2 parents e11eb53 + c9f0f14 commit bc7ee45
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ Listing secrets should show the key names for a given service, along with other
useful metadata including when the secret was last modified, who modified it,
and what the current version is.

```bash
$ chamber list -e service
Key Version LastModified User Value
apikey 2 06-09 17:30:56 daniel-fuentes apikeyvalue
other 1 06-09 17:30:34 daniel-fuentes othervalue
```

Listing secrets with expand parameter should show the key names and values for a given service, along with other useful metadata including when the secret was last modified, who modified it,
and what the current version is.

### Historic view

Expand Down
24 changes: 20 additions & 4 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ var listCmd = &cobra.Command{
RunE: list,
}

var (
withValues bool
)

func init() {
listCmd.Flags().BoolVarP(&withValues, "expand", "e", false, "Expand parameter list with values")
RootCmd.AddCommand(listCmd)
}

Expand All @@ -30,20 +35,31 @@ func list(cmd *cobra.Command, args []string) error {
}

secretStore := store.NewSSMStore(numRetries)
secrets, err := secretStore.List(service, false)
secrets, err := secretStore.List(service, withValues)
if err != nil {
return errors.Wrap(err, "Failed to list store contents")
}

w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
fmt.Fprintln(w, "Key\tVersion\tLastModified\tUser")

fmt.Fprint(w, "Key\tVersion\tLastModified\tUser")
if withValues {
fmt.Fprint(w, "\tValue")
}
fmt.Fprintln(w, "")

for _, secret := range secrets {
fmt.Fprintf(w, "%s\t%d\t%s\t%s\n",
fmt.Fprintf(w, "%s\t%d\t%s\t%s",
key(secret.Meta.Key),
secret.Meta.Version,
secret.Meta.Created.Local().Format(ShortTimeFormat),
secret.Meta.CreatedBy)
if withValues {
fmt.Fprintf(w, "\t%s", *secret.Value)
}
fmt.Fprintln(w, "")
}

w.Flush()
return nil
}
Expand All @@ -57,6 +73,6 @@ func key(s string) string {
}

tokens := strings.Split(s, ".")
secretKey := tokens[1]
secretKey := tokens[1]
return secretKey
}

0 comments on commit bc7ee45

Please sign in to comment.