-
Notifications
You must be signed in to change notification settings - Fork 0
/
vault.go
40 lines (33 loc) · 999 Bytes
/
vault.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"context"
"fmt"
vault "github.com/hashicorp/vault/api"
"github.com/yashvardhan-kukreja/vaultie-talkie/internal/target"
)
type VaultSettings struct {
Host string
Port int64
PathToWatch string
AccessToken string
}
func (v VaultSettings) InitClient() (*vault.Client, error) {
config := vault.DefaultConfig()
config.Address = fmt.Sprintf("http://%s:%d", v.Host, v.Port)
client, err := vault.NewClient(config)
if err != nil {
return nil, fmt.Errorf("error occurred while getting the new client from vault: %w", err)
}
client.SetToken(v.AccessToken)
return client, nil
}
func renderKeyStore(client *vault.Client, path string) (target.KeyStore, error) {
secret, err := client.KVv2("secret").Get(context.Background(), path)
if err != nil {
return nil, fmt.Errorf("error occurred while listing the secret contents at the path '%s': %w", path, err)
}
if secret == nil || secret.Data == nil {
return nil, nil
}
return target.KeyStore(secret.Data), nil
}