github.com/google/go-github/v49@v49.1.0/github/admin.go (about) 1 // Copyright 2016 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 "fmt" 11 ) 12 13 // AdminService handles communication with the admin related methods of the 14 // GitHub API. These API routes are normally only accessible for GitHub 15 // Enterprise installations. 16 // 17 // GitHub API docs: https://docs.github.com/en/rest/enterprise-admin 18 type AdminService service 19 20 // TeamLDAPMapping represents the mapping between a GitHub team and an LDAP group. 21 type TeamLDAPMapping struct { 22 ID *int64 `json:"id,omitempty"` 23 LDAPDN *string `json:"ldap_dn,omitempty"` 24 URL *string `json:"url,omitempty"` 25 Name *string `json:"name,omitempty"` 26 Slug *string `json:"slug,omitempty"` 27 Description *string `json:"description,omitempty"` 28 Privacy *string `json:"privacy,omitempty"` 29 Permission *string `json:"permission,omitempty"` 30 31 MembersURL *string `json:"members_url,omitempty"` 32 RepositoriesURL *string `json:"repositories_url,omitempty"` 33 } 34 35 func (m TeamLDAPMapping) String() string { 36 return Stringify(m) 37 } 38 39 // UserLDAPMapping represents the mapping between a GitHub user and an LDAP user. 40 type UserLDAPMapping struct { 41 ID *int64 `json:"id,omitempty"` 42 LDAPDN *string `json:"ldap_dn,omitempty"` 43 Login *string `json:"login,omitempty"` 44 AvatarURL *string `json:"avatar_url,omitempty"` 45 GravatarID *string `json:"gravatar_id,omitempty"` 46 Type *string `json:"type,omitempty"` 47 SiteAdmin *bool `json:"site_admin,omitempty"` 48 49 URL *string `json:"url,omitempty"` 50 EventsURL *string `json:"events_url,omitempty"` 51 FollowingURL *string `json:"following_url,omitempty"` 52 FollowersURL *string `json:"followers_url,omitempty"` 53 GistsURL *string `json:"gists_url,omitempty"` 54 OrganizationsURL *string `json:"organizations_url,omitempty"` 55 ReceivedEventsURL *string `json:"received_events_url,omitempty"` 56 ReposURL *string `json:"repos_url,omitempty"` 57 StarredURL *string `json:"starred_url,omitempty"` 58 SubscriptionsURL *string `json:"subscriptions_url,omitempty"` 59 } 60 61 func (m UserLDAPMapping) String() string { 62 return Stringify(m) 63 } 64 65 // Enterprise represents the GitHub enterprise profile. 66 type Enterprise struct { 67 ID *int `json:"id,omitempty"` 68 Slug *string `json:"slug,omitempty"` 69 Name *string `json:"name,omitempty"` 70 NodeID *string `json:"node_id,omitempty"` 71 AvatarURL *string `json:"avatar_url,omitempty"` 72 Description *string `json:"description,omitempty"` 73 WebsiteURL *string `json:"website_url,omitempty"` 74 HTMLURL *string `json:"html_url,omitempty"` 75 CreatedAt *Timestamp `json:"created_at,omitempty"` 76 UpdatedAt *Timestamp `json:"updated_at,omitempty"` 77 } 78 79 func (m Enterprise) String() string { 80 return Stringify(m) 81 } 82 83 // UpdateUserLDAPMapping updates the mapping between a GitHub user and an LDAP user. 84 // 85 // GitHub API docs: https://docs.github.com/en/enterprise-server/rest/enterprise-admin/ldap#update-ldap-mapping-for-a-user 86 func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, mapping *UserLDAPMapping) (*UserLDAPMapping, *Response, error) { 87 u := fmt.Sprintf("admin/ldap/users/%v/mapping", user) 88 req, err := s.client.NewRequest("PATCH", u, mapping) 89 if err != nil { 90 return nil, nil, err 91 } 92 93 m := new(UserLDAPMapping) 94 resp, err := s.client.Do(ctx, req, m) 95 if err != nil { 96 return nil, resp, err 97 } 98 99 return m, resp, nil 100 } 101 102 // UpdateTeamLDAPMapping updates the mapping between a GitHub team and an LDAP group. 103 // 104 // GitHub API docs: https://docs.github.com/en/rest/enterprise/ldap/#update-ldap-mapping-for-a-team 105 func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, team int64, mapping *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) { 106 u := fmt.Sprintf("admin/ldap/teams/%v/mapping", team) 107 req, err := s.client.NewRequest("PATCH", u, mapping) 108 if err != nil { 109 return nil, nil, err 110 } 111 112 m := new(TeamLDAPMapping) 113 resp, err := s.client.Do(ctx, req, m) 114 if err != nil { 115 return nil, resp, err 116 } 117 118 return m, resp, nil 119 }