admin.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. package github
  6. import (
  7. "context"
  8. "fmt"
  9. )
  10. // AdminService handles communication with the admin related methods of the
  11. // GitHub API. These API routes are normally only accessible for GitHub
  12. // Enterprise installations.
  13. //
  14. // GitHub API docs: https://developer.github.com/v3/enterprise/
  15. type AdminService service
  16. // TeamLDAPMapping represents the mapping between a GitHub team and an LDAP group.
  17. type TeamLDAPMapping struct {
  18. ID *int64 `json:"id,omitempty"`
  19. LDAPDN *string `json:"ldap_dn,omitempty"`
  20. URL *string `json:"url,omitempty"`
  21. Name *string `json:"name,omitempty"`
  22. Slug *string `json:"slug,omitempty"`
  23. Description *string `json:"description,omitempty"`
  24. Privacy *string `json:"privacy,omitempty"`
  25. Permission *string `json:"permission,omitempty"`
  26. MembersURL *string `json:"members_url,omitempty"`
  27. RepositoriesURL *string `json:"repositories_url,omitempty"`
  28. }
  29. func (m TeamLDAPMapping) String() string {
  30. return Stringify(m)
  31. }
  32. // UserLDAPMapping represents the mapping between a GitHub user and an LDAP user.
  33. type UserLDAPMapping struct {
  34. ID *int64 `json:"id,omitempty"`
  35. LDAPDN *string `json:"ldap_dn,omitempty"`
  36. Login *string `json:"login,omitempty"`
  37. AvatarURL *string `json:"avatar_url,omitempty"`
  38. GravatarID *string `json:"gravatar_id,omitempty"`
  39. Type *string `json:"type,omitempty"`
  40. SiteAdmin *bool `json:"site_admin,omitempty"`
  41. URL *string `json:"url,omitempty"`
  42. EventsURL *string `json:"events_url,omitempty"`
  43. FollowingURL *string `json:"following_url,omitempty"`
  44. FollowersURL *string `json:"followers_url,omitempty"`
  45. GistsURL *string `json:"gists_url,omitempty"`
  46. OrganizationsURL *string `json:"organizations_url,omitempty"`
  47. ReceivedEventsURL *string `json:"received_events_url,omitempty"`
  48. ReposURL *string `json:"repos_url,omitempty"`
  49. StarredURL *string `json:"starred_url,omitempty"`
  50. SubscriptionsURL *string `json:"subscriptions_url,omitempty"`
  51. }
  52. func (m UserLDAPMapping) String() string {
  53. return Stringify(m)
  54. }
  55. // UpdateUserLDAPMapping updates the mapping between a GitHub user and an LDAP user.
  56. //
  57. // GitHub API docs: https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-user
  58. func (s *AdminService) UpdateUserLDAPMapping(ctx context.Context, user string, mapping *UserLDAPMapping) (*UserLDAPMapping, *Response, error) {
  59. u := fmt.Sprintf("admin/ldap/users/%v/mapping", user)
  60. req, err := s.client.NewRequest("PATCH", u, mapping)
  61. if err != nil {
  62. return nil, nil, err
  63. }
  64. m := new(UserLDAPMapping)
  65. resp, err := s.client.Do(ctx, req, m)
  66. if err != nil {
  67. return nil, resp, err
  68. }
  69. return m, resp, nil
  70. }
  71. // UpdateTeamLDAPMapping updates the mapping between a GitHub team and an LDAP group.
  72. //
  73. // GitHub API docs: https://developer.github.com/v3/enterprise/ldap/#update-ldap-mapping-for-a-team
  74. func (s *AdminService) UpdateTeamLDAPMapping(ctx context.Context, team int64, mapping *TeamLDAPMapping) (*TeamLDAPMapping, *Response, error) {
  75. u := fmt.Sprintf("admin/ldap/teams/%v/mapping", team)
  76. req, err := s.client.NewRequest("PATCH", u, mapping)
  77. if err != nil {
  78. return nil, nil, err
  79. }
  80. m := new(TeamLDAPMapping)
  81. resp, err := s.client.Do(ctx, req, m)
  82. if err != nil {
  83. return nil, resp, err
  84. }
  85. return m, resp, nil
  86. }