forked from linode/linode_api4-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiam.py
More file actions
98 lines (72 loc) · 2.92 KB
/
Copy pathiam.py
File metadata and controls
98 lines (72 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from typing import Any, Dict, List, Optional, Union
from linode_api4.errors import UnexpectedResponseError
from linode_api4.groups import Group
from linode_api4.objects import EntityAccess, LinodeEntity
class IAMGroup(Group):
def role_permissions(self):
"""
Returns the permissions available on the account assigned to any user of the account.
This is intended to be called off of the :any:`LinodeClient`
class, like this::
permissions = client.role_permissions()
API Documentation: TODO
:returns: The JSON role permissions for the account.
"""
return self.client.get("/iam/role-permissions", model=self)
def role_permissions_user_get(self, username):
"""
Returns the permissions available on the account assigned to the specified user.
This is intended to be called off of the :any:`LinodeClient`
class, like this::
permissions = client.role_permissions_user_get("myusername")
API Documentation: TODO
:returns: The JSON role permissions for the user.
"""
return self.client.get(
f"/iam/users/{username}/role-permissions", model=self
)
def role_permissions_user_set(
self,
username,
account_access: Optional[List[str]] = None,
entity_access: Optional[
Union[List[EntityAccess], Dict[str, Any]]
] = None,
):
"""
Assigns the specified permissions to the specified user, and returns them.
This is intended to be called off of the :any:`LinodeClient`
class, like this::
permissions = client.role_permissions_user_set("muusername")
API Documentation: TODO
:returns: The JSON role permissions for the user.
"""
params = {
"account_access": account_access,
"entity_access": entity_access,
}
result = self.client.put(
f"/iam/users/{username}/role-permissions",
data=params,
)
if "account_access" not in result:
raise UnexpectedResponseError(
"Unexpected response updating role permissions!", json=result
)
return result
def entities(self, *filters):
"""
Returns the current entities of the account.
This is intended to be called off of the :any:`LinodeClient`
class, like this::
permissions = client.entities()
API Documentation: TODO
:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.
:returns: A list of entities that match the query.
:rtype: PaginatedList of Entity
"""
return self.client._get_and_filter(
LinodeEntity, *filters, endpoint="/entities"
)