license.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // Copyright 2018, Patrick Webster
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package gitlab
  17. // LicenseService handles communication with the license
  18. // related methods of the GitLab API.
  19. //
  20. // GitLab API docs:
  21. // https://docs.gitlab.com/ee/api/license.html
  22. type LicenseService struct {
  23. client *Client
  24. }
  25. // License represents a GitLab license.
  26. //
  27. // GitLab API docs:
  28. // https://docs.gitlab.com/ee/api/license.html
  29. type License struct {
  30. StartsAt *ISOTime `json:"starts_at"`
  31. ExpiresAt *ISOTime `json:"expires_at"`
  32. Licensee struct {
  33. Name string `json:"Name"`
  34. Company string `json:"Company"`
  35. Email string `json:"Email"`
  36. } `json:"licensee"`
  37. UserLimit int `json:"user_limit"`
  38. ActiveUsers int `json:"active_users"`
  39. AddOns struct {
  40. GitLabFileLocks int `json:"GitLabFileLocks"`
  41. } `json:"add_ons"`
  42. }
  43. func (l License) String() string {
  44. return Stringify(l)
  45. }
  46. // GetLicense retrieves information about the current license.
  47. //
  48. // GitLab API docs:
  49. // https://docs.gitlab.com/ee/api/license.html#retrieve-information-about-the-current-license
  50. func (s *LicenseService) GetLicense() (*License, *Response, error) {
  51. req, err := s.client.NewRequest("GET", "license", nil, nil)
  52. if err != nil {
  53. return nil, nil, err
  54. }
  55. l := new(License)
  56. resp, err := s.client.Do(req, l)
  57. if err != nil {
  58. return nil, resp, err
  59. }
  60. return l, resp, err
  61. }
  62. // AddLicenseOptions represents the available AddLicense() options.
  63. //
  64. // https://docs.gitlab.com/ee/api/license.html#add-a-new-license
  65. type AddLicenseOptions struct {
  66. License *string `url:"license" json:"license"`
  67. }
  68. // AddLicense adds a new license.
  69. //
  70. // GitLab API docs:
  71. // https://docs.gitlab.com/ee/api/license.html#add-a-new-license
  72. func (s *LicenseService) AddLicense(opt *AddLicenseOptions, options ...OptionFunc) (*License, *Response, error) {
  73. req, err := s.client.NewRequest("POST", "license", opt, options)
  74. if err != nil {
  75. return nil, nil, err
  76. }
  77. l := new(License)
  78. resp, err := s.client.Do(req, l)
  79. if err != nil {
  80. return nil, resp, err
  81. }
  82. return l, resp, err
  83. }