forked from Caiyeon/goldfish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
approle.go
54 lines (47 loc) · 1.07 KB
/
approle.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
package vault
import (
"encoding/json"
"errors"
)
type Role struct {
Roleid string
Token_TTL int
Token_max_TTL int
Secret_id_TTL int
Secret_id_num_uses int
Policies []string
Period int
Bind_secret_id bool
Bound_cidr_list string
}
func (auth AuthInfo) ListApproleRoles() ([]Role, error) {
client, err := auth.Client()
if err != nil {
return nil, err
}
logical := client.Logical()
// get a list of roles
resp, err := logical.List("auth/approle/role")
if err != nil {
return nil, err
}
if resp == nil || resp.Data == nil {
return []Role{}, nil
}
rolenames, ok := resp.Data["keys"].([]interface{})
if !ok {
return nil, errors.New("Failed to convert response")
}
// fetch each role's details
roles := make([]Role, len(rolenames))
for i, role := range rolenames {
roles[i].Roleid = role.(string)
resp, err := logical.Read("auth/approle/role/" + roles[i].Roleid)
if err == nil {
if b, err := json.Marshal(resp.Data); err == nil {
json.Unmarshal(b, &roles[i])
}
}
}
return roles, nil
}