Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 557e30f

Browse files
IevaVasiljevaJguer
andauthored
RBAC: endpoints to support reading and setting role assignments (#110)
* API client for reading and setting role assignments * clean up * remove the logic dealing with global assignments * Update role_assignments.go Co-authored-by: Jo <[email protected]> Co-authored-by: Jo <[email protected]>
1 parent daa5f78 commit 557e30f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

role_assignments.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package gapi
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"fmt"
7+
"net/http"
8+
)
9+
10+
type RoleAssignments struct {
11+
RoleUID string `json:"role_uid"`
12+
Users []int `json:"users,omitempty"`
13+
Teams []int `json:"teams,omitempty"`
14+
ServiceAccounts []int `json:"service_accounts,omitempty"`
15+
}
16+
17+
func (c *Client) GetRoleAssignments(uid string) (*RoleAssignments, error) {
18+
assignments := &RoleAssignments{}
19+
url := fmt.Sprintf("/api/access-control/roles/%s/assignments", uid)
20+
if err := c.request(http.MethodGet, url, nil, nil, assignments); err != nil {
21+
return nil, err
22+
}
23+
24+
return assignments, nil
25+
}
26+
27+
func (c *Client) UpdateRoleAssignments(ra *RoleAssignments) (*RoleAssignments, error) {
28+
response := &RoleAssignments{}
29+
30+
data, err := json.Marshal(ra)
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
url := fmt.Sprintf("/api/access-control/roles/%s/assignments", ra.RoleUID)
36+
err = c.request(http.MethodPut, url, nil, bytes.NewBuffer(data), &response)
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
return response, nil
42+
}

0 commit comments

Comments
 (0)