Skip to content

Commit ec2b5ba

Browse files
authored
feat(iam): add ListQuota method (#62)
1 parent 90c52d2 commit ec2b5ba

File tree

8 files changed

+372
-0
lines changed

8 files changed

+372
-0
lines changed

scaleway-async/scaleway_async/iam/v1alpha1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .types import ListGroupsRequestOrderBy
77
from .types import ListPermissionSetsRequestOrderBy
88
from .types import ListPoliciesRequestOrderBy
9+
from .types import ListQuotaRequestOrderBy
910
from .types import ListSSHKeysRequestOrderBy
1011
from .types import ListUsersRequestOrderBy
1112
from .types import PermissionSetScopeType
@@ -19,11 +20,13 @@
1920
from .types import ListGroupsResponse
2021
from .types import ListPermissionSetsResponse
2122
from .types import ListPoliciesResponse
23+
from .types import ListQuotaResponse
2224
from .types import ListRulesResponse
2325
from .types import ListSSHKeysResponse
2426
from .types import ListUsersResponse
2527
from .types import PermissionSet
2628
from .types import Policy
29+
from .types import Quotum
2730
from .types import Rule
2831
from .types import RuleSpecs
2932
from .types import SSHKey
@@ -38,6 +41,7 @@
3841
"ListGroupsRequestOrderBy",
3942
"ListPermissionSetsRequestOrderBy",
4043
"ListPoliciesRequestOrderBy",
44+
"ListQuotaRequestOrderBy",
4145
"ListSSHKeysRequestOrderBy",
4246
"ListUsersRequestOrderBy",
4347
"PermissionSetScopeType",
@@ -51,11 +55,13 @@
5155
"ListGroupsResponse",
5256
"ListPermissionSetsResponse",
5357
"ListPoliciesResponse",
58+
"ListQuotaResponse",
5459
"ListRulesResponse",
5560
"ListSSHKeysResponse",
5661
"ListUsersResponse",
5762
"PermissionSet",
5863
"Policy",
64+
"Quotum",
5965
"Rule",
6066
"RuleSpecs",
6167
"SSHKey",

scaleway-async/scaleway_async/iam/v1alpha1/api.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
ListGroupsRequestOrderBy,
2020
ListPermissionSetsRequestOrderBy,
2121
ListPoliciesRequestOrderBy,
22+
ListQuotaRequestOrderBy,
2223
ListSSHKeysRequestOrderBy,
2324
ListUsersRequestOrderBy,
2425
APIKey,
@@ -29,11 +30,13 @@
2930
ListGroupsResponse,
3031
ListPermissionSetsResponse,
3132
ListPoliciesResponse,
33+
ListQuotaResponse,
3234
ListRulesResponse,
3335
ListSSHKeysResponse,
3436
ListUsersResponse,
3537
PermissionSet,
3638
Policy,
39+
Quotum,
3740
Rule,
3841
RuleSpecs,
3942
SSHKey,
@@ -73,13 +76,15 @@
7376
unmarshal_Application,
7477
unmarshal_Group,
7578
unmarshal_Policy,
79+
unmarshal_Quotum,
7680
unmarshal_SSHKey,
7781
unmarshal_User,
7882
unmarshal_ListAPIKeysResponse,
7983
unmarshal_ListApplicationsResponse,
8084
unmarshal_ListGroupsResponse,
8185
unmarshal_ListPermissionSetsResponse,
8286
unmarshal_ListPoliciesResponse,
87+
unmarshal_ListQuotaResponse,
8388
unmarshal_ListRulesResponse,
8489
unmarshal_ListSSHKeysResponse,
8590
unmarshal_ListUsersResponse,
@@ -1728,3 +1733,91 @@ async def delete_api_key(
17281733

17291734
self._throw_on_error(res)
17301735
return None
1736+
1737+
async def list_quota(
1738+
self,
1739+
*,
1740+
order_by: ListQuotaRequestOrderBy = ListQuotaRequestOrderBy.NAME_ASC,
1741+
page: Optional[int] = None,
1742+
page_size: Optional[int] = None,
1743+
organization_id: Optional[str] = None,
1744+
) -> ListQuotaResponse:
1745+
"""
1746+
1747+
Usage:
1748+
::
1749+
1750+
result = await api.list_quota()
1751+
"""
1752+
1753+
res = self._request(
1754+
"GET",
1755+
f"/iam/v1alpha1/quota",
1756+
params={
1757+
"order_by": order_by,
1758+
"organization_id": organization_id
1759+
or self.client.default_organization_id,
1760+
"page": page,
1761+
"page_size": page_size or self.client.default_page_size,
1762+
},
1763+
)
1764+
1765+
self._throw_on_error(res)
1766+
return unmarshal_ListQuotaResponse(res.json())
1767+
1768+
async def list_quota_all(
1769+
self,
1770+
*,
1771+
order_by: Optional[ListQuotaRequestOrderBy] = None,
1772+
page: Optional[int] = None,
1773+
page_size: Optional[int] = None,
1774+
organization_id: Optional[str] = None,
1775+
) -> List[Quotum]:
1776+
"""
1777+
:return: :class:`List[ListQuotaResponse] <List[ListQuotaResponse]>`
1778+
1779+
Usage:
1780+
::
1781+
1782+
result = await api.list_quota_all()
1783+
"""
1784+
1785+
return await fetch_all_pages_async(
1786+
type=ListQuotaResponse,
1787+
key="quota",
1788+
fetcher=self.list_quota,
1789+
args={
1790+
"order_by": order_by,
1791+
"page": page,
1792+
"page_size": page_size,
1793+
"organization_id": organization_id,
1794+
},
1795+
)
1796+
1797+
async def get_quotum(
1798+
self,
1799+
*,
1800+
quotum_name: str,
1801+
organization_id: Optional[str] = None,
1802+
) -> Quotum:
1803+
"""
1804+
1805+
Usage:
1806+
::
1807+
1808+
result = await api.get_quotum(quotum_name="example")
1809+
"""
1810+
1811+
param_quotum_name = validate_path_param("quotum_name", quotum_name)
1812+
1813+
res = self._request(
1814+
"GET",
1815+
f"/iam/v1alpha1/quota/{param_quotum_name}",
1816+
params={
1817+
"organization_id": organization_id
1818+
or self.client.default_organization_id,
1819+
},
1820+
)
1821+
1822+
self._throw_on_error(res)
1823+
return unmarshal_Quotum(res.json())

scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
ListGroupsResponse,
1919
ListPermissionSetsResponse,
2020
ListPoliciesResponse,
21+
ListQuotaResponse,
2122
ListRulesResponse,
2223
ListSSHKeysResponse,
2324
ListUsersResponse,
2425
PermissionSet,
2526
Policy,
27+
Quotum,
2628
Rule,
2729
RuleSpecs,
2830
SSHKey,
@@ -238,6 +240,26 @@ def unmarshal_Policy(data: Any) -> Policy:
238240
return Policy(**args)
239241

240242

243+
def unmarshal_Quotum(data: Any) -> Quotum:
244+
if type(data) is not dict:
245+
raise TypeError(
246+
f"Unmarshalling the type 'Quotum' failed as data isn't a dictionary."
247+
)
248+
249+
args: Dict[str, Any] = {}
250+
251+
field = data.get("limit")
252+
args["limit"] = field
253+
254+
field = data.get("name")
255+
args["name"] = field
256+
257+
field = data.get("unlimited")
258+
args["unlimited"] = field
259+
260+
return Quotum(**args)
261+
262+
241263
def unmarshal_Rule(data: Any) -> Rule:
242264
if type(data) is not dict:
243265
raise TypeError(
@@ -433,6 +455,23 @@ def unmarshal_ListPoliciesResponse(data: Any) -> ListPoliciesResponse:
433455
return ListPoliciesResponse(**args)
434456

435457

458+
def unmarshal_ListQuotaResponse(data: Any) -> ListQuotaResponse:
459+
if type(data) is not dict:
460+
raise TypeError(
461+
f"Unmarshalling the type 'ListQuotaResponse' failed as data isn't a dictionary."
462+
)
463+
464+
args: Dict[str, Any] = {}
465+
466+
field = data.get("quota")
467+
args["quota"] = [unmarshal_Quotum(v) for v in data["quota"]]
468+
469+
field = data.get("total_count")
470+
args["total_count"] = field
471+
472+
return ListQuotaResponse(**args)
473+
474+
436475
def unmarshal_ListRulesResponse(data: Any) -> ListRulesResponse:
437476
if type(data) is not dict:
438477
raise TypeError(

scaleway-async/scaleway_async/iam/v1alpha1/types.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def __str__(self) -> str:
7575
return str(self.value)
7676

7777

78+
class ListQuotaRequestOrderBy(str, Enum):
79+
NAME_ASC = "name_asc"
80+
NAME_DESC = "name_desc"
81+
82+
def __str__(self) -> str:
83+
return str(self.value)
84+
85+
7886
class ListSSHKeysRequestOrderBy(str, Enum):
7987
CREATED_AT_ASC = "created_at_asc"
8088
CREATED_AT_DESC = "created_at_desc"
@@ -374,6 +382,13 @@ class ListPoliciesResponse:
374382
"""
375383

376384

385+
@dataclass
386+
class ListQuotaResponse:
387+
quota: List[Quotum]
388+
389+
total_count: int
390+
391+
377392
@dataclass
378393
class ListRulesResponse:
379394
"""
@@ -542,6 +557,21 @@ class Policy:
542557
"""
543558

544559

560+
@dataclass
561+
class Quotum:
562+
name: str
563+
564+
limit: Optional[int]
565+
"""
566+
One-of ('value'): at most one of 'limit', 'unlimited' could be set.
567+
"""
568+
569+
unlimited: Optional[bool]
570+
"""
571+
One-of ('value'): at most one of 'limit', 'unlimited' could be set.
572+
"""
573+
574+
545575
@dataclass
546576
class Rule:
547577
"""
@@ -1456,3 +1486,21 @@ class DeleteAPIKeyRequest:
14561486
"""
14571487
Access key to delete
14581488
"""
1489+
1490+
1491+
@dataclass
1492+
class ListQuotaRequest:
1493+
order_by: Optional[ListQuotaRequestOrderBy]
1494+
1495+
page: Optional[int]
1496+
1497+
page_size: Optional[int]
1498+
1499+
organization_id: Optional[str]
1500+
1501+
1502+
@dataclass
1503+
class GetQuotumRequest:
1504+
quotum_name: str
1505+
1506+
organization_id: Optional[str]

scaleway/scaleway/iam/v1alpha1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .types import ListGroupsRequestOrderBy
77
from .types import ListPermissionSetsRequestOrderBy
88
from .types import ListPoliciesRequestOrderBy
9+
from .types import ListQuotaRequestOrderBy
910
from .types import ListSSHKeysRequestOrderBy
1011
from .types import ListUsersRequestOrderBy
1112
from .types import PermissionSetScopeType
@@ -19,11 +20,13 @@
1920
from .types import ListGroupsResponse
2021
from .types import ListPermissionSetsResponse
2122
from .types import ListPoliciesResponse
23+
from .types import ListQuotaResponse
2224
from .types import ListRulesResponse
2325
from .types import ListSSHKeysResponse
2426
from .types import ListUsersResponse
2527
from .types import PermissionSet
2628
from .types import Policy
29+
from .types import Quotum
2730
from .types import Rule
2831
from .types import RuleSpecs
2932
from .types import SSHKey
@@ -38,6 +41,7 @@
3841
"ListGroupsRequestOrderBy",
3942
"ListPermissionSetsRequestOrderBy",
4043
"ListPoliciesRequestOrderBy",
44+
"ListQuotaRequestOrderBy",
4145
"ListSSHKeysRequestOrderBy",
4246
"ListUsersRequestOrderBy",
4347
"PermissionSetScopeType",
@@ -51,11 +55,13 @@
5155
"ListGroupsResponse",
5256
"ListPermissionSetsResponse",
5357
"ListPoliciesResponse",
58+
"ListQuotaResponse",
5459
"ListRulesResponse",
5560
"ListSSHKeysResponse",
5661
"ListUsersResponse",
5762
"PermissionSet",
5863
"Policy",
64+
"Quotum",
5965
"Rule",
6066
"RuleSpecs",
6167
"SSHKey",

0 commit comments

Comments
 (0)