Skip to content

Commit ff940a9

Browse files
author
Andrej Simurka
committed
Reflected coderabbit suggestions
1 parent b42eb24 commit ff940a9

File tree

15 files changed

+34
-21
lines changed

15 files changed

+34
-21
lines changed

docs/openapi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,7 @@
20132013
"value": {
20142014
"detail": {
20152015
"cause": "Storing feedback is disabled.",
2016-
"response": "Storing feedback is disabled."
2016+
"response": "Storing feedback is disabled"
20172017
}
20182018
}
20192019
}
@@ -5674,7 +5674,7 @@
56745674
{
56755675
"detail": {
56765676
"cause": "Storing feedback is disabled.",
5677-
"response": "Storing feedback is disabled."
5677+
"response": "Storing feedback is disabled"
56785678
},
56795679
"label": "feedback"
56805680
},

src/authentication/k8s.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@ async def __call__(self, request: Request) -> tuple[str, str, bool, str]:
271271
)
272272
response = authorization_api.create_subject_access_review(sar)
273273

274-
if not response.status.allowed:
275-
response = ForbiddenResponse.endpoint(user_id=user_info.user.uid)
276-
raise HTTPException(**response.model_dump())
277274
except Exception as e:
278275
logger.error("API exception during SubjectAccessReview: %s", e)
279276
response = ServiceUnavailableResponse(
@@ -282,6 +279,10 @@ async def __call__(self, request: Request) -> tuple[str, str, bool, str]:
282279
)
283280
raise HTTPException(**response.model_dump()) from e
284281

282+
if not response.status.allowed:
283+
response = ForbiddenResponse.endpoint(user_id=user_info.user.uid)
284+
raise HTTPException(**response.model_dump())
285+
285286
return (
286287
user_info.user.uid,
287288
user_info.user.username,

src/authentication/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66

77

88
def extract_user_token(headers: Headers) -> str:
9-
"""Extract the bearer token from an HTTP authorization header.
9+
"""Extract the bearer token from an HTTP Authorization header.
1010
1111
Args:
12-
header: The authorization header containing the token.
12+
headers: The request headers containing the Authorization value.
13+
1314
Returns:
14-
The extracted token if present, else an empty string.
15+
The extracted bearer token.
16+
17+
Raises:
18+
HTTPException: If the Authorization header is missing or malformed.
1519
"""
1620
authorization_header = headers.get("Authorization")
1721
if not authorization_header:

src/authorization/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ async def _perform_authorization_check(
9090
user_roles = await role_resolver.resolve_roles(auth) | everyone_roles
9191

9292
if not access_resolver.check_access(action, user_roles):
93-
response = ForbiddenResponse.endpoint(user_id=auth[1])
93+
response = ForbiddenResponse.endpoint(user_id=auth[0])
9494
raise HTTPException(**response.model_dump())
9595

9696
authorized_actions = access_resolver.get_actions(user_roles)

src/metrics/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from llama_stack.models.llama.datatypes import RawMessage
77
from llama_stack.models.llama.llama3.chat_format import ChatFormat
88
from llama_stack.models.llama.llama3.tokenizer import Tokenizer
9-
from llama_stack_client import APIConnectionError
9+
from llama_stack_client import APIConnectionError, APIStatusError
1010
from llama_stack_client.types.agents.turn import Turn
1111

1212
import metrics
@@ -27,7 +27,7 @@ async def setup_model_metrics() -> None:
2727
check_configuration_loaded(configuration)
2828
try:
2929
model_list = await AsyncLlamaStackClientHolder().get_client().models.list()
30-
except APIConnectionError as e:
30+
except (APIConnectionError, APIStatusError) as e:
3131
response = ServiceUnavailableResponse(backend_name="Llama Stack", cause=str(e))
3232
raise HTTPException(**response.model_dump()) from e
3333

src/models/responses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ class ForbiddenResponse(AbstractErrorResponse):
12871287
{
12881288
"label": "feedback",
12891289
"detail": {
1290-
"response": "Storing feedback is disabled.",
1290+
"response": "Storing feedback is disabled",
12911291
"cause": "Storing feedback is disabled.",
12921292
},
12931293
},
@@ -1332,7 +1332,7 @@ def endpoint(cls, user_id: str) -> "ForbiddenResponse":
13321332
def feedback_disabled(cls) -> "ForbiddenResponse":
13331333
"""Create a ForbiddenResponse for disabled feedback."""
13341334
return cls(
1335-
response="Feedback is disabled",
1335+
response="Storing feedback is disabled",
13361336
cause="Storing feedback is disabled.",
13371337
)
13381338

tests/e2e/features/feedback.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Feature: feedback endpoint API tests
109109
"""
110110
{
111111
"detail": {
112-
"response": "Feedback is disabled",
112+
"response": "Storing feedback is disabled",
113113
"cause": "Storing feedback is disabled."
114114
}
115115
}

tests/unit/app/endpoints/test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ async def test_config_endpoint_handler_configuration_not_loaded(
1818
mock_authorization_resolvers(mocker)
1919

2020
mock_config = AppConfig()
21+
mock_config._configuration = None # pylint: disable=protected-access
2122
mocker.patch("app.endpoints.config.configuration", mock_config)
2223

2324
# HTTP request mock required by URL endpoint handler

tests/unit/app/endpoints/test_feedback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def test_assert_feedback_enabled_disabled(mocker: MockerFixture) -> None:
6262
await assert_feedback_enabled(mocker.Mock())
6363

6464
assert exc_info.value.status_code == status.HTTP_403_FORBIDDEN
65-
assert exc_info.value.detail["response"] == "Feedback is disabled" # type: ignore
65+
assert exc_info.value.detail["response"] == "Storing feedback is disabled" # type: ignore
6666
assert exc_info.value.detail["cause"] == "Storing feedback is disabled." # type: ignore
6767

6868

tests/unit/app/endpoints/test_providers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def test_providers_endpoint_configuration_not_loaded(
3939
async def test_providers_endpoint_connection_error(
4040
mocker: MockerFixture, minimal_config: AppConfig
4141
) -> None:
42-
"""Test that /providers endpoint raises HTTP 500 if Llama Stack connection fails."""
42+
"""Test that /providers endpoint raises HTTP 503 if Llama Stack connection fails."""
4343
mocker.patch("app.endpoints.providers.configuration", minimal_config)
4444

4545
mocker.patch(

0 commit comments

Comments
 (0)