Skip to content

Commit

Permalink
fix: Ensure at least one permission when calling allow. (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjholm authored Nov 14, 2023
2 parents f76b971 + aa864de commit 1034b90
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions nitric/resources/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def _perms_to_actions(self, *args: BucketPermission) -> List[int]:
def _to_resource(self) -> Resource:
return Resource(name=self.name, type=ResourceType.Bucket) # type:ignore

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

return Storage().bucket(self.name)
Expand Down
4 changes: 2 additions & 2 deletions nitric/resources/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ def _perms_to_actions(self, *args: CollectionPermission) -> List[int]:

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

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

return Documents().collection(self.name)
Expand Down
4 changes: 2 additions & 2 deletions nitric/resources/queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ async def _register(self) -> None:
except GRPCError as grpc_err:
raise exception_from_grpc_error(grpc_err)

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

return Queues().queue(self.name)
Expand Down
4 changes: 2 additions & 2 deletions nitric/resources/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ def _perms_to_actions(self, *args: SecretPermission) -> List[int]:

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

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

return Secrets().secret(self.name)
Expand Down
4 changes: 2 additions & 2 deletions nitric/resources/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def _perms_to_actions(self, *args: TopicPermission) -> List[int]:

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

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

return Events().topic(self.name)
Expand Down

0 comments on commit 1034b90

Please sign in to comment.