Skip to content

Commit 1034b90

Browse files
authored
fix: Ensure at least one permission when calling allow. (#126)
2 parents f76b971 + aa864de commit 1034b90

5 files changed

Lines changed: 10 additions & 10 deletions

File tree

nitric/resources/buckets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def _perms_to_actions(self, *args: BucketPermission) -> List[int]:
6969
def _to_resource(self) -> Resource:
7070
return Resource(name=self.name, type=ResourceType.Bucket) # type:ignore
7171

72-
def allow(self, *args: BucketPermission) -> BucketRef:
72+
def allow(self, perm: BucketPermission, *args: BucketPermission) -> BucketRef:
7373
"""Request the required permissions for this resource."""
74-
str_args = [str(permission) for permission in args]
74+
str_args = [str(perm)] + [str(permission) for permission in args]
7575
self._register_policy(*str_args)
7676

7777
return Storage().bucket(self.name)

nitric/resources/collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ def _perms_to_actions(self, *args: CollectionPermission) -> List[int]:
6767

6868
return [action for perm in args for action in permission_actions_map[perm]]
6969

70-
def allow(self, *args: CollectionPermission) -> CollectionRef:
70+
def allow(self, perm: CollectionPermission, *args: CollectionPermission) -> CollectionRef:
7171
"""Request the required permissions for this collection."""
7272
# Ensure registration of the resource is complete before requesting permissions.
73-
str_args = [str(permission) for permission in args]
73+
str_args = [str(perm)] + [str(permission) for permission in args]
7474
self._register_policy(*str_args)
7575

7676
return Documents().collection(self.name)

nitric/resources/queues.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ async def _register(self) -> None:
6565
except GRPCError as grpc_err:
6666
raise exception_from_grpc_error(grpc_err)
6767

68-
def allow(self, *args: QueuePermission) -> QueueRef:
68+
def allow(self, perm: QueuePermission, *args: QueuePermission) -> QueueRef:
6969
"""Request the required permissions for this queue."""
7070
# Ensure registration of the resource is complete before requesting permissions.
71-
str_args = [str(permission) for permission in args]
71+
str_args = [str(perm)] + [str(permission) for permission in args]
7272
self._register_policy(*str_args)
7373

7474
return Queues().queue(self.name)

nitric/resources/secrets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def _perms_to_actions(self, *args: SecretPermission) -> List[int]:
6666

6767
return [action for perm in args for action in permissions_actions_map[perm]]
6868

69-
def allow(self, *args: SecretPermission) -> SecretContainerRef:
69+
def allow(self, perm: SecretPermission, *args: SecretPermission) -> SecretContainerRef:
7070
"""Request the specified permissions to this resource."""
71-
str_args = [str(permission) for permission in args]
71+
str_args = [str(perm)] + [str(permission) for permission in args]
7272
self._register_policy(*str_args)
7373

7474
return Secrets().secret(self.name)

nitric/resources/topics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def _perms_to_actions(self, *args: TopicPermission) -> List[int]:
6363

6464
return [action for perm in args for action in _permMap[perm]]
6565

66-
def allow(self, *args: TopicPermission) -> TopicRef:
66+
def allow(self, perm: TopicPermission, *args: TopicPermission) -> TopicRef:
6767
"""Request the specified permissions to this resource."""
68-
str_args = [str(permission) for permission in args]
68+
str_args = [perm] + [str(permission) for permission in args]
6969
self._register_policy(*str_args)
7070

7171
return Events().topic(self.name)

0 commit comments

Comments
 (0)