1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "encoding/json"
11 "fmt"
12 )
13
14
15
16
17
18 type SCIMService service
19
20
21
22
23 type SCIMUserAttributes struct {
24 UserName string `json:"userName"`
25 Name SCIMUserName `json:"name"`
26 DisplayName *string `json:"displayName,omitempty"`
27 Emails []*SCIMUserEmail `json:"emails"`
28 Schemas []string `json:"schemas,omitempty"`
29 ExternalID *string `json:"externalId,omitempty"`
30 Groups []string `json:"groups,omitempty"`
31 Active *bool `json:"active,omitempty"`
32
33 ID *string `json:"id,omitempty"`
34 Meta *SCIMMeta `json:"meta,omitempty"`
35 }
36
37
38 type SCIMUserName struct {
39 GivenName string `json:"givenName"`
40 FamilyName string `json:"familyName"`
41 Formatted *string `json:"formatted,omitempty"`
42 }
43
44
45 type SCIMUserEmail struct {
46 Value string `json:"value"`
47 Primary *bool `json:"primary,omitempty"`
48 Type *string `json:"type,omitempty"`
49 }
50
51
52 type SCIMMeta struct {
53 ResourceType *string `json:"resourceType,omitempty"`
54 Created *Timestamp `json:"created,omitempty"`
55 LastModified *Timestamp `json:"lastModified,omitempty"`
56 Location *string `json:"location,omitempty"`
57 }
58
59
60 type SCIMProvisionedIdentities struct {
61 Schemas []string `json:"schemas,omitempty"`
62 TotalResults *int `json:"totalResults,omitempty"`
63 ItemsPerPage *int `json:"itemsPerPage,omitempty"`
64 StartIndex *int `json:"startIndex,omitempty"`
65 Resources []*SCIMUserAttributes `json:"Resources,omitempty"`
66 }
67
68
69
70
71 type ListSCIMProvisionedIdentitiesOptions struct {
72 StartIndex *int `url:"startIndex,omitempty"`
73 Count *int `url:"count,omitempty"`
74
75
76
77
78
79 Filter *string `url:"filter,omitempty"`
80 }
81
82
83
84
85 func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org string, opts *ListSCIMProvisionedIdentitiesOptions) (*SCIMProvisionedIdentities, *Response, error) {
86 u := fmt.Sprintf("scim/v2/organizations/%v/Users", org)
87 u, err := addOptions(u, opts)
88 if err != nil {
89 return nil, nil, err
90 }
91
92 req, err := s.client.NewRequest("GET", u, nil)
93 if err != nil {
94 return nil, nil, err
95 }
96
97 identities := new(SCIMProvisionedIdentities)
98 resp, err := s.client.Do(ctx, req, identities)
99 if err != nil {
100 return nil, resp, err
101 }
102
103 return identities, resp, nil
104 }
105
106
107
108
109 func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, opts *SCIMUserAttributes) (*Response, error) {
110 u := fmt.Sprintf("scim/v2/organizations/%v/Users", org)
111 u, err := addOptions(u, opts)
112 if err != nil {
113 return nil, err
114 }
115
116 req, err := s.client.NewRequest("POST", u, nil)
117 if err != nil {
118 return nil, err
119 }
120
121 return s.client.Do(ctx, req, nil)
122 }
123
124
125
126
127 func (s *SCIMService) GetSCIMProvisioningInfoForUser(ctx context.Context, org, scimUserID string) (*SCIMUserAttributes, *Response, error) {
128 u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
129 req, err := s.client.NewRequest("GET", u, nil)
130 if err != nil {
131 return nil, nil, err
132 }
133
134 user := new(SCIMUserAttributes)
135 resp, err := s.client.Do(ctx, req, &user)
136 if err != nil {
137 return nil, resp, err
138 }
139
140 return user, resp, nil
141 }
142
143
144
145
146 func (s *SCIMService) UpdateProvisionedOrgMembership(ctx context.Context, org, scimUserID string, opts *SCIMUserAttributes) (*Response, error) {
147 u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
148 u, err := addOptions(u, opts)
149 if err != nil {
150 return nil, err
151 }
152
153 req, err := s.client.NewRequest("PUT", u, nil)
154 if err != nil {
155 return nil, err
156 }
157
158 return s.client.Do(ctx, req, nil)
159 }
160
161
162
163
164 type UpdateAttributeForSCIMUserOptions struct {
165 Schemas []string `json:"schemas,omitempty"`
166 Operations UpdateAttributeForSCIMUserOperations `json:"operations"`
167 }
168
169
170 type UpdateAttributeForSCIMUserOperations struct {
171 Op string `json:"op"`
172 Path *string `json:"path,omitempty"`
173 Value json.RawMessage `json:"value,omitempty"`
174 }
175
176
177
178
179 func (s *SCIMService) UpdateAttributeForSCIMUser(ctx context.Context, org, scimUserID string, opts *UpdateAttributeForSCIMUserOptions) (*Response, error) {
180 u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
181 u, err := addOptions(u, opts)
182 if err != nil {
183 return nil, err
184 }
185
186 req, err := s.client.NewRequest("PATCH", u, nil)
187 if err != nil {
188 return nil, err
189 }
190
191 return s.client.Do(ctx, req, nil)
192 }
193
194
195
196
197 func (s *SCIMService) DeleteSCIMUserFromOrg(ctx context.Context, org, scimUserID string) (*Response, error) {
198 u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
199 req, err := s.client.NewRequest("DELETE", u, nil)
200 if err != nil {
201 return nil, err
202 }
203
204 return s.client.Do(ctx, req, nil)
205 }
206
View as plain text