Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyphu committed Nov 7, 2023
1 parent 7f999aa commit 938ba75
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 14 deletions.
17 changes: 9 additions & 8 deletions test/test_live.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import warrant
import unittest


class LiveTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -686,16 +687,16 @@ def test_batch_create_delete_warrants(self):
user_has_permissions = warrant.Authz.check_many(
warrant.CheckOp.ALL_OF,
[
{"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}}
{"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}}
],
opts={"Warrant-Token": "latest"}
)
self.assertEqual(user_has_permissions, False)

warrants = warrant.Warrant.batch_create([
{"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}}
{"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}}
])
self.assertEqual(len(warrants), 2)

Expand All @@ -720,16 +721,16 @@ def test_batch_create_delete_warrants(self):
user_has_permissions = warrant.Authz.check_many(
warrant.CheckOp.ALL_OF,
[
{"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}}
{"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}}
],
opts={"Warrant-Token": "latest"}
)
self.assertEqual(user_has_permissions, True)

warrant.Warrant.batch_delete([
{"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}}
{"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([
{"objectType": permission1.object_type, "objectId": permission1.id},
Expand Down
3 changes: 2 additions & 1 deletion warrant/authz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from enum import Enum
from typing import Any, Dict, List, Optional, Union


class CheckOp(str, Enum):
ANY_OF = "anyOf"
ALL_OF = "allOf"

class Authz(APIResource):

class Authz(APIResource):
@classmethod
def check(cls, object_type: str, object_id: str, relation: str, subject, context: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> bool:
warrantToCheck = {
Expand Down
1 change: 1 addition & 0 deletions warrant/feature.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from warrant import APIResource, Subject, Warrant, WarrantObject, constants, ListResult
from typing import Any, Dict, List, Optional


class Feature(WarrantObject):
def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None:
self.id = id
Expand Down
1 change: 1 addition & 0 deletions warrant/list_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

T = TypeVar('T')


class ListResult(Generic[T]):
def __init__(self, results: List[T], prev_cursor: str = "", next_cursor: str = "") -> None:
self.results = results
Expand Down
1 change: 0 additions & 1 deletion warrant/pricing_tier.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def create(cls, id: str, meta: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -
def delete(cls, id: str, opts: Dict[str, Any] = {}):
return WarrantObject.delete("pricing-tier", id, opts=opts)


"""
Features
"""
Expand Down
1 change: 1 addition & 0 deletions warrant/query_result.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from warrant import Warrant
from typing import Any, Dict


class QueryResult:
def __init__(self, object_type: str, object_id: str, warrant: Warrant, is_implicit: bool, meta: Dict[str, Any] = {}):
self.object_type = object_type
Expand Down
1 change: 1 addition & 0 deletions warrant/role.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from warrant import APIResource, Permission, Subject, Warrant, WarrantObject, constants, ListResult
from typing import Any, Dict, List, Optional


class Role(WarrantObject):
def __init__(self, id: str = "", meta: Dict[str, Any] = {}) -> None:
self.id = id
Expand Down
5 changes: 4 additions & 1 deletion warrant/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def create(cls, id: str = "", meta: Dict[str, Any] = {}, opts: Dict[str, Any] =

@classmethod
def batch_create(cls, tenants: List[Dict[str, Any]], opts: Dict[str, Any] = {}) -> List["Tenant"]:
objects = map(lambda tenant: {"objectType": "tenant", "objectId": tenant['tenantId'], "meta": tenant['meta']} if "meta" in tenant.keys() else {"objectType": "tenant", "objectId": tenant['tenantId']}, tenants)
objects = map(
lambda tenant: {"objectType": "tenant", "objectId": tenant['tenantId'], "meta": tenant['meta']} if "meta" in tenant.keys() else {"objectType": "tenant", "objectId": tenant['tenantId']},
tenants
)
created_objects = WarrantObject.batch_create(list(objects), opts)
created_tenants = map(lambda warrant_obj: Tenant(warrant_obj.object_id, warrant_obj.meta), created_objects)
return list(created_tenants)
Expand Down
2 changes: 1 addition & 1 deletion warrant/warrant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from warrant import APIResource, WarrantException, ListResult
from typing import Any, Dict, List, Optional


class Subject(object):
def __init__(self, object_type, object_id, relation=""):
self.object_type = object_type
Expand Down Expand Up @@ -38,7 +39,6 @@ def from_json(obj):
return obj



class Warrant(APIResource):
object_type: str
object_id: str
Expand Down
5 changes: 3 additions & 2 deletions warrant/warrant_object.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from warrant import APIResource, ListResult
from typing import Any, Dict, List, Optional


class WarrantObject(APIResource):
def __init__(self, object_type: str, object_id: str, meta: Dict[str, Any] = {}) -> None:
self.object_type = object_type
Expand All @@ -14,9 +15,9 @@ def __init__(self, object_type: str, object_id: str, meta: Dict[str, Any] = {})
@classmethod
def list(cls, params: Dict[str, Any] = {}, opts: Dict[str, Any] = {}) -> ListResult["WarrantObject"]:
if params is None:
params={}
params = {}
if opts is None:
opts={}
opts = {}
list_result = cls._get(uri="/v2/objects", params=params, opts=opts, object_hook=WarrantObject.from_json)
if "prevCursor" in list_result and "nextCursor" in list_result:
return ListResult[WarrantObject](list_result['results'], list_result['prevCursor'], list_result['nextCursor'])
Expand Down

0 comments on commit 938ba75

Please sign in to comment.