| 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/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/[email protected]/rest/enterprise-admin/ldap#update-ldap-mapping-for-a-user |
| 86 |
// |
| 87 |
//meta:operation PATCH /admin/ldap/users/{username}/mapping |
| 88 |
func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, mapping *UserLDAPMapping) (*UserLDAPMapping, *Response, error) { |
| 89 |
u := fmt.Sprintf("admin/ldap/users/%v/mapping", user) |
| 90 |
req, err := s.client.NewRequest("PATCH", u, mapping) |
| 91 |
if err != nil { |
| 92 |
return nil, nil, err |
| 93 |
} |
| 94 |
|
| 95 |
m := new(UserLDAPMapping) |
| 96 |
resp, err := s.client.Do(ctx, req, m) |
| 97 |
if err != nil { |
| 98 |
return nil, resp, err |
| 99 |
} |
| 100 |
|
| 101 |
return m, resp, nil |
| 102 |
} |
| 103 |
|
| 104 |
// UpdateTeamLDAPMapping updates the mapping between a GitHub team and an LDAP group. |
| 105 |
// |
| 106 |
// GitHub API docs: https://docs.github.com/[email protected]/rest/enterprise-admin/ldap#update-ldap-mapping-for-a-team |
| 107 |
// |
| 108 |
//meta:operation PATCH /admin/ldap/teams/{team_id}/mapping |
| 109 |
func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, team int64, mapping *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) { |
| 110 |
u := fmt.Sprintf("admin/ldap/teams/%v/mapping", team) |
| 111 |
req, err := s.client.NewRequest("PATCH", u, mapping) |
| 112 |
if err != nil { |
| 113 |
return nil, nil, err |
| 114 |
} |
| 115 |
|
| 116 |
m := new(TeamLDAPMapping) |
| 117 |
resp, err := s.client.Do(ctx, req, m) |
| 118 |
if err != nil { |
| 119 |
return nil, resp, err |
| 120 |
} |
| 121 |
|
| 122 |
return m, resp, nil |
| 123 |
} |