Skip to content

Commit b4c017b

Browse files
authored
Merge pull request road-core#298 from tisnik/user-is-as-optional-api-parameter
User ID as optional REST API parameter
2 parents 62af894 + e492a85 commit b4c017b

File tree

5 files changed

+86
-11
lines changed

5 files changed

+86
-11
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,10 @@ Depends on configuration, but usually it is not needed to generate or use API ke
377377
module: "noop"
378378
```
379379

380-
In this case it is possible to pass `user-id` optional when calling REST API query endpoints. If the `user-id` won't be passed, the default one will be used: `00000000-0000-0000-0000-000000000000`
380+
In this case it is possible to pass `user-id` optional parameter when calling REST API query endpoints. If the `user-id` won't be passed, the default one will be used: `00000000-0000-0000-0000-000000000000`
381+
382+
[!NOTE]
383+
The value of `user-id` parameter is not checked. This means it is possible to pass non-UUID value, which might not be appropriate for some use cases.
381384

382385
## 4. Configure RCS TLS communication
383386

docs/openapi.json

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,35 @@
1212
"query"
1313
],
1414
"summary": "Conversation Request",
15-
"description": "Handle conversation requests for the OLS endpoint.\n\nArgs:\n llm_request: The request containing a query, conversation ID, and optional attachments.\n auth: The Authentication handler (FastAPI Depends) that will handle authentication Logic.\n\nReturns:\n Response containing the processed information.",
15+
"description": "Handle conversation requests for the OLS endpoint.\n\nArgs:\n llm_request: The request containing a query, conversation ID, and optional attachments.\n auth: The Authentication handler (FastAPI Depends) that will handle authentication Logic.\n user_id: Optional user ID used only when no-op auth is enabled.\n\nReturns:\n Response containing the processed information.",
1616
"operationId": "conversation_request_v1_query_post",
17+
"parameters": [
18+
{
19+
"name": "user_id",
20+
"in": "query",
21+
"required": false,
22+
"schema": {
23+
"anyOf": [
24+
{
25+
"type": "string"
26+
},
27+
{
28+
"type": "null"
29+
}
30+
],
31+
"title": "User Id"
32+
}
33+
}
34+
],
1735
"requestBody": {
36+
"required": true,
1837
"content": {
1938
"application/json": {
2039
"schema": {
2140
"$ref": "#/components/schemas/LLMRequest"
2241
}
2342
}
24-
},
25-
"required": true
43+
}
2644
},
2745
"responses": {
2846
"200": {
@@ -94,17 +112,35 @@
94112
"streaming_query"
95113
],
96114
"summary": "Conversation Request",
97-
"description": "Handle conversation requests for the OLS endpoint.\n\nArgs:\n llm_request: The incoming request containing query details.\n auth: The authentication context, provided by dependency injection.\n\nReturns:\n StreamingResponse: The streaming response generated for the query.",
115+
"description": "Handle conversation requests for the OLS endpoint.\n\nArgs:\n llm_request: The incoming request containing query details.\n auth: The authentication context, provided by dependency injection.\n user_id: Optional user ID used only when no-op auth is enabled.\n\nReturns:\n StreamingResponse: The streaming response generated for the query.",
98116
"operationId": "conversation_request_v1_streaming_query_post",
117+
"parameters": [
118+
{
119+
"name": "user_id",
120+
"in": "query",
121+
"required": false,
122+
"schema": {
123+
"anyOf": [
124+
{
125+
"type": "string"
126+
},
127+
{
128+
"type": "null"
129+
}
130+
],
131+
"title": "User Id"
132+
}
133+
}
134+
],
99135
"requestBody": {
136+
"required": true,
100137
"content": {
101138
"application/json": {
102139
"schema": {
103140
"$ref": "#/components/schemas/LLMRequest"
104141
}
105142
}
106-
},
107-
"required": true
143+
}
108144
},
109145
"responses": {
110146
"200": {
@@ -349,6 +385,24 @@
349385
"summary": "Is User Authorized",
350386
"description": "Validate if the logged-in user is authorized to access OLS.\n\nParameters:\n request (Request): The FastAPI request object.\n\nReturns:\n The user's UID and username if authentication and authorization succeed.\n\nRaises:\n HTTPException: If authentication fails or the user does not have access.",
351387
"operationId": "is_user_authorized_authorized_post",
388+
"parameters": [
389+
{
390+
"name": "user_id",
391+
"in": "query",
392+
"required": false,
393+
"schema": {
394+
"anyOf": [
395+
{
396+
"type": "string"
397+
},
398+
{
399+
"type": "null"
400+
}
401+
],
402+
"title": "User Id"
403+
}
404+
}
405+
],
352406
"responses": {
353407
"200": {
354408
"description": "The user is logged-in and authorized to access OLS",
@@ -389,6 +443,16 @@
389443
}
390444
}
391445
}
446+
},
447+
"422": {
448+
"description": "Validation Error",
449+
"content": {
450+
"application/json": {
451+
"schema": {
452+
"$ref": "#/components/schemas/HTTPValidationError"
453+
}
454+
}
455+
}
392456
}
393457
}
394458
}

ols/app/endpoints/authorized.py

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

33
import asyncio
44
import logging
5-
from typing import Any
5+
from typing import Any, Optional
66

77
from fastapi import APIRouter, Request
88

@@ -40,7 +40,9 @@
4040

4141

4242
@router.post("/authorized", responses=authorized_responses)
43-
def is_user_authorized(request: Request) -> AuthorizationResponse:
43+
def is_user_authorized(
44+
request: Request, user_id: Optional[str] = None
45+
) -> AuthorizationResponse:
4446
"""Validate if the logged-in user is authorized to access OLS.
4547
4648
Parameters:

ols/app/endpoints/ols.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,16 @@
6868

6969
@router.post("/query", responses=query_responses)
7070
def conversation_request(
71-
llm_request: LLMRequest, auth: Any = Depends(auth_dependency)
71+
llm_request: LLMRequest,
72+
auth: Any = Depends(auth_dependency),
73+
user_id: Optional[str] = None,
7274
) -> LLMResponse:
7375
"""Handle conversation requests for the OLS endpoint.
7476
7577
Args:
7678
llm_request: The request containing a query, conversation ID, and optional attachments.
7779
auth: The Authentication handler (FastAPI Depends) that will handle authentication Logic.
80+
user_id: Optional user ID used only when no-op auth is enabled.
7881
7982
Returns:
8083
Response containing the processed information.

ols/app/endpoints/streaming_ols.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@
7070

7171
@router.post("/streaming_query", responses=query_responses)
7272
def conversation_request(
73-
llm_request: LLMRequest, auth: Any = Depends(auth_dependency)
73+
llm_request: LLMRequest,
74+
auth: Any = Depends(auth_dependency),
75+
user_id: Optional[str] = None,
7476
) -> StreamingResponse:
7577
"""Handle conversation requests for the OLS endpoint.
7678
7779
Args:
7880
llm_request: The incoming request containing query details.
7981
auth: The authentication context, provided by dependency injection.
82+
user_id: Optional user ID used only when no-op auth is enabled.
8083
8184
Returns:
8285
StreamingResponse: The streaming response generated for the query.

0 commit comments

Comments
 (0)