forked from nscuro/dtrack-client
-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
oidc.go
124 lines (100 loc) · 2.91 KB
/
oidc.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package dtrack
import (
"context"
"fmt"
"net/http"
"strconv"
"github.com/google/uuid"
)
type OIDCService struct {
client *Client
}
type OIDCGroup struct {
Name string `json:"name,omitempty"`
UUID uuid.UUID `json:"uuid,omitempty"`
}
type OIDCMappingRequest struct {
Team uuid.UUID `json:"team"`
Group uuid.UUID `json:"group"`
}
type OIDCMapping struct {
Group OIDCGroup `json:"group"`
UUID uuid.UUID `json:"uuid"`
}
func (s OIDCService) Available(ctx context.Context) (available bool, err error) {
req, err := s.client.newRequest(ctx, http.MethodGet, "/api/v1/oidc/available", withAcceptContentType("text/plain"))
if err != nil {
return
}
var value string
_, err = s.client.doRequest(req, &value)
if err != nil {
return
}
available, err = strconv.ParseBool(value)
return
}
func (s OIDCService) GetAllGroups(ctx context.Context, po PageOptions) (p Page[OIDCGroup], err error) {
req, err := s.client.newRequest(ctx, http.MethodGet, "/api/v1/oidc/group", withPageOptions(po))
if err != nil {
return
}
res, err := s.client.doRequest(req, &p.Items)
if err != nil {
return
}
p.TotalCount = res.TotalCount
return
}
func (s OIDCService) CreateGroup(ctx context.Context, name string) (g OIDCGroup, err error) {
req, err := s.client.newRequest(ctx, http.MethodPut, "/api/v1/oidc/group", withBody(OIDCGroup{Name: name}))
if err != nil {
return
}
_, err = s.client.doRequest(req, &g)
return
}
func (s OIDCService) UpdateGroup(ctx context.Context, group OIDCGroup) (g OIDCGroup, err error) {
req, err := s.client.newRequest(ctx, http.MethodPost, "/api/v1/oidc/group", withBody(group))
if err != nil {
return
}
_, err = s.client.doRequest(req, &g)
return
}
func (s OIDCService) DeleteGroup(ctx context.Context, groupUUID uuid.UUID) (err error) {
req, err := s.client.newRequest(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/oidc/group/%s", groupUUID.String()))
if err != nil {
return
}
_, err = s.client.doRequest(req, nil)
return
}
func (s OIDCService) GetAllTeamsOf(ctx context.Context, group OIDCGroup, po PageOptions) (p Page[Team], err error) {
req, err := s.client.newRequest(ctx, http.MethodGet, fmt.Sprintf("/api/v1/oidc/group/%s/team", group.UUID.String()), withPageOptions(po))
if err != nil {
return
}
res, err := s.client.doRequest(req, &p.Items)
if err != nil {
return
}
p.TotalCount = res.TotalCount
return
}
func (s OIDCService) AddTeamMapping(ctx context.Context, mapping OIDCMappingRequest) (m OIDCMapping, err error) {
req, err := s.client.newRequest(ctx, http.MethodPut, "/api/v1/oidc/mapping", withBody(mapping))
if err != nil {
return
}
_, err = s.client.doRequest(req, &m)
return
}
func (s OIDCService) RemoveTeamMapping(ctx context.Context, mappingID uuid.UUID) (err error) {
req, err := s.client.newRequest(ctx, http.MethodDelete, fmt.Sprintf("/api/v1/oidc/mapping/%s", mappingID.String()))
if err != nil {
return
}
_, err = s.client.doRequest(req, nil)
return
}