Skip to content

Commit 1ec88cd

Browse files
committed
LCORE-2120: Refactoring - use AuthTuple where appropriate
1 parent c91efce commit 1ec88cd

5 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/authentication/api_key_token.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from fastapi import HTTPException, Request, status
1212

13-
from authentication.interface import AuthInterface
13+
from authentication.interface import AuthInterface, AuthTuple
1414
from authentication.utils import extract_user_token
1515
from constants import (
1616
DEFAULT_USER_NAME,
@@ -45,7 +45,7 @@ def __init__(
4545
self.config: APIKeyTokenConfiguration = config
4646
self.skip_userid_check = True
4747

48-
async def __call__(self, request: Request) -> tuple[str, str, bool, str]:
48+
async def __call__(self, request: Request) -> AuthTuple:
4949
"""Validate FastAPI Requests for authentication and authorization.
5050
5151
Args:

src/authentication/k8s.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from kubernetes.client.rest import ApiException
1010
from kubernetes.config import ConfigException
1111

12-
from authentication.interface import NO_AUTH_TUPLE, AuthInterface
12+
from authentication.interface import NO_AUTH_TUPLE, AuthInterface, AuthTuple
1313
from authentication.utils import extract_user_token
1414
from configuration import configuration
1515
from constants import DEFAULT_VIRTUAL_PATH
@@ -418,7 +418,7 @@ def __init__(self, virtual_path: str = DEFAULT_VIRTUAL_PATH) -> None:
418418
self.virtual_path = virtual_path
419419
self.skip_userid_check = False
420420

421-
async def __call__(self, request: Request) -> tuple[str, str, bool, str]:
421+
async def __call__(self, request: Request) -> AuthTuple:
422422
"""Validate FastAPI Requests for authentication and authorization.
423423
424424
Parameters:

src/authentication/noop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from fastapi import HTTPException, Request
44

5-
from authentication.interface import AuthInterface
5+
from authentication.interface import AuthInterface, AuthTuple
66
from constants import (
77
DEFAULT_USER_NAME,
88
DEFAULT_USER_UID,
@@ -31,7 +31,7 @@ def __init__(self, virtual_path: str = DEFAULT_VIRTUAL_PATH) -> None:
3131
self.virtual_path = virtual_path
3232
self.skip_userid_check = True
3333

34-
async def __call__(self, request: Request) -> tuple[str, str, bool, str]:
34+
async def __call__(self, request: Request) -> AuthTuple:
3535
"""Validate FastAPI Requests for authentication and authorization.
3636
3737
Parameters:
@@ -40,7 +40,7 @@ async def __call__(self, request: Request) -> tuple[str, str, bool, str]:
4040
4141
Returns:
4242
-------
43-
tuple[str, str, bool, str]: A 4-tuple containing:
43+
AuthTuple: A 4-tuple containing:
4444
- user_id: the value of the "user_id" query parameter if
4545
present, otherwise DEFAULT_USER_UID.
4646
- username: DEFAULT_USER_NAME.

src/authentication/noop_with_token.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from fastapi import HTTPException, Request
1313

14-
from authentication.interface import AuthInterface
14+
from authentication.interface import AuthInterface, AuthTuple
1515
from authentication.utils import extract_user_token
1616
from constants import (
1717
DEFAULT_USER_NAME,
@@ -43,7 +43,7 @@ def __init__(self, virtual_path: str = DEFAULT_VIRTUAL_PATH) -> None:
4343
self.virtual_path = virtual_path
4444
self.skip_userid_check = True
4545

46-
async def __call__(self, request: Request) -> tuple[str, str, bool, str]:
46+
async def __call__(self, request: Request) -> AuthTuple:
4747
"""Validate FastAPI Requests for authentication and authorization.
4848
4949
Parameters:
@@ -52,7 +52,7 @@ async def __call__(self, request: Request) -> tuple[str, str, bool, str]:
5252
5353
Returns:
5454
-------
55-
tuple[str, str, bool, str]: A 4-tuple containing:
55+
AuthTuple: A 4-tuple containing:
5656
- user_id: The value of the "user_id" query parameter or
5757
DEFAULT_USER_UID if absent.
5858
- username: DEFAULT_USER_NAME.

tests/unit/app/endpoints/test_responses.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
handle_streaming_response,
2525
responses_endpoint_handler,
2626
)
27+
from authentication.interface import AuthTuple
2728
from configuration import AppConfig
2829
from constants import DEFAULT_SYSTEM_PROMPT, SUBSTITUTED_INSTRUCTIONS_PLACEHOLDER
2930
from models.api.responses.successful import ResponsesResponse
@@ -57,7 +58,7 @@ def build_api_params_and_context( # pylint: disable=too-many-arguments
5758
*,
5859
updated_request: ResponsesRequest,
5960
client: Any,
60-
auth: tuple[str, str, bool, str],
61+
auth: AuthTuple,
6162
input_text: str,
6263
started_at: datetime,
6364
moderation_result: Any,

0 commit comments

Comments
 (0)