mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-07-27 06:28:50 +00:00
api access
- Create BaseServerMiddleware base class for server middleware - Refactor TracingMiddleware to extend BaseServerMiddleware - Consolidate route matching logic in base class - Update server.py to use user_from_scope utility - Add required_scope parameter to WebMethod in schema_utils.py - Create AccessControlMiddleware with simplified scope checking - Update telemetry API to use required_scope protection - Add comprehensive test coverage for access control logic - Integrate access control middleware into server setup - Rename AccessControlMiddleware to AuthorizationMiddleware for better clarity - Update imports and references in server.py and tests - Keep the same functionality and API - Merge authorization logic directly into AuthenticationMiddleware - Remove separate access_control.py file - Update middleware setup in server.py to use single middleware - Rename and update tests to test the merged functionality - AuthenticationMiddleware now handles both authentication and authorization
This commit is contained in:
parent
632cf9eb72
commit
ebea3c8277
7 changed files with 331 additions and 36 deletions
|
@ -101,3 +101,15 @@ def get_authenticated_user() -> User | None:
|
|||
if not provider_data:
|
||||
return None
|
||||
return provider_data.get("__authenticated_user")
|
||||
|
||||
|
||||
def user_from_scope(scope: dict) -> User | None:
|
||||
"""Create a User object from ASGI scope data (set by authentication middleware)"""
|
||||
user_attributes = scope.get("user_attributes", {})
|
||||
principal = scope.get("principal", "")
|
||||
|
||||
# auth not enabled
|
||||
if not principal and not user_attributes:
|
||||
return None
|
||||
|
||||
return User(principal=principal, attributes=user_attributes)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue