Skip to content

Commit 1a44f2e

Browse files
committed
squashme: fixups from rebasing
1 parent b0545e2 commit 1a44f2e

11 files changed

Lines changed: 343 additions & 305 deletions

File tree

components/renku_data_services/authn/dummy.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Optional
88

99
from sanic import Request
10+
from ulid import ULID
1011

1112
import renku_data_services.base_models as base_models
1213

@@ -39,10 +40,22 @@ class DummyAuthenticator:
3940
"""
4041

4142
token_field = "Authorization" # nosec: B105
43+
anon_id_header_key: str = "Renku-Auth-Anon-Id"
44+
anon_id_cookie_name: str = "Renku-Auth-Anon-Id"
4245

43-
@staticmethod
44-
async def authenticate(access_token: str, request: Request) -> base_models.APIUser:
46+
async def authenticate(self, access_token: str, request: Request) -> base_models.APIUser:
4547
"""Indicates whether the user has successfully logged in."""
48+
access_token = request.headers.get(self.token_field) or ""
49+
if not access_token or len(access_token) == 0:
50+
# Try to get an anonymous user ID if the validation of keycloak credentials failed
51+
anon_id = request.headers.get(self.anon_id_header_key)
52+
if anon_id is None:
53+
anon_id = request.cookies.get(self.anon_id_cookie_name)
54+
if anon_id is None:
55+
anon_id = f"anon-{str(ULID())}"
56+
return base_models.AnonymousAPIUser(id=str(anon_id))
57+
58+
access_token = access_token.removeprefix("Bearer ").removeprefix("bearer ")
4659
user_props = {}
4760
with contextlib.suppress(Exception):
4861
user_props = json.loads(access_token)

components/renku_data_services/notebooks/api.spec.yaml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -439,24 +439,27 @@ components:
439439
- registered
440440
type: object
441441
ErrorResponse:
442-
properties:
443-
error:
444-
"$ref": "#/components/schemas/ErrorResponseNested"
445-
required:
446-
- error
447442
type: object
448-
ErrorResponseNested:
449443
properties:
450-
code:
451-
type: integer
452-
detail:
453-
type: string
454-
message:
455-
type: string
444+
error:
445+
type: object
446+
properties:
447+
code:
448+
type: integer
449+
minimum: 0
450+
exclusiveMinimum: true
451+
example: 1404
452+
detail:
453+
type: string
454+
example: "A more detailed optional message showing what the problem was"
455+
message:
456+
type: string
457+
example: "Something went wrong - please try again later"
458+
required:
459+
- "code"
460+
- "message"
456461
required:
457-
- code
458-
- message
459-
type: object
462+
- "error"
460463
Generated:
461464
properties:
462465
enabled:

components/renku_data_services/notebooks/apispec.py

Lines changed: 11 additions & 9 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-19T14:52:52+00:00
3+
# timestamp: 2024-09-23T08:31:51+00:00
44

55
from __future__ import annotations
66

@@ -34,10 +34,16 @@ class DefaultCullingThresholds(BaseAPISpec):
3434
registered: CullingThreshold
3535

3636

37-
class ErrorResponseNested(BaseAPISpec):
38-
code: int
39-
detail: Optional[str] = None
40-
message: str
37+
class Error(BaseAPISpec):
38+
code: int = Field(..., example=1404, gt=0)
39+
detail: Optional[str] = Field(
40+
None, example="A more detailed optional message showing what the problem was"
41+
)
42+
message: str = Field(..., example="Something went wrong - please try again later")
43+
44+
45+
class ErrorResponse(BaseAPISpec):
46+
error: Error
4147

4248

4349
class Generated(BaseAPISpec):
@@ -293,10 +299,6 @@ class SessionsImagesGetParametersQuery(BaseAPISpec):
293299
image_url: str
294300

295301

296-
class ErrorResponse(BaseAPISpec):
297-
error: ErrorResponseNested
298-
299-
300302
class LaunchNotebookRequest(BaseAPISpec):
301303
project_id: str
302304
launcher_id: str

components/renku_data_services/session/db.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from collections.abc import Callable
66
from contextlib import AbstractAsyncContextManager, nullcontext
77
from datetime import UTC, datetime
8-
from pathlib import PurePosixPath
98
from typing import Any
109

1110
from sqlalchemy import select

poetry.lock

Lines changed: 121 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/background_jobs/poetry.lock

Lines changed: 1 addition & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)