-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaultx.go
105 lines (86 loc) · 2.31 KB
/
vaultx.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package vaultx
import (
"net/http"
"strings"
"github.com/hashicorp/go-cleanhttp"
"github.com/jaredpetersen/vaultx/api"
"github.com/jaredpetersen/vaultx/auth"
"github.com/jaredpetersen/vaultx/db"
"github.com/jaredpetersen/vaultx/kv"
"github.com/jaredpetersen/vaultx/transit"
)
// Client is a resource for interacting with Vault.
type Client struct {
// Config configures how the Vault client will interact with Vault.
Config *Config
http *http.Client
api *api.Client
auth *auth.Client
kv *kv.Client
transit *transit.Client
db *db.Client
}
// API is a direct client to the Vault HTTP engine, enabling manual execution against Vault.
func (c *Client) API() *api.Client {
return c.api
}
// Auth is a gateway into Vault authentication.
//
// See https://www.vaultproject.io/api-docs/auth for more information.
func (c *Client) Auth() *auth.Client {
return c.auth
}
// KV is a gateway into the key-value secrets engine.
//
// For more information, see https://www.vaultproject.io/docs/secrets/kv.
func (c *Client) KV() *kv.Client {
return c.kv
}
// Transit is a gateway into the transit secrets engine.
//
// For more information, see https://www.vaultproject.io/docs/secrets/transit.
func (c *Client) Transit() *transit.Client {
return c.transit
}
// DB is a gateway into the database secrets engine.
//
// For more information, see https://www.vaultproject.io/docs/secrets/databases.
func (c *Client) DB() *db.Client {
return c.db
}
// New creates a new Vault client.
func New(config Config) *Client {
// Remove trailing slash if present, just for predictability with building urls
config.URL = strings.TrimSuffix(config.URL, "/")
httpClient := cleanhttp.DefaultClient()
httpClient.Timeout = config.HTTP.Timeout
apiClient := &api.Client{
HTTP: httpClient,
URL: config.URL,
}
authClient := &auth.Client{
API: apiClient,
AuthMethod: config.Auth.Method,
}
kvClient := &kv.Client{
API: apiClient,
TokenManager: authClient,
}
transitClient := &transit.Client{
API: apiClient,
TokenManager: authClient,
}
dbClient := &db.Client{
API: apiClient,
TokenManager: authClient,
}
return &Client{
Config: &config,
http: httpClient,
api: apiClient,
auth: authClient,
kv: kvClient,
transit: transitClient,
db: dbClient,
}
}