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