forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
team.go
92 lines (74 loc) · 2.13 KB
/
team.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
91
92
package dtrack
import (
"context"
"fmt"
"net/http"
"github.com/google/uuid"
)
type Team struct {
UUID uuid.UUID `json:"uuid,omitempty"`
Name string `json:"name,omitempty"`
APIKeys []APIKey `json:"apiKeys,omitempty"`
Permissions []Permission `json:"permissions,omitempty"`
MappedOIDCGroups []OIDCMapping `json:"mappedOidcGroups,omitempty"`
}
type APIKey struct {
Key string `json:"key"`
}
type TeamService struct {
client *Client
}
func (ts TeamService) Get(ctx context.Context, teamUUID uuid.UUID) (t Team, err error) {
req, err := ts.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/team/%s", teamUUID))
if err != nil {
return
}
_, err = ts.client.doRequest(req, &t)
return
}
func (ts TeamService) GetAll(ctx context.Context, po PageOptions) (p Page[Team], err error) {
req, err := ts.client.newRequest(ctx, http.MethodGet, "/api/v1/team", withPageOptions(po))
if err != nil {
return
}
res, err := ts.client.doRequest(req, &p.Items)
if err != nil {
return
}
p.TotalCount = res.TotalCount
return
}
func (ts TeamService) GenerateAPIKey(ctx context.Context, teamUUID uuid.UUID) (key string, err error) {
req, err := ts.client.newRequest(ctx, http.MethodPut, fmt.Sprintf("/api/v1/team/%s/key", teamUUID))
if err != nil {
return
}
var apiKey APIKey
_, err = ts.client.doRequest(req, &apiKey)
key = apiKey.Key
return
}
func (ts TeamService) Create(ctx context.Context, team Team) (t Team, err error) {
req, err := ts.client.newRequest(ctx, http.MethodPut, "/api/v1/team", withBody(team))
if err != nil {
return
}
_, err = ts.client.doRequest(req, &t)
return
}
func (ts TeamService) Update(ctx context.Context, team Team) (t Team, err error) {
req, err := ts.client.newRequest(ctx, http.MethodPost, "/api/v1/team", withBody(team))
if err != nil {
return
}
_, err = ts.client.doRequest(req, &t)
return
}
func (ts TeamService) Delete(ctx context.Context, team Team) (err error) {
req, err := ts.client.newRequest(ctx, http.MethodDelete, "/api/v1/team", withBody(team))
if err != nil {
return
}
_, err = ts.client.doRequest(req, nil)
return
}