-
Notifications
You must be signed in to change notification settings - Fork 18
/
rbac.go
90 lines (73 loc) · 2.46 KB
/
rbac.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
package runscope
import "fmt"
type Role struct {
Name string `json:"name"`
Permissions []string `json:"permissions"`
UUID string `json:"uuid"`
}
// ListRoles list all the roles. See https://api.blazemeter.com/api-monitoring/#list-roles
func (client *Client) ListRoles(teamID string) ([]*Role, error) {
resource, error := client.readResource("roles", teamID,
fmt.Sprintf("/teams/%s/roles", teamID))
if error != nil {
return nil, error
}
roles, error := getRolesFromResponse(resource.Data)
if error != nil {
return nil, error
}
return roles, nil
}
// CreateRole creates a new role with specified permissions. See https://api.blazemeter.com/api-monitoring/#create-role
func (client *Client) CreateRole(role *Role, teamID string) (*Role, error) {
newRole, err := client.createResource(role, "role", role.Name,
fmt.Sprintf("/teams/%s/roles", teamID))
if err != nil {
return nil, err
}
roleInfo, err := getRoleFromResponse(newRole.Data)
if err != nil {
return nil, err
}
return roleInfo, nil
}
// DeleteRole delete runscope role. See https://api.blazemeter.com/api-monitoring/#delete-a-role
func (client *Client) DeleteRole(role *Role, teamID string) error {
return client.deleteResource("role", role.Name, fmt.Sprintf("/teams/%s/roles/%s", teamID, role.UUID))
}
// ReadRole creates a new role with specified permissions. See https://api.blazemeter.com/api-monitoring/#role-details
func (client *Client) ReadRole(role *Role, teamID string) (*Role, error) {
resource, err := client.readResource("role", role.Name,
fmt.Sprintf("/teams/%s/roles/%s", teamID, role.UUID))
if err != nil {
return nil, err
}
readRole, err := getRoleFromResponse(resource.Data)
if err != nil {
return nil, err
}
return readRole, nil
}
// UpdateRole update a runscope role. See https://api.blazemeter.com/api-monitoring/#modify-role
func (client *Client) UpdateRole(role *Role, teamID string) (*Role, error) {
resource, error := client.updateResource(role, "role", role.UUID,
fmt.Sprintf("/teams/%s/roles/%s", teamID, role.UUID))
if error != nil {
return nil, error
}
readRole, error := getRoleFromResponse(resource.Data)
if error != nil {
return nil, error
}
return readRole, nil
}
func getRolesFromResponse(response interface{}) ([]*Role, error) {
var roles []*Role
err := decode(&roles, response)
return roles, err
}
func getRoleFromResponse(response interface{}) (*Role, error) {
role := new(Role)
err := decode(role, response)
return role, err
}