8000 Return proper responses for SCIM provisioned identities by tenyo · Pull Request #2474 · google/go-github · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Return proper responses for SCIM provisioned identities #2474

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 4 commits into from
Sep 27, 2022
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
72 changes: 72 additions & 0 deletions github/github-accessors.go

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

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

56 changes: 49 additions & 7 deletions github/scim.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type SCIMUserAttributes struct {
ExternalID *string `json:"externalId,omitempty"` // (Optional.)
Groups []string `json:"groups,omitempty"` // (Optional.)
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"`
}

// SCIMUserName represents SCIM user information.
Expand All @@ -45,6 +48,23 @@ type SCIMUserEmail struct {
Type *string `json:"type,omitempty"` // (Optional.)
}

// SCIMMeta represents metadata about the SCIM resource.
type SCIMMeta struct {
ResourceType *string `json:"resourceType,omitempty"`
Created *Timestamp `json:"created,omitempty"`
LastModified *Timestamp `json:"lastModified,omitempty"`
Location *string `json:"location,omitempty"`
}

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

// ListSCIMProvisionedIdentitiesOptions represents options for ListSCIMProvisionedIdentities.
//
// Github API docs: https://docs.github.com/en/rest/scim#list-scim-provisioned-identities--parameters
Expand All @@ -62,17 +82,25 @@ type ListSCIMProvisionedIdentitiesOptions struct {
// ListSCIMProvisionedIdentities lists SCIM provisioned identities.
//
// GitHub API docs: https://docs.github.com/en/rest/scim#list-scim-provisioned-identities
func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org string, opts *ListSCIMProvisionedIdentitiesOptions) (*Response, error) {
func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org string, opts *ListSCIMProvisionedIdentitiesOptions) (*SCIMProvisionedIdentities, *Response, error) {
u := fmt.Sprintf("scim/v2/organizations/%v/Users", org)
u, err := addOptions(u, opts)
if err != nil {
return nil, err
return nil, nil, err
}

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

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

return identities, resp, nil
}

// ProvisionAndInviteSCIMUser provisions organization membership for a user, and sends an activation email to the email address.
Expand All @@ -84,23 +112,32 @@ func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string
if err != nil {
return nil, err
}

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

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

// GetSCIMProvisioningInfoForUser returns SCIM provisioning information for a user.
//
// GitHub API docs: https://docs.github.com/en/rest/scim#supported-scim-user-attributes
func (s *SCIMService) GetSCIMProvisioningInfoForUser(ctx context.Context, org, scimUserID string) (*Response, error) {
func (s *SCIMService) GetSCIMProvisioningInfoForUser(ctx context.Context, org, scimUserID string) (*SCIMUserAttributes, *Response, error) {
u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, err
return nil, nil, err
}
return s.client.Do(ctx, req, nil)

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

return user, resp, nil
}

// UpdateProvisionedOrgMembership updates a provisioned organization membership.
Expand All @@ -112,10 +149,12 @@ func (s *SCIMService) UpdateProvisionedOrgMembership(ctx context.Context, org, s
if err != nil {
return nil, err
}

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

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

Expand Down Expand Up @@ -143,10 +182,12 @@ func (s *SCIMService) UpdateAttributeForSCIMUser(ctx context.Context, org, scimU
if err != nil {
return nil, err
}

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

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

Expand All @@ -159,5 +200,6 @@ func (s *SCIMService) DeleteSCIMUserFromOrg(ctx context.Context, org, scimUserID
if err != nil {
return nil, err
}

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