/ github / Enterprise.py
Enterprise.py
 1  ############################ Copyrights and license ############################
 2  #                                                                              #
 3  # Copyright 2023 Yugo Hino <henom06@gmail.com>                                 #
 4  #                                                                              #
 5  # This file is part of PyGithub.                                               #
 6  # http://pygithub.readthedocs.io/                                              #
 7  #                                                                              #
 8  # PyGithub is free software: you can redistribute it and/or modify it under    #
 9  # the terms of the GNU Lesser General Public License as published by the Free  #
10  # Software Foundation, either version 3 of the License, or (at your option)    #
11  # any later version.                                                           #
12  #                                                                              #
13  # PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY  #
14  # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS    #
15  # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
16  # details.                                                                     #
17  #                                                                              #
18  # You should have received a copy of the GNU Lesser General Public License     #
19  # along with PyGithub. If not, see <http://www.gnu.org/licenses/>.             #
20  #                                                                              #
21  ################################################################################
22  from typing import Any, Dict
23  
24  from github.EnterpriseConsumedLicenses import EnterpriseConsumedLicenses
25  from github.GithubObject import Attribute, NonCompletableGithubObject, NotSet
26  from github.Requester import Requester
27  
28  
29  class Enterprise(NonCompletableGithubObject):
30      """
31      This class represents Enterprises. Such objects do not exist in the Github API, so this class merely collects all endpoints the start with /enterprises/{enterprise}/. See methods below for specific endpoints and docs.
32      https://docs.github.com/en/enterprise-cloud@latest/rest/enterprise-admin?apiVersion=2022-11-28
33      """
34  
35      def __init__(
36          self,
37          requester: Requester,
38          enterprise: str,
39      ):
40          super().__init__(requester, {}, {"enterprise": enterprise, "url": f"/enterprises/{enterprise}"}, True)
41  
42      def _initAttributes(self) -> None:
43          self._enterprise: Attribute[str] = NotSet
44          self._url: Attribute[str] = NotSet
45  
46      def __repr__(self) -> str:
47          return self.get__repr__({"enterprise": self._enterprise.value})
48  
49      @property
50      def enterprise(self) -> str:
51          return self._enterprise.value
52  
53      @property
54      def url(self) -> str:
55          return self._url.value
56  
57      def get_consumed_licenses(self) -> EnterpriseConsumedLicenses:
58          """
59          :calls: `GET /enterprises/{enterprise}/consumed-licenses <https://docs.github.com/en/enterprise-cloud@latest/rest/enterprise-admin/license#list-enterprise-consumed-licenses>`_
60          """
61          headers, data = self._requester.requestJsonAndCheck("GET", self.url + "/consumed-licenses")
62          if "url" not in data:
63              data["url"] = self.url + "/consumed-licenses"
64  
65          return EnterpriseConsumedLicenses(self._requester, headers, data, completed=True)
66  
67      def _useAttributes(self, attributes: Dict[str, Any]) -> None:
68          if "enterprise" in attributes:  # pragma no branch
69              self._enterprise = self._makeStringAttribute(attributes["enterprise"])
70          if "url" in attributes:  # pragma no branch
71              self._url = self._makeStringAttribute(attributes["url"])