mirror of
https://github.com/Viren070/mediaflow-proxy.git
synced 2025-12-01 23:22:12 +01:00
Make API_PASSWORD optional for app that uses mediaflow as lib package
Updated `api_password` to be optional in configurations and logic, allowing API access to function without it if not set. Adjusted related checks and encryption handling to accommodate this change while maintaining security features when a password is provided. Updated README to reflect the change.
This commit is contained in:
@@ -43,7 +43,7 @@ MediaFlow Proxy is a powerful and flexible solution for proxifying various types
|
||||
|
||||
Set the following environment variables:
|
||||
|
||||
- `API_PASSWORD`: Required. Protects against unauthorized access and API network abuses.
|
||||
- `API_PASSWORD`: Optional. Protects against unauthorized access and API network abuses.
|
||||
- `ENABLE_STREAMING_PROGRESS`: Optional. Enable streaming progress logging. Default is `false`.
|
||||
|
||||
### Transport Configuration
|
||||
|
||||
@@ -51,7 +51,7 @@ class TransportConfig(BaseSettings):
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
api_password: str # The password for accessing the API endpoints.
|
||||
api_password: str | None = None # The password for protecting the API endpoints.
|
||||
log_level: str = "INFO" # The logging level to use.
|
||||
transport_config: TransportConfig = Field(default_factory=TransportConfig) # Configuration for httpx transport.
|
||||
enable_streaming_progress: bool = False # Whether to enable streaming progress tracking.
|
||||
|
||||
@@ -38,6 +38,9 @@ async def verify_api_key(api_key: str = Security(api_password_query), api_key_al
|
||||
Raises:
|
||||
HTTPException: If the API key is invalid.
|
||||
"""
|
||||
if not settings.api_password:
|
||||
return
|
||||
|
||||
if api_key == settings.api_password or api_key_alt == settings.api_password:
|
||||
return
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class EncryptionMiddleware(BaseHTTPMiddleware):
|
||||
|
||||
async def dispatch(self, request: Request, call_next):
|
||||
encrypted_token = request.query_params.get("token")
|
||||
if encrypted_token:
|
||||
if encrypted_token and self.encryption_handler:
|
||||
try:
|
||||
client_ip = self.get_client_ip(request)
|
||||
decrypted_data = self.encryption_handler.decrypt_data(encrypted_token, client_ip)
|
||||
@@ -107,4 +107,4 @@ class EncryptionMiddleware(BaseHTTPMiddleware):
|
||||
return request.client.host if request.client else "127.0.0.1"
|
||||
|
||||
|
||||
encryption_handler = EncryptionHandler(settings.api_password)
|
||||
encryption_handler = EncryptionHandler(settings.api_password) if settings.api_password else None
|
||||
|
||||
Reference in New Issue
Block a user