Skip to content
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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ linters:
- Repository
- RepositoryContentFileOptions
- RequiredStatusChecksRequest
- SCIMUserAttributes
- SourceImportAuthor
- Subscription
# Body type names exempt from the "Options" suffix rule.
Expand Down
88 changes: 88 additions & 0 deletions github/github-accessors.go

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

115 changes: 115 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.

22 changes: 19 additions & 3 deletions github/scim.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ type SCIMUserAttributes struct {
Roles []*SCIMUserRole `json:"roles,omitempty"` // (Optional, GHES only.)
Active *bool `json:"active,omitempty"` // (Optional.)
// Only populated as a result of calling ListSCIMProvisionedIdentitiesOptions or GetSCIMProvisioningInfoForUser:
ID *string `json:"id,omitempty"`
Meta *SCIMMeta `json:"meta,omitempty"`
ID *string `json:"id,omitempty"`
Meta *SCIMMeta `json:"meta,omitempty"`
OrganizationID *int64 `json:"organization_id,omitempty"`
ProfileURL *string `json:"profileUrl,omitempty"`
Operations []*UpdateAttributeForSCIMUserOperations `json:"operations,omitempty"`
}

// SCIMUserName represents SCIM user information.
Expand Down Expand Up @@ -119,12 +122,25 @@ func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org str
return identities, resp, nil
}

// ProvisionAndInviteSCIMUserRequest represents the body of a request to
// provision and invite a SCIM user.
type ProvisionAndInviteSCIMUserRequest struct {
UserName string `json:"userName"` // Configured by the admin. Could be an email, login, or username. (Required.)
Name SCIMUserName `json:"name"` // (Required.)
DisplayName *string `json:"displayName,omitempty"` // The name of the user, suitable for display to end-users. (Optional.)
Emails []*SCIMUserEmail `json:"emails"` // User emails. (Required.)
Schemas []string `json:"schemas,omitzero"` // (Optional.)
ExternalID *string `json:"externalId,omitempty"` // (Optional.)
Groups []string `json:"groups,omitzero"` // (Optional.)
Active *bool `json:"active,omitempty"` // (Optional.)
}

// ProvisionAndInviteSCIMUser provisions organization membership for a user, and sends an activation email to the email address.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim?apiVersion=2022-11-28#provision-and-invite-a-scim-user
//
//meta:operation POST /scim/v2/organizations/{org}/Users
func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, body *SCIMUserAttributes) (*SCIMUserAttributes, *Response, error) {
func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, body ProvisionAndInviteSCIMUserRequest) (*SCIMUserAttributes, *Response, error) {
u := fmt.Sprintf("scim/v2/organizations/%v/Users", org)

req, err := s.client.NewRequest(ctx, "POST", u, body)
Expand Down
52 changes: 36 additions & 16 deletions github/scim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,7 @@ func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/scim/v2/organizations/o/Users", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{"id":"1234567890","userName":"userName"}`)
})

ctx := t.Context()
opts := &SCIMUserAttributes{
body := ProvisionAndInviteSCIMUserRequest{
UserName: "userName",
Name: SCIMUserName{
GivenName: "givenName",
Expand All @@ -147,7 +140,16 @@ func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) {
},
},
}
user, _, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts)

mux.HandleFunc("/scim/v2/organizations/o/Users", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testJSONBody(t, r, body)
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{"id":"1234567890","userName":"userName"}`)
})

ctx := t.Context()
user, _, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", body)
if err != nil {
t.Errorf("SCIM.ProvisionAndInviteSCIMUser returned error: %v", err)
}
Expand All @@ -162,12 +164,12 @@ func TestSCIMService_ProvisionAndInviteSCIMUser(t *testing.T) {

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

testNewRequestAndDoFailureCategory(t, methodName, client, ScimCategory, func() (*Response, error) {
got, resp, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", opts)
got, resp, err := client.SCIM.ProvisionAndInviteSCIMUser(ctx, "o", body)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down Expand Up @@ -210,7 +212,16 @@ func TestSCIMService_GetSCIMProvisioningInfoForUser(t *testing.T) {
"created": ` + refTimeStr(1136178000) + `,
"lastModified": ` + refTimeStr(1136178001) + `,
"location": "https://api.github.com/scim/v2/organizations/octo-org/Users/edefdfedf-050c-11e7-8d32"
}
},
"organization_id": 1,
"profileUrl": "https://example.com/mona",
"operations": [
{
"op": "replace",
"path": "active",
"value": false
}
]
}`))
})

Expand Down Expand Up @@ -244,10 +255,19 @@ func TestSCIMService_GetSCIMProvisioningInfoForUser(t *testing.T) {
Value: "mona@octocat.github.com",
},
},
Schemas: []string{"urn:ietf:params:scim:schemas:core:2.0:User"},
ExternalID: new("a7d0f98382"),
Groups: nil,
Active: new(true),
Schemas: []string{"urn:ietf:params:scim:schemas:core:2.0:User"},
ExternalID: new("a7d0f98382"),
Groups: nil,
Active: new(true),
OrganizationID: new(int64(1)),
ProfileURL: new("https://example.com/mona"),
Operations: []*UpdateAttributeForSCIMUserOperations{
{
Op: "replace",
Path: new("active"),
Value: json.RawMessage(`false`),
},
},
}

if !cmp.Equal(user, &want) {
Expand Down
Loading