Skip to content

Commit 23b7119

Browse files
authored
feat: Support roles field in SCIM (#3728)
1 parent fdb91ff commit 23b7119

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

github/github-accessors.go

Lines changed: 24 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: 33 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: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ type SCIMDisplayReference struct {
3939

4040
// SCIMUserAttributes represents supported SCIM User attributes.
4141
//
42-
// GitHub API docs: https://docs.github.com/rest/scim#supported-scim-user-attributes
42+
// GitHub Enterprise Cloud API docs: https://docs.github.com/rest/scim#supported-scim-user-attributes
43+
// GitHub Enterprise Server API docs: https://docs.github.com/en/enterprise-server@latest/rest/enterprise-admin/scim?apiVersion=2022-11-28#supported-scim-user-attributes
4344
type SCIMUserAttributes struct {
4445
UserName string `json:"userName"` // Configured by the admin. Could be an email, login, or username. (Required.)
4546
Name SCIMUserName `json:"name"` // (Required.)
@@ -48,6 +49,7 @@ type SCIMUserAttributes struct {
4849
Schemas []string `json:"schemas,omitempty"` // (Optional.)
4950
ExternalID *string `json:"externalId,omitempty"` // (Optional.)
5051
Groups []string `json:"groups,omitempty"` // (Optional.)
52+
Roles []*SCIMUserRole `json:"roles,omitempty"` // (Optional, GHES only.)
5153
Active *bool `json:"active,omitempty"` // (Optional.)
5254
// Only populated as a result of calling ListSCIMProvisionedIdentitiesOptions or GetSCIMProvisioningInfoForUser:
5355
ID *string `json:"id,omitempty"`
@@ -68,6 +70,18 @@ type SCIMUserEmail struct {
6870
Type *string `json:"type,omitempty"` // (Optional.)
6971
}
7072

73+
// SCIMUserRole is an enterprise-wide role granted to the user. This is only
74+
// supported in GitHub Enterprise Server, and not GitHub Enterprise Cloud.
75+
// See the docs for allowed role names.
76+
//
77+
// https://docs.github.com/en/enterprise-server@latest/rest/enterprise-admin/scim?apiVersion=2022-11-28#provision-a-scim-enterprise-user
78+
type SCIMUserRole struct {
79+
Value string `json:"value"` // (Required.)
80+
Display *string `json:"display,omitempty"` // (Optional.)
81+
Type *string `json:"type,omitempty"` // (Optional.)
82+
Primary *bool `json:"primary,omitempty"` // (Optional.)
83+
}
84+
7185
// SCIMMeta represents metadata about the SCIM resource.
7286
type SCIMMeta struct {
7387
ResourceType *string `json:"resourceType,omitempty"`

github/scim_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,24 @@ func TestSCIMMeta_Marshal(t *testing.T) {
621621
testJSONMarshal(t, u, want)
622622
}
623623

624+
func TestSCIMUserRole_Marshal(t *testing.T) {
625+
t.Parallel()
626+
627+
testJSONMarshal(t, &SCIMUserRole{
628+
Value: "enterprise_owner",
629+
Primary: Bool(true),
630+
}, `{
631+
"value": "enterprise_owner",
632+
"primary": true
633+
}`)
634+
635+
r := &SCIMUserRole{
636+
Value: "billing_manager",
637+
}
638+
want := `{"value": "billing_manager"}`
639+
testJSONMarshal(t, r, want)
640+
}
641+
624642
func TestSCIMProvisionedIdentities_Marshal(t *testing.T) {
625643
t.Parallel()
626644
testJSONMarshal(t, &SCIMProvisionedIdentities{}, `{}`)

0 commit comments

Comments
 (0)