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

fix: Ensure at least one permission when calling allow. #126

Merged
merged 1 commit into from
Nov 14, 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
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
Loading