Skip to content

Commit

Permalink
Output the cli command to get the secret on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
slarwise committed Sep 20, 2024
1 parent 6a89e4c commit 4a12085
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/vault/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (c Client) listDir(mount string, name string) ([]dirEnt, error) {

type Secret struct {
Url string `json:"url"`
Cli string `json:"cli"`
Data struct {
Data map[string]interface{} `json:"data"`
Metadata map[string]interface{} `json:"metadata"`
Expand Down Expand Up @@ -156,6 +157,7 @@ func (c Client) GetSecret(mount, name string) Secret {
panic(fmt.Errorf("Got %s on url %s", response.Status, url))
}
secret.Url = fmt.Sprintf("%s/ui/vault/secrets/%s/show%s", c.Addr, mount, name)
secret.Cli = fmt.Sprintf("vault kv get -mount=%s %s", mount, name)
cachedSecrets[name] = secret
return secret
}
Expand Down
4 changes: 4 additions & 0 deletions internal/vault/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func TestGetSecret(t *testing.T) {
if secret.Url != expectedUrl {
t.Fatalf("Expected url to be %s, got %s", expectedUrl, secret.Url)
}
expectedCli := "vault kv get -mount=secret /bar/baz"
if secret.Cli != expectedCli {
t.Fatalf("Expected cli command to be %s, got %s", expectedCli, secret.Cli)
}
}

func startVault(token, addr string) (*exec.Cmd, error) {
Expand Down

0 comments on commit 4a12085

Please sign in to comment.