Skip to content

Commit 61c462e

Browse files
authored
Add query api method (#8)
* Update example to delete created permission * Add query warrants method * Update query method to take a Subject object instead of string
1 parent 962bb3b commit 61c462e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

examples/example.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def make_warrant_requests(api_key):
4545
print(f"create_report role/permission check authorization result: {role_permission_check}")
4646
print(f"List all warrants: {client.list_warrants()}")
4747

48+
# Query all warrants for user1
49+
print(f"List all warrants for user1: {client.query_warrants(user1_subject)}")
50+
4851
# Delete users, tenants, roles, permissions
4952
client.remove_permission_from_role(admin_role, permission2)
5053
client.remove_permission_from_user(user1, permission1)
@@ -59,6 +62,8 @@ def make_warrant_requests(api_key):
5962
print("Deleted role " + admin_role)
6063
client.delete_permission(permission1)
6164
print("Deleted permission " + permission1)
65+
client.delete_permission(permission2)
66+
print("Deleted permission " + permission2)
6267

6368
if __name__ == '__main__':
6469
# Replace with your Warrant api key

warrant/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,18 @@ def list_warrants(self, object_type="", object_id="", relation="", user_id=""):
212212
resp = self._make_get_request(uri="/v1/warrants", params=filters)
213213
return resp
214214

215+
def query_warrants(self, subject, object_type="", relation=""):
216+
if not isinstance(subject, Subject):
217+
raise WarrantException(msg="Subject must be of type Subject")
218+
subject_param = subject.object_type + ":" + subject.object_id
219+
params = {
220+
"objectType": object_type,
221+
"relation": relation,
222+
"subject": subject_param,
223+
}
224+
resp = self._make_get_request(uri="/v1/query", params=params)
225+
return resp
226+
215227
def is_authorized(self, warrant_check):
216228
if not isinstance(warrant_check.warrants, list):
217229
raise WarrantException(msg="Must provide a list of warrants")

0 commit comments

Comments
 (0)