forked from DependencyTrack/client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permission.go
52 lines (42 loc) · 1.26 KB
/
permission.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
package dtrack
import (
"context"
"fmt"
"net/http"
"github.com/google/uuid"
)
type PermissionService struct {
client *Client
}
type Permission struct {
Name string `json:"name"`
Description string `json:"description"`
}
func (ps PermissionService) GetAll(ctx context.Context, po PageOptions) (p Page[Permission], err error) {
req, err := ps.client.newRequest(ctx, http.MethodGet, "/api/v1/permission", withPageOptions(po))
if err != nil {
return
}
res, err := ps.client.doRequest(req, &p.Items)
if err != nil {
return
}
p.TotalCount = res.TotalCount
return
}
func (ps PermissionService) AddPermissionToTeam(ctx context.Context, permission Permission, team uuid.UUID) (t Team, err error) {
req, err := ps.client.newRequest(ctx, http.MethodPost, fmt.Sprintf("/api/v1/permission/%s/team/%s", permission.Name, team.String()))
if err != nil {
return
}
_, err = ps.client.doRequest(req, &t)
return
}
func (ps PermissionService) RemovePermissionFromTeam(ctx context.Context, permission Permission, team uuid.UUID) (t Team, err error) {
req, err := ps.client.newRequest(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/permission/%s/team/%s", permission.Name, team.String()))
if err != nil {
return
}
_, err = ps.client.doRequest(req, &t)
return
}