Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename WarrantObject to Object #17

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions test/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,46 +221,46 @@ def test_crud_features(self):
self.assertEqual(len(features_list.results), 0)

def test_crud_objects(self):
object1 = warrant.WarrantObject.create("document")
object1 = warrant.Object.create("document")
self.assertEqual(object1.object_type, "document")
self.assertIsNotNone(object1.object_id)
self.assertEqual(object1.meta, {})

object2 = warrant.WarrantObject.create("folder", "planning")
refetched_object = warrant.WarrantObject.get(object2.object_type, object2.object_id, {"Warrant-Token": "latest"})
object2 = warrant.Object.create("folder", "planning")
refetched_object = warrant.Object.get(object2.object_type, object2.object_id, {"Warrant-Token": "latest"})
self.assertEqual(object2.object_type, refetched_object.object_type)
self.assertEqual(object2.object_id, refetched_object.object_id)
self.assertEqual(object2.meta, refetched_object.meta)

object2.update({"description": "Second document"})
refetched_object = warrant.WarrantObject.get(object2.object_type, object2.object_id, {"Warrant-Token": "latest"})
refetched_object = warrant.Object.get(object2.object_type, object2.object_id, {"Warrant-Token": "latest"})
self.assertEqual(refetched_object.object_type, "folder")
self.assertEqual(refetched_object.object_id, "planning")
self.assertEqual(refetched_object.meta, {"description": "Second document"})

objects_list = warrant.WarrantObject.list({"sortBy": "createdAt", "limit": 10}, {"Warrant-Token": "latest"})
objects_list = warrant.Object.list({"sortBy": "createdAt", "limit": 10}, {"Warrant-Token": "latest"})
self.assertEqual(len(objects_list.results), 2)
self.assertEqual(objects_list.results[0].object_type, object1.object_type)
self.assertEqual(objects_list.results[0].object_id, object1.object_id)
self.assertEqual(objects_list.results[1].object_type, object2.object_type)
self.assertEqual(objects_list.results[1].object_id, object2.object_id)

warrant_token = warrant.WarrantObject.delete(object1.object_type, object1.object_id)
warrant_token = warrant.Object.delete(object1.object_type, object1.object_id)
self.assertIsNotNone(warrant_token)
warrant_token = warrant.WarrantObject.delete(object2.object_type, object2.object_id)
warrant_token = warrant.Object.delete(object2.object_type, object2.object_id)
self.assertIsNotNone(warrant_token)
objects_list = warrant.WarrantObject.list({"sortBy": "createdAt", "limit": 10}, {"Warrant-Token": "latest"})
objects_list = warrant.Object.list({"sortBy": "createdAt", "limit": 10}, {"Warrant-Token": "latest"})
self.assertEqual(len(objects_list.results), 0)

