forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
role_assignments.go
41 lines (33 loc) · 994 Bytes
/
role_assignments.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
package gapi
import (
"encoding/json"
"fmt"
"net/http"
)
type RoleAssignments struct {
RoleUID string `json:"role_uid"`
Users []int `json:"users,omitempty"`
Teams []int `json:"teams,omitempty"`
ServiceAccounts []int `json:"service_accounts,omitempty"`
}
func (c *Client) GetRoleAssignments(uid string) (*RoleAssignments, error) {
assignments := &RoleAssignments{}
url := fmt.Sprintf("/api/access-control/roles/%s/assignments", uid)
if err := c.request(http.MethodGet, url, nil, nil, assignments); err != nil {
return nil, err
}
return assignments, nil
}
func (c *Client) UpdateRoleAssignments(ra *RoleAssignments) (*RoleAssignments, error) {
response := &RoleAssignments{}
data, err := json.Marshal(ra)
if err != nil {
return nil, err
}
url := fmt.Sprintf("/api/access-control/roles/%s/assignments", ra.RoleUID)
err = c.request(http.MethodPut, url, nil, data, &response)
if err != nil {
return nil, err
}
return response, nil
}