Skip to content

Commit e279f70

Browse files
feat: Implement Enterprise SCIM - Update Group & User attributes (#3848)
1 parent b480d82 commit e279f70

File tree

4 files changed

+475
-151
lines changed

4 files changed

+475
-151
lines changed

github/enterprise_scim.go

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ const SCIMSchemasURINamespacesUser = "urn:ietf:params:scim:schemas:core:2.0:User
2222
// This constant represents the standard SCIM namespace for list responses used in paginated queries, as defined by RFC 7644.
2323
const SCIMSchemasURINamespacesListResponse = "urn:ietf:params:scim:api:messages:2.0:ListResponse"
2424

25-
// SCIMEnterpriseGroupAttributes represents supported SCIM Enterprise group attributes.
25+
// SCIMSchemasURINamespacesPatchOp is the SCIM schema URI namespace for patch operations.
26+
// This constant represents the standard SCIM namespace for patch operations as defined by RFC 7644.
27+
const SCIMSchemasURINamespacesPatchOp = "urn:ietf:params:scim:api:messages:2.0:PatchOp"
28+
29+
// SCIMEnterpriseGroupAttributes represents supported SCIM Enterprise group attributes, and represents the result of calling UpdateSCIMGroupAttribute.
2630
//
2731
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#supported-scim-group-attributes
2832
type SCIMEnterpriseGroupAttributes struct {
2933
DisplayName *string `json:"displayName,omitempty"` // Human-readable name for a group.
3034
Members []*SCIMEnterpriseDisplayReference `json:"members,omitempty"` // List of members who are assigned to the group in SCIM provider
3135
ExternalID *string `json:"externalId,omitempty"` // This identifier is generated by a SCIM provider. Must be unique per user.
32-
// Bellow: Only populated as a result of calling SetSCIMInformationForProvisionedGroup:
36+
// Bellow: Only populated as a result of calling UpdateSCIMGroupAttribute:
3337
Schemas []string `json:"schemas,omitempty"` // The URIs that are used to indicate the namespaces of the SCIM schemas.
3438
ID *string `json:"id,omitempty"` // The internally generated id for the group object.
3539
Meta *SCIMEnterpriseMeta `json:"meta,omitempty"` // The metadata associated with the creation/updates to the group.
@@ -76,7 +80,8 @@ type ListProvisionedSCIMGroupsEnterpriseOptions struct {
7680
Count *int `url:"count,omitempty"`
7781
}
7882

79-
// SCIMEnterpriseUserAttributes represents supported SCIM enterprise user attributes.
83+
// SCIMEnterpriseUserAttributes represents supported SCIM enterprise user attributes, and represents the result of calling UpdateSCIMUserAttribute.
84+
//
8085
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#supported-scim-user-attributes
8186
type SCIMEnterpriseUserAttributes struct {
8287
DisplayName string `json:"displayName"` // Human-readable name for a user
@@ -87,7 +92,7 @@ type SCIMEnterpriseUserAttributes struct {
8792
ExternalID string `json:"externalId"` // This identifier is generated by a SCIM provider. Must be unique per user.
8893
Active bool `json:"active"` // Indicates whether the identity is active (true) or should be suspended (false).
8994
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:
95+
// Bellow: Only populated as a result of calling UpdateSCIMUserAttribute:
9196
ID *string `json:"id,omitempty"` // Identifier generated by the GitHub's SCIM endpoint.
9297
Groups []*SCIMEnterpriseDisplayReference `json:"groups,omitempty"` // List of groups who are assigned to the user in SCIM provider
9398
Meta *SCIMEnterpriseMeta `json:"meta,omitempty"` // The metadata associated with the creation/updates to the user.
@@ -116,7 +121,7 @@ type SCIMEnterpriseUserRole struct {
116121
Primary *bool `json:"primary,omitempty"` // Is the role a primary role for the user?
117122
}
118123

119-
// SCIMEnterpriseUsers represents the result of calling ProvisionSCIMEnterpriseUser.
124+
// SCIMEnterpriseUsers represents the result of calling ListProvisionedSCIMUsers.
120125
type SCIMEnterpriseUsers struct {
121126
Schemas []string `json:"schemas,omitempty"`
122127
TotalResults *int `json:"totalResults,omitempty"`
@@ -125,7 +130,7 @@ type SCIMEnterpriseUsers struct {
125130
Resources []*SCIMEnterpriseUserAttributes `json:"Resources,omitempty"`
126131
}
127132

128-
// ListProvisionedSCIMUsersEnterpriseOptions represents query parameters for ListSCIMProvisionedUsers.
133+
// ListProvisionedSCIMUsersEnterpriseOptions represents query parameters for ListProvisionedSCIMUsers.
129134
//
130135
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#list-scim-provisioned-identities-for-an-enterprise
131136
type ListProvisionedSCIMUsersEnterpriseOptions struct {
@@ -140,6 +145,21 @@ type ListProvisionedSCIMUsersEnterpriseOptions struct {
140145
Count *int `url:"count,omitempty"`
141146
}
142147

148+
// SCIMEnterpriseAttribute represents attribute operations for UpdateSCIMGroupAttribute or UpdateSCIMUserAttribute.
149+
//
150+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#update-an-attribute-for-a-scim-enterprise-group
151+
type SCIMEnterpriseAttribute struct {
152+
Schemas []string `json:"schemas"` // The URIs that are used to indicate the namespaces for a SCIM patch operation.
153+
Operations []*SCIMEnterpriseAttributeOperation `json:"Operations"` // Set of operations to be performed.
154+
}
155+
156+
// SCIMEnterpriseAttributeOperation represents an operation for UpdateSCIMGroupAttribute or UpdateSCIMUserAttribute.
157+
type SCIMEnterpriseAttributeOperation struct {
158+
Op string `json:"op"` // Can be one of: `add`, `replace`, `remove`.
159+
Path *string `json:"path,omitempty"` // Path to the attribute being modified (Filters are not supported).
160+
Value *string `json:"value,omitempty"` // New value for the attribute being modified.
161+
}
162+
143163
// ListProvisionedSCIMGroups lists provisioned SCIM groups in an enterprise.
144164
//
145165
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#list-provisioned-scim-groups-for-an-enterprise
@@ -193,3 +213,47 @@ func (s *EnterpriseService) ListProvisionedSCIMUsers(ctx context.Context, enterp
193213

194214
return users, resp, nil
195215
}
216+
217+
// UpdateSCIMGroupAttribute updates a provisioned group’s individual attributes.
218+
//
219+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#update-an-attribute-for-a-scim-enterprise-group
220+
//
221+
//meta:operation PATCH /scim/v2/enterprises/{enterprise}/Groups/{scim_group_id}
222+
func (s *EnterpriseService) UpdateSCIMGroupAttribute(ctx context.Context, enterprise, scimGroupID string, attribute SCIMEnterpriseAttribute) (*SCIMEnterpriseGroupAttributes, *Response, error) {
223+
u := fmt.Sprintf("scim/v2/enterprises/%v/Groups/%v", enterprise, scimGroupID)
224+
req, err := s.client.NewRequest("PATCH", u, attribute)
225+
if err != nil {
226+
return nil, nil, err
227+
}
228+
req.Header.Set("Accept", mediaTypeSCIM)
229+
230+
group := new(SCIMEnterpriseGroupAttributes)
231+
resp, err := s.client.Do(ctx, req, group)
232+
if err != nil {
233+
return nil, resp, err
234+
}
235+
236+
return group, resp, nil
237+
}
238+
239+
// UpdateSCIMUserAttribute updates a provisioned user's individual attributes.
240+
//
241+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/scim#update-an-attribute-for-a-scim-enterprise-user
242+
//
243+
//meta:operation PATCH /scim/v2/enterprises/{enterprise}/Users/{scim_user_id}
244+
func (s *EnterpriseService) UpdateSCIMUserAttribute(ctx context.Context, enterprise, scimUserID string, attribute SCIMEnterpriseAttribute) (*SCIMEnterpriseUserAttributes, *Response, error) {
245+
u := fmt.Sprintf("scim/v2/enterprises/%v/Users/%v", enterprise, scimUserID)
246+
req, err := s.client.NewRequest("PATCH", u, attribute)
247+
if err != nil {
248+
return nil, nil, err
249+
}
250+
req.Header.Set("Accept", mediaTypeSCIM)
251+
252+
user := new(SCIMEnterpriseUserAttributes)
253+
resp, err := s.client.Do(ctx, req, user)
254+
if err != nil {
255+
return nil, resp, err
256+
}
257+
258+
return user, resp, nil
259+
}

0 commit comments

Comments
 (0)