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:
mhdzumair
2024-12-11 15:15:35 +05:30
parent 2af0ac42f2
commit 779e01a57f
4 changed files with 7 additions and 4 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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.
+3
View File
@@ -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
+2 -2
View File
@@ -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