feat: add endpoint access permissions via auth_dependency parameter#38
Merged
Conversation
Reviewer's GuideThe PR introduces an optional auth_dependency parameter to the Radar class, propagates this dependency to both API and dashboard endpoints via FastAPI’s dependencies system, and updates documentation and examples to illustrate usage. Sequence diagram for request authentication with auth_dependencysequenceDiagram
actor User
participant FastAPI
participant Radar
participant "auth_dependency"
User->>FastAPI: Request to /__radar or /__radar/api
FastAPI->>Radar: Route request
Radar->>"auth_dependency": Execute authentication dependency (if set)
"auth_dependency"-->>Radar: Authentication result
Radar->>FastAPI: Serve dashboard/API if authenticated
FastAPI-->>User: Response
Class diagram for updated Radar class with auth_dependencyclassDiagram
class Radar {
+app
+db_engine
+dashboard_path
+exclude_paths
+slow_query_threshold
+theme
+service_name
+include_in_schema
+db_path
+auth_dependency
+query_capture
+__init__(app, db_engine, dashboard_path, exclude_paths, slow_query_threshold, theme, service_name, include_in_schema, db_path, auth_dependency)
+_setup_api(include_in_schema)
+_setup_dashboard(include_in_schema)
}
Radar --> "1" create_api_router : uses
Class diagram for updated create_api_router function with auth_dependencyclassDiagram
class create_api_router {
+get_session_context
+auth_dependency
+returns: APIRouter
}
create_api_router --> APIRouter : returns
File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Add optional auth_dependency parameter to Radar class that allows users to secure the dashboard and API endpoints with any FastAPI dependency function. Changes: - Add auth_dependency parameter to Radar.__init__() - Apply auth dependency to API router via dependencies parameter - Apply auth dependency to dashboard route via dependencies parameter - Add comprehensive documentation with examples (HTTP Basic, Bearer, Custom) - Add commented example in example_app.py showing HTTP Basic auth usage This provides maximum flexibility while maintaining backward compatibility. Users can implement any authentication mechanism (OAuth2, JWT, API keys, etc.) using standard FastAPI dependency patterns. Fixes #27
424ea26 to
c620cd1
Compare
Add three minimal examples demonstrating different auth approaches: - HTTP Basic authentication (example_auth_app.py) - Bearer token authentication (example_bearer_auth.py) - Custom API key authentication (example_custom_auth.py) Each example is self-contained and demonstrates how to use the auth_dependency parameter with different authentication methods.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds optional auth_dependency parameter to the Radar class that allows users to secure the dashboard and API endpoints with any FastAPI dependency function.
Changes
Features
Testing
Closes #27
Summary by Sourcery
Introduce an auth_dependency option to the Radar class to protect both the monitoring API and dashboard via FastAPI dependencies, while preserving existing behavior when no authentication is configured and providing detailed documentation with examples.
New Features:
Enhancements:
Documentation:
Summary by cubic
Add an optional auth_dependency to Radar to secure the dashboard and API endpoints with any FastAPI dependency. Default behavior stays the same when not set.
Written for commit c7297a1. Summary will update automatically on new commits.