Skip to content

Commit 55ef859

Browse files
feat!: Implement Enterprise SCIM - EnterpriseService.ListProvisionedSCIMUsers (#3839)
BREAKING CHANGE: `ListProvisionedSCIMGroupsEnterpriseOptions` optional fields are now pointers.
1 parent 4bdf8fb commit 55ef859

File tree

5 files changed

+682
-10
lines changed

5 files changed

+682
-10
lines changed

github/enterprise_scim.go

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
// This constant represents the standard SCIM core schema for group objects as defined by RFC 7643.
1515
const SCIMSchemasURINamespacesGroups = "urn:ietf:params:scim:schemas:core:2.0:Group"
1616

17+
// SCIMSchemasURINamespacesUser is the SCIM schema URI namespace for user resources.
18+
// This constant represents the standard SCIM core schema for user objects as defined by RFC 7643.
19+
const SCIMSchemasURINamespacesUser = "urn:ietf:params:scim:schemas:core:2.0:User"
20+
1721
// SCIMSchemasURINamespacesListResponse is the SCIM schema URI namespace for list response resources.
1822
// This constant represents the standard SCIM namespace for list responses used in paginated queries, as defined by RFC 7644.
1923
const SCIMSchemasURINamespacesListResponse = "urn:ietf:params:scim:api:messages:2.0:ListResponse"
@@ -61,15 +65,79 @@ type SCIMEnterpriseGroups struct {
6165
type ListProvisionedSCIMGroupsEnterpriseOptions struct {
6266
// If specified, only results that match the specified filter will be returned.
6367
// Possible filters are `externalId`, `id`, and `displayName`. For example, `externalId eq "a123"`.
64-
Filter string `url:"filter,omitempty"`
68+
Filter *string `url:"filter,omitempty"`
6569
// Excludes the specified attribute from being returned in the results.
66-
ExcludedAttributes string `url:"excludedAttributes,omitempty"`
70+
ExcludedAttributes *string `url:"excludedAttributes,omitempty"`
71+
// Used for pagination: the starting index of the first result to return when paginating through values.
72+
// Default: 1.
73+
StartIndex *int `url:"startIndex,omitempty"`
74+
// Used for pagination: the number of results to return per page.
75+
// Default: 30.
76+
Count *int `url:"count,omitempty"`
77+
}
78+
79+
// SCIMEnterpriseUserAttributes represents supported SCIM enterprise user attributes.
80+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#supported-scim-user-attributes
81+
type SCIMEnterpriseUserAttributes struct {
82+
DisplayName string `json:"displayName"` // Human-readable name for a user
83+
Name *SCIMEnterpriseUserName `json:"name,omitempty"` // The user's full name
84+
UserName string `json:"userName"` // The username for the user (GitHub Account after normalized), generated by the SCIM provider. Must be unique per user.
85+
Emails []*SCIMEnterpriseUserEmail `json:"emails"` // List of the user's emails. They all must be unique per user.
86+
Roles []*SCIMEnterpriseUserRole `json:"roles,omitempty"` // List of the user's roles.
87+
ExternalID string `json:"externalId"` // This identifier is generated by a SCIM provider. Must be unique per user.
88+
Active bool `json:"active"` // Indicates whether the identity is active (true) or should be suspended (false).
89+
Schemas []string `json:"schemas"` // The URIs that are used to indicate the namespaces of the SCIM schemas.
90+
// Bellow: Only populated as a result of calling SetSCIMInformationForProvisionedUser:
91+
ID *string `json:"id,omitempty"` // Identifier generated by the GitHub's SCIM endpoint.
92+
Groups []*SCIMEnterpriseDisplayReference `json:"groups,omitempty"` // List of groups who are assigned to the user in SCIM provider
93+
Meta *SCIMEnterpriseMeta `json:"meta,omitempty"` // The metadata associated with the creation/updates to the user.
94+
}
95+
96+
// SCIMEnterpriseUserName represents SCIM enterprise user's name information.
97+
type SCIMEnterpriseUserName struct {
98+
GivenName string `json:"givenName"` // The first name of the user.
99+
FamilyName string `json:"familyName"` // The last name of the user.
100+
Formatted *string `json:"formatted,omitempty"` // The user's full name, including all middle names, titles, and suffixes, formatted for display.
101+
MiddleName *string `json:"middleName,omitempty"` // The middle name(s) of the user.
102+
}
103+
104+
// SCIMEnterpriseUserEmail represents SCIM enterprise user's emails.
105+
type SCIMEnterpriseUserEmail struct {
106+
Value string `json:"value"` // The email address.
107+
Primary bool `json:"primary"` // Whether this email address is the primary address.
108+
Type string `json:"type"` // The type of email address
109+
}
110+
111+
// SCIMEnterpriseUserRole is an enterprise-wide role granted to the user.
112+
type SCIMEnterpriseUserRole struct {
113+
Value string `json:"value"` // The role value representing a user role in GitHub.
114+
Display *string `json:"display,omitempty"`
115+
Type *string `json:"type,omitempty"`
116+
Primary *bool `json:"primary,omitempty"` // Is the role a primary role for the user?
117+
}
118+
119+
// SCIMEnterpriseUsers represents the result of calling ProvisionSCIMEnterpriseUser.
120+
type SCIMEnterpriseUsers struct {
121+
Schemas []string `json:"schemas,omitempty"`
122+
TotalResults *int `json:"totalResults,omitempty"`
123+
ItemsPerPage *int `json:"itemsPerPage,omitempty"`
124+
StartIndex *int `json:"startIndex,omitempty"`
125+
Resources []*SCIMEnterpriseUserAttributes `json:"Resources,omitempty"`
126+
}
127+
128+
// ListProvisionedSCIMUsersEnterpriseOptions represents query parameters for ListSCIMProvisionedUsers.
129+
//
130+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#list-scim-provisioned-identities-for-an-enterprise
131+
type ListProvisionedSCIMUsersEnterpriseOptions struct {
132+
// If specified, only results that match the specified filter will be returned.
133+
// Possible filters are `userName`, `externalId`, `id`, and `displayName`. For example, `externalId eq "a123"`.
134+
Filter *string `url:"filter,omitempty"`
67135
// Used for pagination: the starting index of the first result to return when paginating through values.
68136
// Default: 1.
69-
StartIndex int `url:"startIndex,omitempty"`
137+
StartIndex *int `url:"startIndex,omitempty"`
70138
// Used for pagination: the number of results to return per page.
71139
// Default: 30.
72-
Count int `url:"count,omitempty"`
140+
Count *int `url:"count,omitempty"`
73141
}
74142

75143
// ListProvisionedSCIMGroups lists provisioned SCIM groups in an enterprise.
@@ -88,6 +156,7 @@ func (s *EnterpriseService) ListProvisionedSCIMGroups(ctx context.Context, enter
88156
if err != nil {
89157
return nil, nil, err
90158
}
159+
req.Header.Set("Accept", mediaTypeSCIM)
91160

92161
groups := new(SCIMEnterpriseGroups)
93162
resp, err := s.client.Do(ctx, req, groups)
@@ -97,3 +166,30 @@ func (s *EnterpriseService) ListProvisionedSCIMGroups(ctx context.Context, enter
97166

98167
return groups, resp, nil
99168
}
169+
170+
// ListProvisionedSCIMUsers lists provisioned SCIM enterprise users.
171+
//
172+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#list-scim-provisioned-identities-for-an-enterprise
173+
//
174+
//meta:operation GET /scim/v2/enterprises/{enterprise}/Users
175+
func (s *EnterpriseService) ListProvisionedSCIMUsers(ctx context.Context, enterprise string, opts *ListProvisionedSCIMUsersEnterpriseOptions) (*SCIMEnterpriseUsers, *Response, error) {
176+
u := fmt.Sprintf("scim/v2/enterprises/%v/Users", enterprise)
177+
u, err := addOptions(u, opts)
178+
if err != nil {
179+
return nil, nil, err
180+
}
181+
182+
req, err := s.client.NewRequest("GET", u, nil)
183+
if err != nil {
184+
return nil, nil, err
185+
}
186+
req.Header.Set("Accept", mediaTypeSCIM)
187+
188+
users := new(SCIMEnterpriseUsers)
189+
resp, err := s.client.Do(ctx, req, users)
190+
if err != nil {
191+
return nil, resp, err
192+
}
193+
194+
return users, resp, nil
195+
}

0 commit comments

Comments
 (0)