def test_batch_create_delete_objects(self):
objects = warrant.WarrantObject.batch_create([
objects = warrant.Object.batch_create([
{"objectType": "document", "objectId": "document-a"},
{"objectType": "document", "objectId": "document-b"},
{"objectType": "folder", "objectId": "resources", "meta": {"description": "Helpful documents"}}
])
self.assertEqual(len(objects), 3)

objects_list = warrant.WarrantObject.list({"limit": 10}, {"Warrant-Token": "latest"})
objects_list = warrant.Object.list({"limit": 10}, {"Warrant-Token": "latest"})
self.assertEqual(len(objects_list.results), 3)
self.assertEqual(objects_list.results[0].object_type, "document")
self.assertEqual(objects_list.results[0].object_id, "document-a")
Expand All @@ -270,12 +270,12 @@ def test_batch_create_delete_objects(self):
self.assertEqual(objects_list.results[2].object_id, "resources")
self.assertEqual(objects_list.results[2].meta, {"description": "Helpful documents"})

warrant.WarrantObject.batch_delete([
warrant.Object.batch_delete([
{"objectType": "document", "objectId": "document-a"},
{"objectType": "document", "objectId": "document-b"},
{"objectType": "folder", "objectId": "resources", "meta": {"description": "Helpful documents"}}
])
objects_list = warrant.WarrantObject.list({"limit": 10}, {"Warrant-Token": "latest"})
objects_list = warrant.Object.list({"limit": 10}, {"Warrant-Token": "latest"})
self.assertEqual(len(objects_list.results), 0)

def test_multitenancy_example(self):
Expand Down Expand Up @@ -732,7 +732,7 @@ def test_batch_create_delete_warrants(self):
{"objectType": permission1.object_type, "objectId": permission1.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}},
{"objectType": permission2.object_type, "objectId": permission2.id, "relation": "member", "subject": {"objectType": new_user.object_type, "objectId": new_user.id}}
])
warrant.WarrantObject.batch_delete([
warrant.Object.batch_delete([
{"objectType": permission1.object_type, "objectId": permission1.id},
{"objectType": permission2.object_type, "objectId": permission2.id},
{"objectType": new_user.object_type, "objectId": new_user.id},
Expand Down
2 changes: 1 addition & 1 deletion warrant/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from warrant.api_resource import APIResource, WarrantException
from warrant.list_result import ListResult
from warrant.warrant_object import WarrantObject
from warrant.object import Object
from warrant.warrant import Warrant, Subject, QueryResult
from warrant.authz import Authz, CheckOp

Expand Down
14 changes: 7 additions & 7 deletions warrant/feature.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from warrant import APIResource, Subject, Warrant, WarrantObject, constants, ListResult
from warrant import APIResource, Subject, Warrant, Object, constants, ListResult
from typing import Any, Dict, List, Optional


class Feature(WarrantObject):
class Feature(Object):
def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None:
self.id = id
WarrantObject.__init__(self, "feature", id, meta)
Object.__init__(self, "feature", id, meta)

@classmethod
def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
list_params['objectType'] = 'feature'
list_result = WarrantObject.list(list_params, opts=opts)
list_result = Object.list(list_params, opts=opts)
features = map(lambda warrant_obj: Feature(warrant_obj.object_id, warrant_obj.meta), list_result.results)
if list_result.prev_cursor != "" and list_result.next_cursor != "":
return ListResult[Feature](list(features), list_result.prev_cursor, list_result.next_cursor)
Expand All @@ -23,17 +23,17 @@ def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):

@classmethod
def get(cls, id: str, opts: Dict[str, Any] = {}) -> "Feature":
warrant_obj = WarrantObject.get("feature", id, opts=opts)
warrant_obj = Object.get("feature", id, opts=opts)
return Feature.from_warrant_obj(warrant_obj)

@classmethod
def create(cls, id: str, meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> "Feature":
warrant_obj = WarrantObject.create("feature", id, meta, opts=opts)
warrant_obj = Object.create("feature", id, meta, opts=opts)
return Feature.from_warrant_obj(warrant_obj)

@classmethod
def delete(cls, id: str, opts: Dict[str, Any] = {}) -> Optional[str]:
return WarrantObject.delete("feature", id, opts=opts)
return Object.delete("feature", id, opts=opts)

"""
Pricing tiers
Expand Down
32 changes: 16 additions & 16 deletions warrant/warrant_object.py → warrant/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@
from typing import Any, Dict, List, Optional


class WarrantObject(APIResource):
class Object(APIResource):
def __init__(self, object_type: str, object_id: str, meta: Dict[str, Any] = {}) -> None:
self.object_type = object_type
self.object_id = object_id
self.meta = meta

@classmethod
def list(cls, params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> ListResult["WarrantObject"]:
def list(cls, params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> ListResult["Object"]:
if params is None:
params = {}
if opts is None:
opts = {}
list_result = cls._get(uri="/v2/objects", params=params, opts=opts, object_hook=WarrantObject.from_json)
list_result = cls._get(uri="/v2/objects", params=params, opts=opts, object_hook=Object.from_json)
if "prevCursor" in list_result and "nextCursor" in list_result:
return ListResult[WarrantObject](list_result['results'], list_result['prevCursor'], list_result['nextCursor'])
return ListResult[Object](list_result['results'], list_result['prevCursor'], list_result['nextCursor'])
elif "prevCursor" in list_result:
return ListResult[WarrantObject](list_result['results'], list_result['prevCursor'])
return ListResult[Object](list_result['results'], list_result['prevCursor'])
elif "nextCursor" in list_result:
return ListResult[WarrantObject](list_result['results'], next_cursor=list_result['nextCursor'])
return ListResult[Object](list_result['results'], next_cursor=list_result['nextCursor'])
else:
return ListResult[WarrantObject](list_result['results'])
return ListResult[Object](list_result['results'])

@classmethod
def create(cls, object_type: str, object_id: str = "", meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> "WarrantObject":
def create(cls, object_type: str, object_id: str = "", meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> "Object":
payload: Dict[str, Any] = {
"objectType": object_type
}
if object_id is not None and object_id != "":
payload["objectId"] = object_id
if meta != {}:
payload["meta"] = meta
return cls._post(uri="/v2/objects", json_payload=payload, opts=opts, object_hook=WarrantObject.from_json)
return cls._post(uri="/v2/objects", json_payload=payload, opts=opts, object_hook=Object.from_json)

@classmethod
def batch_create(cls, objects: List[Dict[str, Any]], opts: Dict[str, Any] = {}) -> List["WarrantObject"]:
return cls._post(uri="/v2/objects", json_payload=objects, opts=opts, object_hook=WarrantObject.from_json)
def batch_create(cls, objects: List[Dict[str, Any]], opts: Dict[str, Any] = {}) -> List["Object"]:
return cls._post(uri="/v2/objects", json_payload=objects, opts=opts, object_hook=Object.from_json)

@classmethod
def get(cls, object_type: str, object_id: str, opts: Dict[str, Any] = {}) -> "WarrantObject":
return cls._get("/v2/objects/"+object_type+"/"+object_id, params={}, opts=opts, object_hook=WarrantObject.from_json)
def get(cls, object_type: str, object_id: str, opts: Dict[str, Any] = {}) -> "Object":
return cls._get("/v2/objects/"+object_type+"/"+object_id, params={}, opts=opts, object_hook=Object.from_json)

def update(self, meta: Dict[str, Any], opts: Dict[str, Any] = {}) -> None:
payload = {
"meta": meta
}
updated_obj = self._put(uri="/v2/objects/"+self.object_type+"/"+self.object_id, json_payload=payload, opts=opts, object_hook=WarrantObject.from_json)
updated_obj = self._put(uri="/v2/objects/"+self.object_type+"/"+self.object_id, json_payload=payload, opts=opts, object_hook=Object.from_json)
self.meta = updated_obj.meta

@classmethod
Expand All @@ -65,8 +65,8 @@ def batch_delete(cls, objects: List[Dict[str, Any]], opts: Dict[str, Any] = {})
def from_json(obj):
if "objectType" in obj and "objectId" in obj:
if "meta" in obj:
return WarrantObject(obj["objectType"], obj["objectId"], obj["meta"])
return Object(obj["objectType"], obj["objectId"], obj["meta"])
else:
return WarrantObject(obj["objectType"], obj["objectId"])
return Object(obj["objectType"], obj["objectId"])
else:
return obj
14 changes: 7 additions & 7 deletions warrant/permission.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from warrant import APIResource, Subject, Warrant, WarrantObject, constants, ListResult
from warrant import APIResource, Subject, Warrant, Object, constants, ListResult
from typing import Any, Dict, List, Optional


class Permission(WarrantObject):
class Permission(Object):
def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None:
self.id = id
WarrantObject.__init__(self, "permission", id, meta)
Object.__init__(self, "permission", id, meta)

@classmethod
def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
list_params['objectType'] = 'permission'
list_result = WarrantObject.list(list_params, opts=opts)
list_result = Object.list(list_params, opts=opts)
permissions = map(lambda warrant_obj: Permission(warrant_obj.object_id, warrant_obj.meta), list_result.results)
if list_result.prev_cursor != "" and list_result.next_cursor != "":
return ListResult[Permission](list(permissions), list_result.prev_cursor, list_result.next_cursor)
Expand All @@ -23,17 +23,17 @@ def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):

@classmethod
def get(cls, id: str, opts: Dict[str, Any] = {}) -> "Permission":
warrant_obj = WarrantObject.get("permission", id, opts=opts)
warrant_obj = Object.get("permission", id, opts=opts)
return Permission.from_warrant_obj(warrant_obj)

@classmethod
def create(cls, id: str, meta={}, opts: Dict[str, Any] = {}) -> "Permission":
warrant_obj = WarrantObject.create("permission", id, meta, opts=opts)
warrant_obj = Object.create("permission", id, meta, opts=opts)
return Permission.from_warrant_obj(warrant_obj)

@classmethod
def delete(cls, id: str, opts: Dict[str, Any] = {}) -> Optional[str]:
return WarrantObject.delete("permission", id, opts=opts)
return Object.delete("permission", id, opts=opts)

"""
Users
Expand Down
14 changes: 7 additions & 7 deletions warrant/pricing_tier.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from warrant import APIResource, Feature, Subject, Warrant, WarrantObject, constants, ListResult
from warrant import APIResource, Feature, Subject, Warrant, Object, constants, ListResult
from typing import Any, Dict, List, Optional


class PricingTier(WarrantObject):
class PricingTier(Object):
def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None:
self.id = id
WarrantObject.__init__(self, "pricing-tier", id, meta)
Object.__init__(self, "pricing-tier", id, meta)

@classmethod
def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
list_params['objectType'] = 'pricing-tier'
list_result = WarrantObject.list(list_params, opts=opts)
list_result = Object.list(list_params, opts=opts)
pricing_tiers = map(lambda warrant_obj: PricingTier(warrant_obj.object_id, warrant_obj.meta), list_result.results)
if list_result.prev_cursor != "" and list_result.next_cursor != "":
return ListResult[PricingTier](list(pricing_tiers), list_result.prev_cursor, list_result.next_cursor)
Expand All @@ -23,17 +23,17 @@ def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):

@classmethod
def get(cls, id: str, opts: Dict[str, Any] = {}) -> "PricingTier":
warrant_obj = WarrantObject.get("pricing-tier", id, opts=opts)
warrant_obj = Object.get("pricing-tier", id, opts=opts)
return PricingTier.from_warrant_obj(warrant_obj)

@classmethod
def create(cls, id: str, meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> "PricingTier":
warrant_obj = WarrantObject.create("pricing-tier", id, meta, opts=opts)
warrant_obj = Object.create("pricing-tier", id, meta, opts=opts)
return PricingTier.from_warrant_obj(warrant_obj)

@classmethod
def delete(cls, id: str, opts: Dict[str, Any] = {}):
return WarrantObject.delete("pricing-tier", id, opts=opts)
return Object.delete("pricing-tier", id, opts=opts)

"""
Features
Expand Down
14 changes: 7 additions & 7 deletions warrant/role.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from warrant import APIResource, Permission, Subject, Warrant, WarrantObject, constants, ListResult
from warrant import APIResource, Permission, Subject, Warrant, Object, constants, ListResult
from typing import Any, Dict, List, Optional


class Role(WarrantObject):
class Role(Object):
def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None:
self.id = id
WarrantObject.__init__(self, "role", id, meta)
Object.__init__(self, "role", id, meta)

@classmethod
def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):
list_params['objectType'] = 'role'
list_result = WarrantObject.list(list_params, opts=opts)
list_result = Object.list(list_params, opts=opts)
roles = map(lambda warrant_obj: Role(warrant_obj.object_id, warrant_obj.meta), list_result.results)
if list_result.prev_cursor != "" and list_result.next_cursor != "":
return ListResult[Role](list(roles), list_result.prev_cursor, list_result.next_cursor)
Expand All @@ -23,17 +23,17 @@ def list(cls, list_params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}):

@classmethod
def get(cls, id: str, opts: Dict[str, Any] = {}) -> "Role":
warrant_obj = WarrantObject.get("role", id, opts=opts)
warrant_obj = Object.get("role", id, opts=opts)
return Role.from_warrant_obj(warrant_obj)

@classmethod
def create(cls, id: str = "", meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> "Role":
warrant_obj = WarrantObject.create("role", id, meta, opts=opts)
warrant_obj = Object.create("role", id, meta, opts=opts)
return Role.from_warrant_obj(warrant_obj)

@classmethod
def delete(cls, id: str, opts: Dict[str, Any] = {}) -> Optional[str]:
return WarrantObject.delete("role", id, opts=opts)
return Object.delete("role", id, opts=opts)

"""
Users
Expand Down
Loading