@@ -32,6 +32,14 @@ def _make_post_request(self, uri, json={}):
32
32
else :
33
33
raise WarrantException (msg = resp .text , status_code = resp .status_code )
34
34
35
+ def _make_get_request (self , uri , params = {}):
36
+ headers = { "Authorization" : "ApiKey " + self ._apiKey }
37
+ resp = requests .get (url = API_ENDPOINT + API_VERSION + uri , headers = headers , params = params )
38
+ if resp .status_code == 200 :
39
+ return resp .json ()
40
+ else :
41
+ raise WarrantException (msg = resp .text , status_code = resp .status_code )
42
+
35
43
def create_user (self , user_id = "" ):
36
44
if user_id == "" :
37
45
payload = {}
@@ -40,6 +48,14 @@ def create_user(self, user_id=""):
40
48
json = self ._make_post_request (uri = "/users" , json = payload )
41
49
return json ['userId' ]
42
50
51
+ def create_tenant (self , tenant_id = "" ):
52
+ if tenant_id == "" :
53
+ payload = {}
54
+ else :
55
+ payload = { "tenantId" : tenant_id }
56
+ json = self ._make_post_request (uri = "/tenants" , json = payload )
57
+ return json ['tenantId' ]
58
+
43
59
def create_session (self , user_id ):
44
60
if user_id == "" :
45
61
raise WarrantException (msg = "Invalid userId provided" )
@@ -63,6 +79,16 @@ def create_warrant(self, object_type, object_id, relation, user):
63
79
resp = self ._make_post_request (uri = "/warrants" , json = payload )
64
80
return resp ['id' ]
65
81
82
+ def list_warrants (self , object_type = "" , object_id = "" , relation = "" , user_id = "" ):
83
+ filters = {
84
+ "objectType" : object_type ,
85
+ "objectId" : object_id ,
86
+ "relation" : relation ,
87
+ "userId" : user_id ,
88
+ }
89
+ resp = self ._make_get_request (uri = "/warrants" , params = filters )
90
+ return resp
91
+
66
92
def is_authorized (self , object_type , object_id , relation , user_to_check ):
67
93
if object_type == "" or object_id == "" or relation == "" :
68
94
raise WarrantException (msg = "Invalid object_type, object_id and/or relation" )
0 commit comments