Skip to content

Commit d6bb50b

Browse files
committed
Add list warrants method
1 parent a126428 commit d6bb50b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

examples/example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def make_warrant_requests(api_key):
1515
print(client.create_warrant(object_type="store", object_id="store1", relation="owner", user=new_user))
1616
is_authorized = client.is_authorized(object_type="store", object_id="store1", relation="owner", user_to_check=new_user)
1717
print(f"New user authorization result: {is_authorized}")
18+
print(f"All warrants: {client.list_warrants()}")
1819

1920
if __name__ == '__main__':
2021
# Replace with your Warrant api key

warrant/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = {}
@@ -71,6 +79,16 @@ def create_warrant(self, object_type, object_id, relation, user):
7179
resp = self._make_post_request(uri="/warrants", json=payload)
7280
return resp['id']
7381

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+
7492
def is_authorized(self, object_type, object_id, relation, user_to_check):
7593
if object_type == "" or object_id == "" or relation == "":
7694
raise WarrantException(msg="Invalid object_type, object_id and/or relation")

0 commit comments

Comments
 (0)