forked from DataDog/datadogpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroles.py
More file actions
71 lines (59 loc) · 2.31 KB
/
Copy pathroles.py
File metadata and controls
71 lines (59 loc) · 2.31 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
# Unless explicitly stated otherwise all files in this repository are licensed under the BSD-3-Clause License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2015-Present Datadog, Inc
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, role `id`, 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)