From 4a12085d9a6a8c8992d2e529ef9331d5b4e234bb Mon Sep 17 00:00:00 2001 From: Arvid Bjurklint Date: Fri, 20 Sep 2024 17:09:42 +0200 Subject: [PATCH] Output the cli command to get the secret on exit --- internal/vault/client.go | 2 ++ internal/vault/client_test.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/internal/vault/client.go b/internal/vault/client.go index bc28c5e..267b0e3 100644 --- a/internal/vault/client.go +++ b/internal/vault/client.go @@ -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"` @@ -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 } diff --git a/internal/vault/client_test.go b/internal/vault/client_test.go index 0fee3cb..978018c 100644 --- a/internal/vault/client_test.go +++ b/internal/vault/client_test.go @@ -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) {