...

Source file src/github.com/google/go-github/v47/github/scim.go

Documentation: github.com/google/go-github/v47/github

     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/en/rest/scim
    18  type SCIMService service
    19  
    20  // SCIMUserAttributes represents supported SCIM User attributes.
    21  //
    22  // GitHub API docs: https://docs.github.com/en/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  }
    33  
    34  // SCIMUserName represents SCIM user information.
    35  type SCIMUserName struct {
    36  	GivenName  string  `json:"givenName"`           // The first name of the user. (Required.)
    37  	FamilyName string  `json:"familyName"`          // The family name of the user. (Required.)
    38  	Formatted  *string `json:"formatted,omitempty"` // (Optional.)
    39  }
    40  
    41  // SCIMUserEmail represents SCIM user email.
    42  type SCIMUserEmail struct {
    43  	Value   string  `json:"value"`             // (Required.)
    44  	Primary *bool   `json:"primary,omitempty"` // (Optional.)
    45  	Type    *string `json:"type,omitempty"`    // (Optional.)
    46  }
    47  
    48  // ListSCIMProvisionedIdentitiesOptions represents options for ListSCIMProvisionedIdentities.
    49  //
    50  // Github API docs: https://docs.github.com/en/rest/scim#list-scim-provisioned-identities--parameters
    51  type ListSCIMProvisionedIdentitiesOptions struct {
    52  	StartIndex *int `json:"startIndex,omitempty"` // Used for pagination: the index of the first result to return. (Optional.)
    53  	Count      *int `json:"count,omitempty"`      // Used for pagination: the number of results to return. (Optional.)
    54  	// Filter results using the equals query parameter operator (eq).
    55  	// You can filter results that are equal to id, userName, emails, and external_id.
    56  	// For example, to search for an identity with the userName Octocat, you would use this query: ?filter=userName%20eq%20\"Octocat\".
    57  	// To filter results for the identity with the email octocat@github.com, you would use this query: ?filter=emails%20eq%20\"octocat@github.com\".
    58  	// (Optional.)
    59  	Filter *string `json:"filter,omitempty"`
    60  }
    61  
    62  // ListSCIMProvisionedIdentities lists SCIM provisioned identities.
    63  //
    64  // GitHub API docs: https://docs.github.com/en/rest/scim#list-scim-provisioned-identities
    65  func (s *SCIMService) ListSCIMProvisionedIdentities(ctx context.Context, org string, opts *ListSCIMProvisionedIdentitiesOptions) (*Response, error) {
    66  	u := fmt.Sprintf("scim/v2/organizations/%v/Users", org)
    67  	u, err := addOptions(u, opts)
    68  	if err != nil {
    69  		return nil, err
    70  	}
    71  	req, err := s.client.NewRequest("GET", u, nil)
    72  	if err != nil {
    73  		return nil, err
    74  	}
    75  	return s.client.Do(ctx, req, nil)
    76  }
    77  
    78  // ProvisionAndInviteSCIMUser provisions organization membership for a user, and sends an activation email to the email address.
    79  //
    80  // GitHub API docs: https://docs.github.com/en/rest/scim#provision-and-invite-a-scim-user
    81  func (s *SCIMService) ProvisionAndInviteSCIMUser(ctx context.Context, org string, opts *SCIMUserAttributes) (*Response, error) {
    82  	u := fmt.Sprintf("scim/v2/organizations/%v/Users", org)
    83  	u, err := addOptions(u, opts)
    84  	if err != nil {
    85  		return nil, err
    86  	}
    87  	req, err := s.client.NewRequest("POST", u, nil)
    88  	if err != nil {
    89  		return nil, err
    90  	}
    91  	return s.client.Do(ctx, req, nil)
    92  }
    93  
    94  // GetSCIMProvisioningInfoForUser returns SCIM provisioning information for a user.
    95  //
    96  // GitHub API docs: https://docs.github.com/en/rest/scim#supported-scim-user-attributes
    97  func (s *SCIMService) GetSCIMProvisioningInfoForUser(ctx context.Context, org, scimUserID string) (*Response, error) {
    98  	u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
    99  	req, err := s.client.NewRequest("GET", u, nil)
   100  	if err != nil {
   101  		return nil, err
   102  	}
   103  	return s.client.Do(ctx, req, nil)
   104  }
   105  
   106  // UpdateProvisionedOrgMembership updates a provisioned organization membership.
   107  //
   108  // GitHub API docs: https://docs.github.com/en/rest/scim#update-a-provisioned-organization-membership
   109  func (s *SCIMService) UpdateProvisionedOrgMembership(ctx context.Context, org, scimUserID string, opts *SCIMUserAttributes) (*Response, error) {
   110  	u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
   111  	u, err := addOptions(u, opts)
   112  	if err != nil {
   113  		return nil, err
   114  	}
   115  	req, err := s.client.NewRequest("PUT", u, nil)
   116  	if err != nil {
   117  		return nil, err
   118  	}
   119  	return s.client.Do(ctx, req, nil)
   120  }
   121  
   122  // UpdateAttributeForSCIMUserOptions represents options for UpdateAttributeForSCIMUser.
   123  //
   124  // GitHub API docs: https://docs.github.com/en/rest/scim#update-an-attribute-for-a-scim-user--parameters
   125  type UpdateAttributeForSCIMUserOptions struct {
   126  	Schemas    []string                             `json:"schemas,omitempty"` // (Optional.)
   127  	Operations UpdateAttributeForSCIMUserOperations `json:"operations"`        // Set of operations to be performed. (Required.)
   128  }
   129  
   130  // UpdateAttributeForSCIMUserOperations represents operations for UpdateAttributeForSCIMUser.
   131  type UpdateAttributeForSCIMUserOperations struct {
   132  	Op    string          `json:"op"`              // (Required.)
   133  	Path  *string         `json:"path,omitempty"`  // (Optional.)
   134  	Value json.RawMessage `json:"value,omitempty"` // (Optional.)
   135  }
   136  
   137  // UpdateAttributeForSCIMUser updates an attribute for an SCIM user.
   138  //
   139  // GitHub API docs: https://docs.github.com/en/rest/scim#update-an-attribute-for-a-scim-user
   140  func (s *SCIMService) UpdateAttributeForSCIMUser(ctx context.Context, org, scimUserID string, opts *UpdateAttributeForSCIMUserOptions) (*Response, error) {
   141  	u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
   142  	u, err := addOptions(u, opts)
   143  	if err != nil {
   144  		return nil, err
   145  	}
   146  	req, err := s.client.NewRequest("PATCH", u, nil)
   147  	if err != nil {
   148  		return nil, err
   149  	}
   150  	return s.client.Do(ctx, req, nil)
   151  }
   152  
   153  // DeleteSCIMUserFromOrg deletes SCIM user from an organization.
   154  //
   155  // GitHub API docs: https://docs.github.com/en/rest/scim#delete-a-scim-user-from-an-organization
   156  func (s *SCIMService) DeleteSCIMUserFromOrg(ctx context.Context, org, scimUserID string) (*Response, error) {
   157  	u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
   158  	req, err := s.client.NewRequest("DELETE", u, nil)
   159  	if err != nil {
   160  		return nil, err
   161  	}
   162  	return s.client.Do(ctx, req, nil)
   163  }
   164  

View as plain text