-
Notifications
You must be signed in to change notification settings - Fork 76
Added support for IAM endpoints #552
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
Open
ezilber-akamai
wants to merge
2
commits into
linode:proj/iam
Choose a base branch
from
ezilber-akamai:TPT-3700-iam
base: proj/iam
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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" | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import List | ||
|
||
from linode_api4.objects.base import Base, JSONObject, Property | ||
|
||
|
||
class LinodeEntity(Base): | ||
""" | ||
An Entity represents an entity of the account. | ||
|
||
Currently the Entity can only be retrieved by listing, i.e.: | ||
entities = client.iam.entities() | ||
|
||
API documentation: TODO | ||
""" | ||
|
||
properties = { | ||
"id": Property(identifier=True), | ||
"label": Property(), | ||
"type": Property(), | ||
} | ||
|
||
|
||
@dataclass | ||
class EntityAccess(JSONObject): | ||
""" | ||
EntityAccess represents a user's access to an entity. | ||
""" | ||
|
||
id: int | ||
type: str | ||
roles: List[str] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"id": 7, | ||
"label": "linode7", | ||
"type": "linode" | ||
}, | ||
{ | ||
"id": 10, | ||
"label": "linode10", | ||
"type": "linode" | ||
}, | ||
{ | ||
"id": 1, | ||
"label": "no_devices", | ||
"type": "firewall" | ||
}, | ||
{ | ||
"id": 2, | ||
"label": "active_with_nodebalancer", | ||
"type": "firewall" | ||
}, | ||
{ | ||
"id": 1, | ||
"label": "nodebalancer-active", | ||
"type": "nodebalancer" | ||
}, | ||
{ | ||
"id": 1, | ||
"label": "active", | ||
"type": "longview" | ||
}, | ||
{ | ||
"id": 3, | ||
"label": "LongviewClientTest", | ||
"type": "longview" | ||
}, | ||
{ | ||
"id": 1, | ||
"label": "linDomTest1.com", | ||
"type": "domain" | ||
}, | ||
{ | ||
"id": 1, | ||
"label": "API Test", | ||
"type": "stackscript" | ||
}, | ||
{ | ||
"id": 1, | ||
"label": "Test image - mine", | ||
"type": "image" | ||
}, | ||
{ | ||
"id": 3, | ||
"label": "Test image - mine - creating", | ||
"type": "image" | ||
}, | ||
{ | ||
"id": 1, | ||
"label": "volume1", | ||
"type": "volume" | ||
}, | ||
{ | ||
"id": 1, | ||
"label": "mongo_cluster", | ||
"type": "database" | ||
}, | ||
{ | ||
"id": 3, | ||
"label": "empty-vpc", | ||
"type": "vpc" | ||
} | ||
], | ||
"page": 1, | ||
"pages": 1, | ||
"results": 14 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"account_access": [ | ||
{ | ||
"type": "account", | ||
"roles": [ | ||
{ | ||
"name": "account_admin", | ||
"description": "Access to perform any supported action on all entities of the account", | ||
"permissions": [ | ||
"create_linode", | ||
"update_linode", | ||
"update_firewall" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "linode", | ||
"roles": [ | ||
{ | ||
"name": "account_linode_admin", | ||
"description": "Access to perform any supported action on all linode instances of the account", | ||
"permissions": [ | ||
"create_linode", | ||
"update_linode", | ||
"delete_linode" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "firewall", | ||
"roles": [ | ||
{ | ||
"name": "firewall_creator", | ||
"description": "Access to create a firewall instance", | ||
"permissions": [ | ||
"update_linode", | ||
"view_linode" | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"entity_access": [ | ||
{ | ||
"type": "linode", | ||
"roles": [ | ||
{ | ||
"name": "linode_contributor", | ||
"description": "Access to update a linode instance", | ||
"permissions": [ | ||
"update_linode", | ||
"view_linode" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"type": "firewall", | ||
"roles": [ | ||
{ | ||
"name": "firewall_viewer", | ||
"description": "Access to view a firewall instance", | ||
"permissions": [ | ||
"update_linode", | ||
"view_linode" | ||
] | ||
}, | ||
{ | ||
"name": "firewall_admin", | ||
"description": "Access to perform any supported action on a firewall instance", | ||
"permissions": [ | ||
"update_linode", | ||
"view_linode" | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"account_access": [ | ||
"account_linode_admin", | ||
"linode_creator", | ||
"firewall_creator" | ||
], | ||
"entity_access": [ | ||
{ | ||
"id": 1, | ||
"type": "linode", | ||
"roles": [ | ||
"linode_contributor" | ||
] | ||
}, | ||
{ | ||
"id": 1, | ||
"type": "firewall", | ||
"roles": [ | ||
"firewall_admin" | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.