Skip to content

Commit 1537547

Browse files
committed
squashme: address comments
1 parent 8acb720 commit 1537547

4 files changed

Lines changed: 19 additions & 15 deletions

File tree

components/renku_data_services/notebooks/api.spec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ paths:
1919
required: true
2020
schema:
2121
type: string
22+
minLength: 1
2223
responses:
2324
'200':
2425
description: The Docker image is available.
@@ -384,6 +385,7 @@ paths:
384385
required: true
385386
schema:
386387
type: string
388+
minLength: 1
387389
responses:
388390
"200":
389391
description: The docker image can be found

components/renku_data_services/notebooks/api/classes/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ImageRepoDockerAPI:
3030
hostname: str
3131
oauth2_token: Optional[str] = field(default=None, repr=False)
3232
# NOTE: We need to follow redirects so that we can authenticate with the image repositories properly.
33-
# NOTE: If we do not use default_factory to create the client here requests will fail beause it can happen
33+
# NOTE: If we do not use default_factory to create the client here requests will fail because it can happen
3434
# that the client gets created in the wrong asyncio loop.
3535
client: httpx.AsyncClient = field(default_factory=lambda: httpx.AsyncClient(timeout=10, follow_redirects=True))
3636

@@ -65,7 +65,7 @@ async def get_image_manifest(self, image: "Image") -> Optional[dict[str, Any]]:
6565
"""Query the docker API to get the manifest of an image."""
6666
if image.hostname != self.hostname:
6767
raise errors.ValidationError(
68-
message=f"The image hostname {image.hostname} does not match " f"the image repository {self.hostname}"
68+
message=f"The image hostname {image.hostname} does not match the image repository {self.hostname}"
6969
)
7070
token = await self._get_docker_token(image)
7171
image_digest_url = f"https://{image.hostname}/v2/{image.name}/manifests/{image.tag}"

components/renku_data_services/notebooks/apispec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generated by datamodel-codegen:
22
# filename: api.spec.yaml
3-
# timestamp: 2024-09-24T09:26:37+00:00
3+
# timestamp: 2024-10-07T22:25:48+00:00
44

55
from __future__ import annotations
66

@@ -273,7 +273,7 @@ class SessionCloudStoragePost(BaseAPISpec):
273273

274274

275275
class NotebooksImagesGetParametersQuery(BaseAPISpec):
276-
image_url: str
276+
image_url: str = Field(..., min_length=1)
277277

278278

279279
class NotebooksLogsServerNameGetParametersQuery(BaseAPISpec):
@@ -296,7 +296,7 @@ class SessionsSessionIdLogsGetParametersQuery(BaseAPISpec):
296296

297297

298298
class SessionsImagesGetParametersQuery(BaseAPISpec):
299-
image_url: str
299+
image_url: str = Field(..., min_length=1)
300300

301301

302302
class LaunchNotebookRequest(BaseAPISpec):

components/renku_data_services/notebooks/blueprints.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -757,13 +757,14 @@ def check_docker_image(self) -> BlueprintFactoryResponse:
757757
"""Return the availability of the docker image."""
758758

759759
@authenticate_2(self.authenticator, self.internal_gitlab_authenticator)
760+
@validate(query=apispec.NotebooksImagesGetParametersQuery)
760761
async def _check_docker_image(
761-
request: Request, user: AnonymousAPIUser | AuthenticatedAPIUser, internal_gitlab_user: APIUser
762+
request: Request,
763+
user: AnonymousAPIUser | AuthenticatedAPIUser,
764+
internal_gitlab_user: APIUser,
765+
query: apispec.NotebooksImagesGetParametersQuery,
762766
) -> HTTPResponse:
763-
image_url = request.get_args().get("image_url")
764-
if not isinstance(image_url, str):
765-
raise ValueError("required string of image url")
766-
parsed_image = Image.from_path(image_url)
767+
parsed_image = Image.from_path(query.image_url)
767768
image_repo = parsed_image.repo_api()
768769
if parsed_image.hostname == self.nb_config.git.registry and internal_gitlab_user.access_token:
769770
image_repo = image_repo.with_oauth2_token(internal_gitlab_user.access_token)
@@ -1130,13 +1131,14 @@ def check_docker_image(self) -> BlueprintFactoryResponse:
11301131
"""Return the availability of the docker image."""
11311132

11321133
@authenticate_2(self.authenticator, self.internal_gitlab_authenticator)
1134+
@validate(query=apispec.SessionsImagesGetParametersQuery)
11331135
async def _check_docker_image(
1134-
request: Request, user: AnonymousAPIUser | AuthenticatedAPIUser, internal_gitlab_user: APIUser
1136+
request: Request,
1137+
user: AnonymousAPIUser | AuthenticatedAPIUser,
1138+
internal_gitlab_user: APIUser,
1139+
query: apispec.SessionsImagesGetParametersQuery,
11351140
) -> HTTPResponse:
1136-
image_url = request.get_args().get("image_url")
1137-
if not isinstance(image_url, str):
1138-
raise ValueError("required string of image url")
1139-
parsed_image = Image.from_path(image_url)
1141+
parsed_image = Image.from_path(query.image_url)
11401142
image_repo = parsed_image.repo_api()
11411143
if parsed_image.hostname == self.nb_config.git.registry and internal_gitlab_user.access_token:
11421144
image_repo = image_repo.with_oauth2_token(internal_gitlab_user.access_token)

0 commit comments

Comments
 (0)