@@ -32,6 +32,14 @@ def _make_post_request(self, uri, json={}):
3232 else :
3333 raise WarrantException (msg = resp .text , status_code = resp .status_code )
3434
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+
3543 def create_user (self , user_id = "" ):
3644 if user_id == "" :
3745 payload = {}
@@ -40,6 +48,14 @@ def create_user(self, user_id=""):
4048 json = self ._make_post_request (uri = "/users" , json = payload )
4149 return json ['userId' ]
4250
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+
4359 def create_session (self , user_id ):
4460 if user_id == "" :
4561 raise WarrantException (msg = "Invalid userId provided" )
@@ -63,6 +79,16 @@ def create_warrant(self, object_type, object_id, relation, user):
6379 resp = self ._make_post_request (uri = "/warrants" , json = payload )
6480 return resp ['id' ]
6581
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+
6692 def is_authorized (self , object_type , object_id , relation , user_to_check ):
6793 if object_type == "" or object_id == "" or relation == "" :
6894 raise WarrantException (msg = "Invalid object_type, object_id and/or relation" )
0 commit comments