Skip to content

Commit 77684a4

Browse files
authored
feat: Add ListProvisionedScimGroupsForEnterprise inside SCIM service (#3467)
1 parent ce42642 commit 77684a4

File tree

4 files changed

+294
-0
lines changed

4 files changed

+294
-0
lines changed

github/github-accessors.go

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/scim.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ import (
1717
// GitHub API docs: https://docs.github.com/rest/scim
1818
type SCIMService service
1919

20+
// SCIMGroupAttributes represents supported SCIM Group attributes.
21+
//
22+
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/enterprise-admin/scim#list-provisioned-scim-groups-for-an-enterprise
23+
type SCIMGroupAttributes struct {
24+
DisplayName *string `json:"displayName,omitempty"` // The name of the group, suitable for display to end-users. (Optional.)
25+
Members []*SCIMDisplayReference `json:"members,omitempty"` // (Optional.)
26+
Schemas []string `json:"schemas,omitempty"` // (Optional.)
27+
ExternalID *string `json:"externalId,omitempty"` // (Optional.)
28+
// Only populated as a result of calling ListSCIMProvisionedIdentitiesOptions:
29+
ID *string `json:"id,omitempty"`
30+
Meta *SCIMMeta `json:"meta,omitempty"`
31+
}
32+
33+
// SCIMDisplayReference represents a JSON SCIM (System for Cross-domain Identity Management) resource.
34+
type SCIMDisplayReference struct {
35+
Value string `json:"value"` // (Required.)
36+
Ref string `json:"$ref"` // (Required.)
37+
Display *string `json:"display,omitempty"` // (Optional.)
38+
}
39+
2040
// SCIMUserAttributes represents supported SCIM User attributes.
2141
//
2242
// GitHub API docs: https://docs.github.com/rest/scim#supported-scim-user-attributes
@@ -56,6 +76,15 @@ type SCIMMeta struct {
5676
Location *string `json:"location,omitempty"`
5777
}
5878

79+
// SCIMProvisionedGroups represents the result of calling ListSCIMProvisionedGroupsForEnterprise.
80+
type SCIMProvisionedGroups struct {
81+
Schemas []string `json:"schemas,omitempty"`
82+
TotalResults *int `json:"totalResults,omitempty"`
83+
ItemsPerPage *int `json:"itemsPerPage,omitempty"`
84+
StartIndex *int `json:"startIndex,omitempty"`
85+
Resources []*SCIMGroupAttributes `json:"Resources,omitempty"`
86+
}
87+
5988
// SCIMProvisionedIdentities represents the result of calling ListSCIMProvisionedIdentities.
6089
type SCIMProvisionedIdentities struct {
6190
Schemas []string `json:"schemas,omitempty"`
@@ -217,3 +246,25 @@ func (s *SCIMService) DeleteSCIMUserFromOrg(ctx context.Context, org, scimUserID
217246

218247
return s.client.Do(ctx, req, nil)
219248
}
249+
250+
// ListSCIMProvisionedGroupsForEnterprise lists SCIM provisioned groups for an enterprise.
251+
//
252+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#list-provisioned-scim-groups-for-an-enterprise
253+
//
254+
//meta:operation GET /scim/v2/enterprises/{enterprise}/Groups
255+
func (s *SCIMService) ListSCIMProvisionedGroupsForEnterprise(ctx context.Context, enterprise string, opts *ListSCIMProvisionedIdentitiesOptions) (*SCIMProvisionedGroups, *Response, error) {
256+
u := fmt.Sprintf("scim/v2/enterprises/%v/Groups", enterprise)
257+
258+
req, err := s.client.NewRequest("GET", u, nil)
259+
if err != nil {
260+
return nil, nil, err
261+
}
262+
263+
groups := new(SCIMProvisionedGroups)
264+
resp, err := s.client.Do(ctx, req, groups)
265+
if err != nil {
266+
return nil, resp, err
267+
}
268+
269+
return groups, resp, nil
270+
}

github/scim_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,100 @@ func TestSCIMService_ListSCIMProvisionedIdentities(t *testing.T) {
121121
})
122122
}
123123

124+
func TestSCIMService_ListSCIMProvisionedGroups(t *testing.T) {
125+
t.Parallel()
126+
client, mux, _ := setup(t)
127+
128+
mux.HandleFunc("/scim/v2/enterprises/o/Groups", func(w http.ResponseWriter, r *http.Request) {
129+
testMethod(t, r, "GET")
130+
w.WriteHeader(http.StatusOK)
131+
_, _ = w.Write([]byte(`{
132+
"schemas": [
133+
"urn:ietf:params:scim:api:messages:2.0:ListResponse"
134+
],
135+
"totalResults": 1,
136+
"itemsPerPage": 1,
137+
"startIndex": 1,
138+
"Resources": [
139+
{
140+
"schemas": [
141+
"urn:ietf:params:scim:schemas:core:2.0:Group"
142+
],
143+
"id": "123e4567-e89b-12d3-a456-426614174000",
144+
"externalId": "00u1dhhb1fkIGP7RL1d8",
145+
"displayName": "Mona Octocat",
146+
"meta": {
147+
"resourceType": "Group",
148+
"created": "2018-02-13T15:05:24.000-00:00",
149+
"lastModified": "2018-02-13T15:05:24.000-00:00",
150+
"location": "https://api.github.com/scim/v2/enterprises/octo/Groups/123e4567-e89b-12d3-a456-426614174000"
151+
},
152+
"members": [
153+
{
154+
"value": "5fc0c238-1112-11e8-8e45-920c87bdbd75",
155+
"$ref": "https://api.github.com/scim/v2/enterprises/octo/Users/5fc0c238-1112-11e8-8e45-920c87bdbd75",
156+
"display": "Mona Octocat"
157+
}
158+
]
159+
}
160+
]
161+
}`))
162+
})
163+
164+
ctx := context.Background()
165+
opts := &ListSCIMProvisionedIdentitiesOptions{}
166+
groups, _, err := client.SCIM.ListSCIMProvisionedGroupsForEnterprise(ctx, "o", opts)
167+
if err != nil {
168+
t.Errorf("SCIM.ListSCIMProvisionedIdentities returned error: %v", err)
169+
}
170+
171+
date := Timestamp{time.Date(2018, time.February, 13, 15, 5, 24, 0, time.UTC)}
172+
want := SCIMProvisionedGroups{
173+
Schemas: []string{"urn:ietf:params:scim:api:messages:2.0:ListResponse"},
174+
TotalResults: Ptr(1),
175+
ItemsPerPage: Ptr(1),
176+
StartIndex: Ptr(1),
177+
Resources: []*SCIMGroupAttributes{
178+
{
179+
ID: Ptr("123e4567-e89b-12d3-a456-426614174000"),
180+
Meta: &SCIMMeta{
181+
ResourceType: Ptr("Group"),
182+
Created: &date,
183+
LastModified: &date,
184+
Location: Ptr("https://api.github.com/scim/v2/enterprises/octo/Groups/123e4567-e89b-12d3-a456-426614174000"),
185+
},
186+
187+
DisplayName: Ptr("Mona Octocat"),
188+
Schemas: []string{"urn:ietf:params:scim:schemas:core:2.0:Group"},
189+
ExternalID: Ptr("00u1dhhb1fkIGP7RL1d8"),
190+
Members: []*SCIMDisplayReference{
191+
{
192+
Value: "5fc0c238-1112-11e8-8e45-920c87bdbd75",
193+
Ref: "https://api.github.com/scim/v2/enterprises/octo/Users/5fc0c238-1112-11e8-8e45-920c87bdbd75",
194+
Display: Ptr("Mona Octocat"),
195+
},
196+
},
197+
},
198+
},
199+
}
200+
201+
if !cmp.Equal(groups, &want) {
202+
diff := cmp.Diff(groups, want)
203+
t.Errorf("SCIM.ListSCIMProvisionedGroupsForEnterprise returned %+v, want %+v: diff %+v", groups, want, diff)
204+
}
205+
206+
const methodName = "ListSCIMProvisionedGroupsForEnterprise"
207+
testBadOptions(t, methodName, func() (err error) {
208+
_, _, err = client.SCIM.ListSCIMProvisionedGroupsForEnterprise(ctx, "\n", opts)
209+
return err
210+
})
211+
212+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
213+
_, r, err := client.SCIM.ListSCIMProvisionedGroupsForEnterprise(ctx, "o", opts)
214+
return r, err
215+
})
216+
}
217+
124218
func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) {
125219
t.Parallel()
126220
client, mux, _ := setup(t)

0 commit comments

Comments
 (0)