Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions hub_adapter/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,45 @@ async def require_researcher_role(
"""Dependency to check if the user has the ADMIN_ROLE or RESEARCHER_ROLE."""
researcher_role = settings.researcher_role
return _require_role(researcher_role, verified_token, settings)


async def require_admin_role(
verified_token: Annotated[dict, Depends(verify_idp_token)],
settings: Annotated[Settings, Depends(get_settings)],
) -> dict:
"""Dependency to check if the user has the ADMIN_ROLE."""
role_claim_name = settings.role_claim_name
admin_role = settings.admin_role

if not role_claim_name:
return verified_token

if not admin_role:
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail={
"message": "Insufficient permissions, admin role not found in token or not configured.",
"service": "Auth",
"status_code": status.HTTP_503_SERVICE_UNAVAILABLE,
},
)

if role_claim_name:
role_claim_keys = role_claim_name.split(".")
parsed_claim = verified_token
for key in role_claim_keys:
parsed_claim = parsed_claim.get(key, {})
if not parsed_claim:
logger.warning(f"No roles found in token using {role_claim_name}")
if isinstance(parsed_claim, str):
parsed_claim = [parsed_claim]
if admin_role not in parsed_claim:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail={
"message": "Insufficient permissions, admin role not found in token.",
"service": "Auth",
"status_code": status.HTTP_403_FORBIDDEN,
},
)
return verified_token
17 changes: 17 additions & 0 deletions hub_adapter/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,23 @@ def __init__(self):
)


def require_victoria_logs(f):
"""Raise HTTP 503 if VictoriaLogs is not configured."""

@functools.wraps(f)
async def inner(*args, **kwargs):
from hub_adapter.dependencies import get_settings # avoid circular import

if not get_settings().victoria_logs_url:
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="Log service is not configured",
)
return await f(*args, **kwargs)

return inner


def catch_hub_errors(f):
"""Custom error handling decorator for flame_hub_client."""

Expand Down
3 changes: 2 additions & 1 deletion hub_adapter/routers/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ async def list_analysis_nodes(
@catch_hub_errors
async def list_specific_analysis_node(
analysis_node_id: Annotated[uuid.UUID | str, Path(description="Analysis Node UUID.")],
query_params: Annotated[dict, Depends(_parse_query_params)],
core_client: Annotated[flame_hub.CoreClient, Depends(get_core_client)],
):
"""List a specific analysis node."""
return core_client.get_analysis_node(analysis_node_id=analysis_node_id)
return core_client.get_analysis_node(analysis_node_id=analysis_node_id, **query_params)


@hub_router.post(
Expand Down
Loading
Loading