-
Notifications
You must be signed in to change notification settings - Fork 82
Add support for account and entity permissions endpoints #639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: proj/iam
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,3 +96,49 @@ def entities(self, *filters): | |
| return self.client._get_and_filter( | ||
| LinodeEntity, *filters, endpoint="/entities" | ||
| ) | ||
|
|
||
| def account_permissions_get(self, username): | ||
| """ | ||
| Returns the account-level permissions for the specified user. | ||
|
|
||
| This is intended to be called off of the :any:`LinodeClient` | ||
| class, like this:: | ||
|
|
||
| permissions_account = client.account_permissions_get("myusername") | ||
|
|
||
| API Documentation: TODO | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we provide link?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To my latest knowledge there is no working link yet. |
||
|
|
||
| :param username: The username to get permissions for. | ||
| :type username: str | ||
|
|
||
| :returns: The account-level permissions for the user. | ||
| :rtype: List[str] | ||
| """ | ||
| return self.client.get( | ||
| f"/iam/users/{username}/permissions/account", | ||
| ) | ||
|
|
||
| def entity_permissions_get(self, username, entity_type, entity_id): | ||
| """ | ||
| Returns the entity-level permissions for the specified user on a specific entity. | ||
|
|
||
| This is intended to be called off of the :any:`LinodeClient` | ||
| class, like this:: | ||
|
|
||
| permissions_entity = client.entity_permissions_get("myusername", "linode", 123456) | ||
dawiddzhafarov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| API Documentation: TODO | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we provide link?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To my latest knowledge there is no working link yet. |
||
|
|
||
| :param username: The username to get permissions for. | ||
| :type username: str | ||
| :param entity_type: The type of entity (e.g., "linode", "firewall"). | ||
| :type entity_type: str | ||
| :param entity_id: The ID of the specific entity. | ||
| :type entity_id: int | ||
|
|
||
| :returns: The entity-level permissions for the user on the specified entity. | ||
| :rtype: List[str] | ||
| """ | ||
| return self.client.get( | ||
| f"/iam/users/{username}/permissions/{entity_type}/{entity_id}" | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [ | ||
| "list_events", | ||
| "list_entities", | ||
| "view_account_settings", | ||
| "view_invoice_item", | ||
| "cancel_account", | ||
| "create_vpc" | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [ | ||
| "generate_linode_lish_token_remote", | ||
| "rebuild_linode", | ||
| "shutdown_linode", | ||
| "create_linode_config_profile", | ||
| "rescue_linode", | ||
| "list_linode_volumes" | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,3 +58,35 @@ def test_list_entities(test_linode_client): | |
| assert hasattr(entity, "type") | ||
| else: | ||
| pytest.skip("No entities found in IAM response.") | ||
|
|
||
|
|
||
| def test_get_account_permissions(test_linode_client): | ||
| client = test_linode_client | ||
| username = client.profile().username | ||
|
|
||
| account_permissions = client.iam.account_permissions_get(username) | ||
|
|
||
| if not account_permissions: | ||
| pytest.skip("No account permissions found for the user.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we silently skip the test?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know, checks for the details makes sense if the details exist. Should we fail the test?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to fail the test, but we can discuss it. |
||
| else: | ||
| assert len(account_permissions) > 0 | ||
|
|
||
|
|
||
| def test_get_entity_permissions(test_linode_client): | ||
| client = test_linode_client | ||
| username = client.profile().username | ||
|
|
||
| entities = client.iam.entities() | ||
| if not entities: | ||
| pytest.skip("no entities") | ||
| else: | ||
| entity = entities[0] | ||
| entity_permissions = client.iam.entity_permissions_get( | ||
| username, entity.type, entity.id | ||
| ) | ||
| if not entity_permissions: | ||
| pytest.skip( | ||
| "no entity permissions found for the user and chosen entity." | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
| else: | ||
| assert len(entity_permissions) > 0 | ||
Uh oh!
There was an error while loading. Please reload this page.