|
| 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.GithubObject import Attribute, CompletableGithubObject, NotSet |
| 25 | +from github.NamedEnterpriseUser import NamedEnterpriseUser |
| 26 | +from github.PaginatedList import PaginatedList |
| 27 | + |
| 28 | + |
| 29 | +class EnterpriseConsumedLicenses(CompletableGithubObject): |
| 30 | + """ |
| 31 | + This class represents license consumed by enterprises. The reference can be found here https://docs.github.com/en/enterprise-cloud@latest/rest/enterprise-admin/license#list-enterprise-consumed-licenses |
| 32 | + """ |
| 33 | + |
| 34 | + def _initAttributes(self) -> None: |
| 35 | + self._total_seats_consumed: Attribute[int] = NotSet |
| 36 | + self._total_seats_purchased: Attribute[int] = NotSet |
| 37 | + self._enterprise: Attribute[str] = NotSet |
| 38 | + self._url: Attribute[str] = NotSet |
| 39 | + |
| 40 | + def __repr__(self) -> str: |
| 41 | + return self.get__repr__({"enterprise": self._enterprise.value}) |
| 42 | + |
| 43 | + @property |
| 44 | + def total_seats_consumed(self) -> int: |
| 45 | + return self._total_seats_consumed.value |
| 46 | + |
| 47 | + @property |
| 48 | + def total_seats_purchased(self) -> int: |
| 49 | + return self._total_seats_purchased.value |
| 50 | + |
| 51 | + @property |
| 52 | + def enterprise(self) -> str: |
| 53 | + self._completeIfNotSet(self._enterprise) |
| 54 | + return self._enterprise.value |
| 55 | + |
| 56 | + @property |
| 57 | + def url(self) -> str: |
| 58 | + self._completeIfNotSet(self._url) |
| 59 | + return self._url.value |
| 60 | + |
| 61 | + def get_users(self) -> PaginatedList[NamedEnterpriseUser]: |
| 62 | + """ |
| 63 | + :calls: `GET /enterprises/{enterprise}/consumed-licenses <https://docs.github.com/en/enterprise-cloud@latest/rest/enterprise-admin/license#list-enterprise-consumed-licenses>`_ |
| 64 | + """ |
| 65 | + |
| 66 | + url_parameters: Dict[str, Any] = {} |
| 67 | + return PaginatedList( |
| 68 | + NamedEnterpriseUser, |
| 69 | + self._requester, |
| 70 | + self.url, |
| 71 | + url_parameters, |
| 72 | + None, |
| 73 | + "users", |
| 74 | + self.raw_data, |
| 75 | + self.raw_headers, |
| 76 | + ) |
| 77 | + |
| 78 | + def _useAttributes(self, attributes: Dict[str, Any]) -> None: |
| 79 | + if "total_seats_consumed" in attributes: # pragma no branch |
| 80 | + self._total_seats_consumed = self._makeIntAttribute(attributes["total_seats_consumed"]) |
| 81 | + if "total_seats_purchased" in attributes: # pragma no branch |
| 82 | + self._total_seats_purchased = self._makeIntAttribute(attributes["total_seats_purchased"]) |
| 83 | + if "enterprise" in attributes: # pragma no branch |
| 84 | + self._enterprise = self._makeStringAttribute(attributes["enterprise"]) |
| 85 | + if "url" in attributes: # pragma no branch |
| 86 | + self._url = self._makeStringAttribute(attributes["url"]) |
0 commit comments