Skip to content

feat: Add ListProvisionedScimGroupsForEnterprise inside SCIM service with test #3467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions github/scim.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ import (
// GitHub API docs: https://docs.github.com/rest/scim
type SCIMService service

// SCIMGroupAttributes represents supported SCIM Group attributes.
//
// GitHub API docs: https://docs.github.com/en/enterprise-cloud@latest/rest/enterprise-admin/scim#list-provisioned-scim-groups-for-an-enterprise
type SCIMGroupAttributes struct {
DisplayName *string `json:"displayName,omitempty"` // The name of the group, suitable for display to end-users. (Optional.)
Members []*SCIMDisplayReference `json:"members,omitempty"` // (Optional.)
Schemas []string `json:"schemas,omitempty"` // (Optional.)
ExternalID *string `json:"externalId,omitempty"` // (Optional.)
// Only populated as a result of calling ListSCIMProvisionedIdentitiesOptions:
ID *string `json:"id,omitempty"`
Meta *SCIMMeta `json:"meta,omitempty"`
}

// SCIMDisplayReference represents a JSON SCIM (System for Cross-domain Identity Management) resource.
type SCIMDisplayReference struct {
Value string `json:"value"` // (Required.)
Ref string `json:"$ref"` // (Required.)
Display *string `json:"display,omitempty"` // (Optional.)
}

// SCIMUserAttributes represents supported SCIM User attributes.
//
// GitHub API docs: https://docs.github.com/rest/scim#supported-scim-user-attributes
Expand Down Expand Up @@ -56,6 +76,15 @@ type SCIMMeta struct {
Location *string `json:"location,omitempty"`
}

// SCIMProvisionedGroups represents the result of calling ListSCIMProvisionedGroupsForEnterprise.
type SCIMProvisionedGroups struct {
Schemas []string `json:"schemas,omitempty"`
TotalResults *int `json:"totalResults,omitempty"`
ItemsPerPage *int `json:"itemsPerPage,omitempty"`
StartIndex *int `json:"startIndex,omitempty"`
Resources []*SCIMGroupAttributes `json:"Resources,omitempty"`
}

// SCIMProvisionedIdentities represents the result of calling ListSCIMProvisionedIdentities.
type SCIMProvisionedIdentities struct {
Schemas []string `json:"schemas,omitempty"`
Expand Down Expand Up @@ -217,3 +246,25 @@ func (s *SCIMService) DeleteSCIMUserFromOrg(ctx context.Context, org, scimUserID

return s.client.Do(ctx, req, nil)
}

// ListSCIMProvisionedGroupsForEnterprise lists SCIM provisioned groups for an enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#list-provisioned-scim-groups-for-an-enterprise
//
//meta:operation GET /scim/v2/enterprises/{enterprise}/Groups
func (s *SCIMService) ListSCIMProvisionedGroupsForEnterprise(ctx context.Context, enterprise string, opts *ListSCIMProvisionedIdentitiesOptions) (*SCIMProvisionedGroups, *Response, error) {
u := fmt.Sprintf("scim/v2/enterprises/%v/Groups", enterprise)

req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

groups := new(SCIMProvisionedGroups)
resp, err := s.client.Do(ctx, req, groups)
if err != nil {
return nil, resp, err
}

return groups, resp, nil
}
94 changes: 94 additions & 0 deletions github/scim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,100 @@ func TestSCIMService_ListSCIMProvisionedIdentities(t *testing.T) {
})
}

func TestSCIMService_ListSCIMProvisionedGroups(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/scim/v2/enterprises/o/Groups", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:ListResponse"
],
"totalResults": 1,
"itemsPerPage": 1,
"startIndex": 1,
"Resources": [
{
"schemas": [
"urn:ietf:params:scim:schemas:core:2.0:Group"
],
"id": "123e4567-e89b-12d3-a456-426614174000",
"externalId": "00u1dhhb1fkIGP7RL1d8",
"displayName": "Mona Octocat",
"meta": {
"resourceType": "Group",
"created": "2018-02-13T15:05:24.000-00:00",
"lastModified": "2018-02-13T15:05:24.000-00:00",
"location": "https://api.github.com/scim/v2/enterprises/octo/Groups/123e4567-e89b-12d3-a456-426614174000"
},
"members": [
{
"value": "5fc0c238-1112-11e8-8e45-920c87bdbd75",
"$ref": "https://api.github.com/scim/v2/enterprises/octo/Users/5fc0c238-1112-11e8-8e45-920c87bdbd75",
"display": "Mona Octocat"
}
]
}
]
}`))
})

ctx := context.Background()
opts := &ListSCIMProvisionedIdentitiesOptions{}
groups, _, err := client.SCIM.ListSCIMProvisionedGroupsForEnterprise(ctx, "o", opts)
if err != nil {
t.Errorf("SCIM.ListSCIMProvisionedIdentities returned error: %v", err)
}

date := Timestamp{time.Date(2018, time.February, 13, 15, 5, 24, 0, time.UTC)}
want := SCIMProvisionedGroups{
Schemas: []string{"urn:ietf:params:scim:api:messages:2.0:ListResponse"},
TotalResults: Ptr(1),
ItemsPerPage: Ptr(1),
StartIndex: Ptr(1),
Resources: []*SCIMGroupAttributes{
{
ID: Ptr("123e4567-e89b-12d3-a456-426614174000"),
Meta: &SCIMMeta{
ResourceType: Ptr("Group"),
Created: &date,
LastModified: &date,
Location: Ptr("https://api.github.com/scim/v2/enterprises/octo/Groups/123e4567-e89b-12d3-a456-426614174000"),
},

DisplayName: Ptr("Mona Octocat"),
Schemas: []string{"urn:ietf:params:scim:schemas:core:2.0:Group"},
ExternalID: Ptr("00u1dhhb1fkIGP7RL1d8"),
Members: []*SCIMDisplayReference{
{
Value: "5fc0c238-1112-11e8-8e45-920c87bdbd75",
Ref: "https://api.github.com/scim/v2/enterprises/octo/Users/5fc0c238-1112-11e8-8e45-920c87bdbd75",
Display: Ptr("Mona Octocat"),
},
},
},
},
}

if !cmp.Equal(groups, &want) {
diff := cmp.Diff(groups, want)
t.Errorf("SCIM.ListSCIMProvisionedGroupsForEnterprise returned %+v, want %+v: diff %+v", groups, want, diff)
}

const methodName = "ListSCIMProvisionedGroupsForEnterprise"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.SCIM.ListSCIMProvisionedGroupsForEnterprise(ctx, "\n", opts)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
_, r, err := client.SCIM.ListSCIMProvisionedGroupsForEnterprise(ctx, "o", opts)
return r, err
})
}

func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
Expand Down
Loading