-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add roles and permissions apis to datadogpy * Update comments * Add roles * Indent * Indent
- Loading branch information
Showing
5 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,11 @@ | ||
from datadog.api.resources import ActionAPIResource, CreateableAPIResource, CustomUpdatableAPIResource, \ | ||
DeletableAPIResource, GetableAPIResource, ListableAPIResource | ||
|
||
|
||
class Permissions(ActionAPIResource, CreateableAPIResource, CustomUpdatableAPIResource, GetableAPIResource, | ||
ListableAPIResource, DeletableAPIResource): | ||
""" | ||
A wrapper around Tag HTTP API. | ||
""" | ||
_resource_name = 'permissions' | ||
_api_version = 'v2' |
This file contains 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 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,61 @@ | ||
from datadog.api.resources import ActionAPIResource, CreateableAPIResource, CustomUpdatableAPIResource,\ | ||
DeletableAPIResource, GetableAPIResource, ListableAPIResource | ||
|
||
from datadog.api.api_client import APIClient | ||
|
||
|
||
class Roles(ActionAPIResource, CreateableAPIResource, CustomUpdatableAPIResource, GetableAPIResource, | ||
ListableAPIResource, DeletableAPIResource): | ||
""" | ||
A wrapper around Tag HTTP API. | ||
""" | ||
_resource_name = 'roles' | ||
_api_version = 'v2' | ||
|
||
@classmethod | ||
def update(cls, id, **body): | ||
""" | ||
Update a role's attributes | ||
:param id: uuid of the role | ||
:param body: dict with type of the input and modified attributes | ||
:returns: Dictionary representing the API's JSON response | ||
""" | ||
params = {} | ||
return super(Roles, cls).update("PATCH", id, params=params, **body) | ||
|
||
@classmethod | ||
def assign_permission(cls, id, **body): | ||
""" | ||
Assign permission to a role | ||
:param id: uuid of the role to assign permission to | ||
:param body: dict with "type": "permissions" and uuid of permission to assign | ||
:returns: Dictionary representing the API's JSON response | ||
""" | ||
params = {} | ||
path = '{resource_name}/{resource_id}/permissions'.format( | ||
resource_name=cls._resource_name, | ||
resource_id=id | ||
) | ||
api_version = getattr(cls, '_api_version', None) | ||
|
||
return APIClient.submit("POST", path, api_version, body, **params) | ||
|
||
@classmethod | ||
def unassign_permission(cls, id, **body): | ||
""" | ||
Unassign permission from a role | ||
:param id: uuid of the role to unassign permission from | ||
:param body: dict with "type": "permissions" and uuid of permission to unassign | ||
:returns: Dictionary representing the API's JSON response | ||
""" | ||
params = {} | ||
path = '{resource_name}/{resource_id}/permissions'.format( | ||
resource_name=cls._resource_name, | ||
resource_id=id | ||
) | ||
api_version = getattr(cls, '_api_version', None) | ||
|
||
return APIClient.submit("DELETE", path, api_version, body, **params) |
This file contains 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