-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathconfig.py
More file actions
76 lines (60 loc) · 2.74 KB
/
Copy pathconfig.py
File metadata and controls
76 lines (60 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""Handler for REST API call to retrieve service configuration."""
from typing import Annotated, Any
from fastapi import APIRouter, Depends, Request
from lightspeed_stack.authentication import get_auth_dependency
from lightspeed_stack.authentication.interface import AuthTuple
from lightspeed_stack.authorization.middleware import authorize
from lightspeed_stack.configuration import configuration
from lightspeed_stack.log import get_logger
from lightspeed_stack.models.api.responses.constants import (
UNAUTHORIZED_OPENAPI_EXAMPLES,
)
from lightspeed_stack.models.api.responses.error import (
ForbiddenResponse,
InternalServerErrorResponse,
ServiceUnavailableResponse,
UnauthorizedResponse,
)
from lightspeed_stack.models.api.responses.successful import ConfigurationResponse
from lightspeed_stack.models.config import Action
from lightspeed_stack.utils.endpoints import check_configuration_loaded
logger = get_logger(__name__)
router = APIRouter(tags=["config"])
get_config_responses: dict[int | str, dict[str, Any]] = {
200: ConfigurationResponse.openapi_response(),
401: UnauthorizedResponse.openapi_response(examples=UNAUTHORIZED_OPENAPI_EXAMPLES),
403: ForbiddenResponse.openapi_response(examples=["endpoint"]),
500: InternalServerErrorResponse.openapi_response(examples=["configuration"]),
503: ServiceUnavailableResponse.openapi_response(examples=["kubernetes api"]),
}
@router.get("/config", responses=get_config_responses)
@authorize(Action.GET_CONFIG)
async def config_endpoint_handler(
auth: Annotated[AuthTuple, Depends(get_auth_dependency())],
request: Request,
) -> ConfigurationResponse:
"""
Handle requests to the /config endpoint.
Process GET requests to the /config endpoint and returns the
current service configuration.
Ensures the application configuration is loaded before returning it.
### Parameters:
- request: The incoming HTTP request.
- auth: Authentication tuple from the auth dependency.
### Raises:
- HTTPException: with status 401 for unauthorized access.
- HTTPException: with status 403 if permission is denied.
- HTTPException: with status 500 and a detail object containing `response`
and `cause` when service configuration is wrong or incomplete.
- HTTPException: with status 503 and a detail object containing `response`
and `cause` when unable to connect to Llama Stack.
### Returns:
- ConfigurationResponse: The loaded service configuration response.
"""
# Used only for authorization
_ = auth
# Nothing interesting in the request
_ = request
# ensure that configuration is loaded
check_configuration_loaded(configuration)
return ConfigurationResponse(configuration=configuration.configuration)