github.com/google/go-github/v57@v57.0.0/github/scim.go (about) 1 // Copyright 2021 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 "encoding/json" 11 "fmt" 12 ) 13 14 // SCIMService provides access to SCIM related functions in the 15 // GitHub API. 16 // 17 // GitHub API docs: https://docs.github.com/rest/scim 18 type SCIMService service 19 20 // SCIMUserAttributes represents supported SCIM User attributes. 21 // 22 // GitHub API docs: https://docs.github.com/rest/scim#supported-scim-user-attributes 23 type SCIMUserAttributes struct { 24 UserName string `json:"userName"` // Configured by the admin. Could be an email, login, or username. (Required.) 25 Name SCIMUserName `json:"name"` // (Required.) 26 DisplayName *string `json:"displayName,omitempty"` // The name of the user, suitable for display to end-users. (Optional.) 27 Emails []*SCIMUserEmail `json:"emails"` // User emails. (Required.) 28 Schemas []string `json:"schemas,omitempty"` // (Optional.) 29 ExternalID *string `json:"externalId,omitempty"` // (Optional.) 30 Groups []string `json:"groups,omitempty"` // (Optional.) 31 Active *bool `json:"active,omitempty"` // (Optional.) 32 // Only populated as a result of calling ListSCIMProvisionedIdentitiesOptions or GetSCIMProvisioningInfoForUser: 33 ID *string `json:"id,omitempty"` 34 Meta *SCIMMeta `json:"meta,omitempty"` 35 } 36 37 // SCIMUserName represents SCIM user information. 38 type SCIMUserName struct { 39 GivenName string `json:"givenName"` // The first name of the user. (Required.) 40 FamilyName string `json:"familyName"` // The family name of the user. (Required.) 41 Formatted *string `json:"formatted,omitempty"` // (Optional.) 42 } 43 44 // SCIMUserEmail represents SCIM user email. 45 type SCIMUserEmail struct { 46 Value string `json:"value"` // (Required.) 47 Primary *bool `json:"primary,omitempty"` // (Optional.) 48 Type *string `json:"type,omitempty"` // (Optional.) 49 } 50 51 // SCIMMeta represents metadata about the SCIM resource. 52 type SCIMMeta struct { 53 ResourceType *string `json:"resourceType,omitempty"` 54 Created *Timestamp `json:"created,omitempty"` 55 LastModified *Timestamp `json:"lastModified,omitempty"` 56 Location *string `json:"location,omitempty"` 57 } 58 59 // SCIMProvisionedIdentities represents the result of calling ListSCIMProvisionedIdentities. 60 type SCIMProvisionedIdentities struct { 61 Schemas []string `json:"schemas,omitempty"` 62 TotalResults *int `json:"totalResults,omitempty"` 63 ItemsPerPage *int `json:"itemsPerPage,omitempty"` 64 StartIndex *int `json:"startIndex,omitempty"` 65 Resources []*SCIMUserAttributes `json:"Resources,omitempty"` 66 } 67 68 // ListSCIMProvisionedIdentitiesOptions represents options for ListSCIMProvisionedIdentities. 69 // 70 // GitHub API docs: https://docs.github.com/rest/scim#list-scim-provisioned-identities--parameters 71 type ListSCIMProvisionedIdentitiesOptions struct { 72 StartIndex *int `url:"startIndex,omitempty"` // Used for pagination: the index of the first result to return. (Optional.) 73 Count *int `url:"count,omitempty"` // Used for pagination: the number of results to return. (Optional.) 74 // Filter results using the equals query parameter operator (eq). 75 // You can filter results that are equal to id, userName, emails, and external_id. 76 // For example, to search for an identity with the userName Octocat, you would use this query: ?filter=userName%20eq%20\"Octocat\". 77 // To filter results for the identity with the email octocat@github.com, you would use this query: ?filter=emails%20eq%20\"octocat@github.com\". 78 // (Optional.) 79 Filter *string `url:"filter,omitempty"` 80 } 81 82 // ListSCIMProvisionedIdentities lists SCIM provisioned identities. 83 // 84 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim#list-scim-provisioned-identities 85 // 86 //meta:operation GET /scim/v2/organizations/{org}/Users 87 func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org string, opts *ListSCIMProvisionedIdentitiesOptions) (*SCIMProvisionedIdentities, *Response, error) { 88 u := fmt.Sprintf("scim/v2/organizations/%v/Users", org) 89 u, err := addOptions(u, opts) 90 if err != nil { 91 return nil, nil, err 92 } 93 94 req, err := s.client.NewRequest("GET", u, nil) 95 if err != nil { 96 return nil, nil, err 97 } 98 99 identities := new(SCIMProvisionedIdentities) 100 resp, err := s.client.Do(ctx, req, identities) 101 if err != nil { 102 return nil, resp, err 103 } 104 105 return identities, resp, nil 106 } 107 108 // ProvisionAndInviteSCIMUser provisions organization membership for a user, and sends an activation email to the email address. 109 // 110 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim#provision-and-invite-a-scim-user 111 // 112 //meta:operation POST /scim/v2/organizations/{org}/Users 113 func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, opts *SCIMUserAttributes) (*Response, error) { 114 u := fmt.Sprintf("scim/v2/organizations/%v/Users", org) 115 u, err := addOptions(u, opts) 116 if err != nil { 117 return nil, err 118 } 119 120 req, err := s.client.NewRequest("POST", u, nil) 121 if err != nil { 122 return nil, err 123 } 124 125 return s.client.Do(ctx, req, nil) 126 } 127 128 // GetSCIMProvisioningInfoForUser returns SCIM provisioning information for a user. 129 // 130 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim#get-scim-provisioning-information-for-a-user 131 // 132 //meta:operation GET /scim/v2/organizations/{org}/Users/{scim_user_id} 133 func (s *SCIMService) GetSCIMProvisioningInfoForUser(ctx context.Context, org, scimUserID string) (*SCIMUserAttributes, *Response, error) { 134 u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID) 135 req, err := s.client.NewRequest("GET", u, nil) 136 if err != nil { 137 return nil, nil, err 138 } 139 140 user := new(SCIMUserAttributes) 141 resp, err := s.client.Do(ctx, req, &user) 142 if err != nil { 143 return nil, resp, err 144 } 145 146 return user, resp, nil 147 } 148 149 // UpdateProvisionedOrgMembership updates a provisioned organization membership. 150 // 151 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim#update-a-provisioned-organization-membership 152 // 153 //meta:operation PUT /scim/v2/organizations/{org}/Users/{scim_user_id} 154 func (s *SCIMService) UpdateProvisionedOrgMembership(ctx context.Context, org, scimUserID string, opts *SCIMUserAttributes) (*Response, error) { 155 u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID) 156 u, err := addOptions(u, opts) 157 if err != nil { 158 return nil, err 159 } 160 161 req, err := s.client.NewRequest("PUT", u, nil) 162 if err != nil { 163 return nil, err 164 } 165 166 return s.client.Do(ctx, req, nil) 167 } 168 169 // UpdateAttributeForSCIMUserOptions represents options for UpdateAttributeForSCIMUser. 170 // 171 // GitHub API docs: https://docs.github.com/rest/scim#update-an-attribute-for-a-scim-user--parameters 172 type UpdateAttributeForSCIMUserOptions struct { 173 Schemas []string `json:"schemas,omitempty"` // (Optional.) 174 Operations UpdateAttributeForSCIMUserOperations `json:"operations"` // Set of operations to be performed. (Required.) 175 } 176 177 // UpdateAttributeForSCIMUserOperations represents operations for UpdateAttributeForSCIMUser. 178 type UpdateAttributeForSCIMUserOperations struct { 179 Op string `json:"op"` // (Required.) 180 Path *string `json:"path,omitempty"` // (Optional.) 181 Value json.RawMessage `json:"value,omitempty"` // (Optional.) 182 } 183 184 // UpdateAttributeForSCIMUser updates an attribute for an SCIM user. 185 // 186 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim#update-an-attribute-for-a-scim-user 187 // 188 //meta:operation PATCH /scim/v2/organizations/{org}/Users/{scim_user_id} 189 func (s *SCIMService) UpdateAttributeForSCIMUser(ctx context.Context, org, scimUserID string, opts *UpdateAttributeForSCIMUserOptions) (*Response, error) { 190 u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID) 191 u, err := addOptions(u, opts) 192 if err != nil { 193 return nil, err 194 } 195 196 req, err := s.client.NewRequest("PATCH", u, nil) 197 if err != nil { 198 return nil, err 199 } 200 201 return s.client.Do(ctx, req, nil) 202 } 203 204 // DeleteSCIMUserFromOrg deletes SCIM user from an organization. 205 // 206 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim#delete-a-scim-user-from-an-organization 207 // 208 //meta:operation DELETE /scim/v2/organizations/{org}/Users/{scim_user_id} 209 func (s *SCIMService) DeleteSCIMUserFromOrg(ctx context.Context, org, scimUserID string) (*Response, error) { 210 u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID) 211 req, err := s.client.NewRequest("DELETE", u, nil) 212 if err != nil { 213 return nil, err 214 } 215 216 return s.client.Do(ctx, req, nil) 217 }