-
Notifications
You must be signed in to change notification settings - Fork 17
/
userpass_auth.go
57 lines (45 loc) · 1.04 KB
/
userpass_auth.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
package vault
func NewUserpassAuth(c *Client, username string, password string, opts ...UserpassAuthOpt) (AuthProvider, error) {
k := &UserpassAuth{
Client: c,
mountPoint: "userpass",
username: username,
password: password,
}
for _, opt := range opts {
err := opt(k)
if err != nil {
return nil, err
}
}
return k, nil
}
type UserpassAuth struct {
Client *Client
mountPoint string
username string
password string
}
type userpassAuthConfig struct {
Password string `json:"password"`
}
func (k UserpassAuth) Auth() (*AuthResponse, error) {
conf := &userpassAuthConfig{
Password: k.password,
}
res := &AuthResponse{}
err := k.Client.Write([]string{"v1", "auth", k.mountPoint, "login", k.username}, conf, res, &RequestOptions{
SkipRenewal: true,
})
if err != nil {
return nil, err
}
return res, nil
}
type UserpassAuthOpt func(k *UserpassAuth) error
func WithUserpassMountPoint(mountPoint string) UserpassAuthOpt {
return func(k *UserpassAuth) error {
k.mountPoint = mountPoint
return nil
}
}