mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-08-07 11:08:20 +00:00
set api_key to be the default namespace if the server returns no attributes
This commit is contained in:
parent
2692d73d7d
commit
6762e3f911
2 changed files with 7 additions and 3 deletions
|
@ -172,8 +172,10 @@ class AuthenticationMiddleware:
|
||||||
if auth_response.access_attributes:
|
if auth_response.access_attributes:
|
||||||
user_attributes = auth_response.access_attributes.model_dump(exclude_none=True)
|
user_attributes = auth_response.access_attributes.model_dump(exclude_none=True)
|
||||||
else:
|
else:
|
||||||
logger.warning("Authentication response did not contain any attributes")
|
logger.warning("No access attributes, setting namespace to api_key by default")
|
||||||
user_attributes = {}
|
user_attributes = {
|
||||||
|
"namespaces": [api_key],
|
||||||
|
}
|
||||||
|
|
||||||
scope["user_attributes"] = user_attributes
|
scope["user_attributes"] = user_attributes
|
||||||
logger.debug(f"Authentication successful: {len(user_attributes)} attributes")
|
logger.debug(f"Authentication successful: {len(user_attributes)} attributes")
|
||||||
|
|
|
@ -201,4 +201,6 @@ async def test_auth_middleware_no_attributes(mock_middleware, mock_scope):
|
||||||
await middleware(mock_scope, mock_receive, mock_send)
|
await middleware(mock_scope, mock_receive, mock_send)
|
||||||
|
|
||||||
assert "user_attributes" in mock_scope
|
assert "user_attributes" in mock_scope
|
||||||
assert mock_scope["user_attributes"] == {}
|
attributes = mock_scope["user_attributes"]
|
||||||
|
assert "namespaces" in attributes
|
||||||
|
assert attributes["namespaces"] == ["test-api-key"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue