forked from grafana/grafana-api-golang-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard_permissions.go
47 lines (40 loc) · 1.37 KB
/
dashboard_permissions.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
package gapi
import (
"bytes"
"encoding/json"
"fmt"
)
// DashboardPermission has information such as a dashboard, user, team, role and permission.
type DashboardPermission struct {
DashboardID int64 `json:"dashboardId"`
DashboardUID string `json:"uid"`
UserID int64 `json:"userId"`
TeamID int64 `json:"teamId"`
Role string `json:"role"`
IsFolder bool `json:"isFolder"`
Inherited bool `json:"inherited"`
// Permission levels are
// 1 = View
// 2 = Edit
// 4 = Admin
Permission int64 `json:"permission"`
PermissionName string `json:"permissionName"`
}
// DashboardPermissions fetches and returns the permissions for the dashboard whose ID it's passed.
func (c *Client) DashboardPermissions(id int64) ([]*DashboardPermission, error) {
permissions := make([]*DashboardPermission, 0)
err := c.request("GET", fmt.Sprintf("/api/dashboards/id/%d/permissions", id), nil, nil, &permissions)
if err != nil {
return permissions, err
}
return permissions, nil
}
// UpdateDashboardPermissions remove existing permissions if items are not included in the request.
func (c *Client) UpdateDashboardPermissions(id int64, items *PermissionItems) error {
path := fmt.Sprintf("/api/dashboards/id/%d/permissions", id)
data, err := json.Marshal(items)
if err != nil {
return err
}
return c.request("POST", path, nil, bytes.NewBuffer(data), nil)
}