Skip to content

Commit

Permalink
squashme: remove validate path project ID
Browse files Browse the repository at this point in the history
  • Loading branch information
olevski committed Oct 23, 2024
1 parent aae3f82 commit 3085cbb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 34 deletions.
24 changes: 0 additions & 24 deletions components/renku_data_services/base_api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,30 +71,6 @@ async def decorated_function(request: Request, *args: _P.args, **kwargs: _P.kwar
return decorator


def validate_path_project_id(
f: Callable[Concatenate[Request, _P], Coroutine[Any, Any, _T]],
) -> Callable[Concatenate[Request, _P], Coroutine[Any, Any, _T]]:
"""Decorator for a Sanic handler that validates the project_id path parameter."""
_path_project_id_regex = re.compile(r"^[A-Za-z0-9]{26}$")

@wraps(f)
async def decorated_function(request: Request, *args: _P.args, **kwargs: _P.kwargs) -> _T:
project_id = cast(str | None, kwargs.get("project_id"))
if not project_id:
raise errors.ProgrammingError(
message="Could not find 'project_id' in the keyword arguments for the handler in order to validate it."
)
if not _path_project_id_regex.match(project_id):
raise errors.ValidationError(
message=f"The 'project_id' path parameter {project_id} does not match the required "
f"regex {_path_project_id_regex}"
)

return await f(request, *args, **kwargs)

return decorated_function


def validate_path_user_id(
f: Callable[Concatenate[Request, _P], Coroutine[Any, Any, _T]],
) -> Callable[Concatenate[Request, _P], Coroutine[Any, Any, _T]]:
Expand Down
15 changes: 5 additions & 10 deletions components/renku_data_services/project/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from renku_data_services.base_api.auth import (
authenticate,
only_authenticated,
validate_path_project_id,
validate_path_user_id,
)
from renku_data_services.base_api.blueprint import BlueprintFactoryResponse, CustomBlueprint
Expand Down Expand Up @@ -80,12 +79,11 @@ def get_one(self) -> BlueprintFactoryResponse:
"""Get a specific project."""

@authenticate(self.authenticator)
@validate_path_project_id
@extract_if_none_match
async def _get_one(
_: Request, user: base_models.APIUser, project_id: str, etag: str | None
_: Request, user: base_models.APIUser, project_id: ULID, etag: str | None
) -> JSONResponse | HTTPResponse:
project = await self.project_repo.get_project(user=user, project_id=ULID.from_str(project_id))
project = await self.project_repo.get_project(user=user, project_id=project_id)

if project.etag is not None and project.etag == etag:
return HTTPResponse(status=304)
Expand Down Expand Up @@ -210,14 +208,11 @@ def get_permissions(self) -> BlueprintFactoryResponse:
"""Get the permissions of the current user on the project."""

@authenticate(self.authenticator)
@validate_path_project_id
async def _get_permissions(_: Request, user: base_models.APIUser, project_id: str) -> JSONResponse:
permissions = await self.project_repo.get_project_permissions(
user=user, project_id=ULID.from_str(project_id)
)
async def _get_permissions(_: Request, user: base_models.APIUser, project_id: ULID) -> JSONResponse:
permissions = await self.project_repo.get_project_permissions(user=user, project_id=project_id)
return validated_json(apispec.ProjectPermissions, permissions)

return "/projects/<project_id>/permissions", ["GET"], _get_permissions
return "/projects/<project_id:ulid>/permissions", ["GET"], _get_permissions

@staticmethod
def _dump_project(project: project_models.Project) -> dict[str, Any]:
Expand Down

0 comments on commit 3085cbb

Please sign in to comment.