From fd02e90fd5b227145d569a55db62a8ecd7a4293d Mon Sep 17 00:00:00 2001 From: Nick Tan Date: Tue, 12 Sep 2023 09:16:48 -0700 Subject: [PATCH] feat: support Vault auth method (#229) --- providers/vault/vault.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/providers/vault/vault.go b/providers/vault/vault.go index 44dcbe7e..95f6f2f5 100644 --- a/providers/vault/vault.go +++ b/providers/vault/vault.go @@ -3,6 +3,7 @@ package vault import ( + "context" "errors" "net/http" "time" @@ -16,6 +17,9 @@ type Config struct { // Vault server address Address string + // AuthMethod the Vault auth method https://developer.hashicorp.com/vault/docs/auth + AuthMethod api.AuthMethod + // Vault static token Token string @@ -55,7 +59,13 @@ func Provider(cfg Config) *Vault { if err != nil { return nil } - client.SetToken(cfg.Token) + if cfg.AuthMethod != nil { + if _, err := client.Auth().Login(context.Background(), cfg.AuthMethod); err != nil { + return nil + } + } else { + client.SetToken(cfg.Token) + } return &Vault{client: client, cfg: cfg} }