-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathconfig.py
More file actions
87 lines (73 loc) · 2.56 KB
/
config.py
File metadata and controls
87 lines (73 loc) · 2.56 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
77
78
79
80
81
82
83
84
85
86
87
"""Handler for REST API call to retrieve service configuration."""
import logging
from typing import Annotated, Any
from fastapi import APIRouter, Request, Depends
from authentication.interface import AuthTuple
from authentication import get_auth_dependency
from authorization.middleware import authorize
from configuration import configuration
from models.config import Action, Configuration
from utils.endpoints import check_configuration_loaded
logger = logging.getLogger(__name__)
router = APIRouter(tags=["config"])
auth_dependency = get_auth_dependency()
get_config_responses: dict[int | str, dict[str, Any]] = {
200: {
"name": "foo bar baz",
"service": {
"host": "localhost",
"port": 8080,
"auth_enabled": False,
"workers": 1,
"color_log": True,
"access_log": True,
"tls_config": {
"tls_certificate_path": "config/certificate.crt",
"tls_key_path": "config/private.key",
"tls_key_password": None,
},
},
"llama_stack": {
"url": "http://localhost:8321",
"api_key": "*****",
"use_as_library_client": False,
"library_client_config_path": None,
},
"user_data_collection": {
"feedback_enabled": True,
"feedback_storage": "/tmp/data/feedback",
"transcripts_enabled": False,
"transcripts_storage": None,
},
"mcp_servers": [
{"name": "server1", "provider_id": "provider1", "url": "http://url.com:1"},
{"name": "server2", "provider_id": "provider2", "url": "http://url.com:2"},
{"name": "server3", "provider_id": "provider3", "url": "http://url.com:3"},
],
},
503: {
"detail": {
"response": "Configuration is not loaded",
}
},
}
@router.get("/config", responses=get_config_responses)
@authorize(Action.GET_CONFIG)
async def config_endpoint_handler(
auth: Annotated[AuthTuple, Depends(auth_dependency)],
request: Request,
) -> Configuration:
"""
Handle requests to the /config endpoint.
Process GET requests to the /config endpoint and returns the
current service configuration.
Returns:
Configuration: The loaded service configuration object.
"""
# Used only for authorization
_ = auth
# Nothing interesting in the request
_ = request
# ensure that configuration is loaded
check_configuration_loaded(configuration)
return configuration.configuration