Skip to content

Commit

Permalink
feat: support Vault auth method
Browse files Browse the repository at this point in the history
  • Loading branch information
missedone committed Sep 3, 2023
1 parent 01f3d26 commit 10c1385
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion providers/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package vault

import (
"context"
"errors"
"net/http"
"time"
Expand All @@ -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

Expand Down Expand Up @@ -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}
}
Expand Down

0 comments on commit 10c1385

Please sign in to comment.