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 6package github 7 8import ( 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://developer.github.com/v3/enterprise/ 18type AdminService service 19 20// TeamLDAPMapping represents the mapping between a GitHub team and an LDAP group. 21type 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 35func (m TeamLDAPMapping) String() string { 36 return Stringify(m) 37} 38 39// UserLDAPMapping represents the mapping between a GitHub user and an LDAP user. 40type 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 61func (m UserLDAPMapping) String() string { 62 return Stringify(m) 63} 64 65// UpdateUserLDAPMapping updates the mapping between a GitHub user and an LDAP user. 66// 67// GitHub API docs: https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-user 68func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, mapping *UserLDAPMapping) (*UserLDAPMapping, *Response, error) { 69 u := fmt.Sprintf("admin/ldap/users/%v/mapping", user) 70 req, err := s.client.NewRequest("PATCH", u, mapping) 71 if err != nil { 72 return nil, nil, err 73 } 74 75 m := new(UserLDAPMapping) 76 resp, err := s.client.Do(ctx, req, m) 77 if err != nil { 78 return nil, resp, err 79 } 80 81 return m, resp, nil 82} 83 84// UpdateTeamLDAPMapping updates the mapping between a GitHub team and an LDAP group. 85// 86// GitHub API docs: https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-team 87func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, team int64, mapping *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) { 88 u := fmt.Sprintf("admin/ldap/teams/%v/mapping", team) 89 req, err := s.client.NewRequest("PATCH", u, mapping) 90 if err != nil { 91 return nil, nil, err 92 } 93 94 m := new(TeamLDAPMapping) 95 resp, err := s.client.Do(ctx, req, m) 96 if err != nil { 97 return nil, resp, err 98 } 99 100 return m, resp, nil 101} 102