49 lines
No EOL
1.4 KiB
Python
49 lines
No EOL
1.4 KiB
Python
import os
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
# Environment Configuration
|
|
DISABLE_MSAL = os.getenv("DISABLE_MSAL", "false").lower() == "true"
|
|
HIDE_LOCAL_LOGIN = os.getenv("HIDE_LOCAL_LOGIN", "false").lower() == "true"
|
|
BASE_PATH = os.getenv("BASE_PATH", "").rstrip("/") # Remove trailing slash
|
|
|
|
def get_base_path() -> str:
|
|
"""Get the base path for URLs"""
|
|
return BASE_PATH
|
|
|
|
def get_full_url(path: str) -> str:
|
|
"""
|
|
DEPRECATED: Use get_app_url() from main.py instead for consistency.
|
|
Get full URL with base path prefix.
|
|
"""
|
|
import warnings
|
|
warnings.warn(
|
|
"get_full_url() is deprecated. Use get_app_url() from main.py instead.",
|
|
DeprecationWarning,
|
|
stacklevel=2
|
|
)
|
|
path = path.lstrip("/") # Remove leading slash
|
|
if BASE_PATH:
|
|
return f"{BASE_PATH}/{path}"
|
|
return f"/{path}" if path else "/"
|
|
|
|
def is_msal_enabled() -> bool:
|
|
"""Check if MSAL authentication is enabled"""
|
|
return not DISABLE_MSAL
|
|
|
|
def show_local_login() -> bool:
|
|
"""Check if local login should be shown (hidden in production)"""
|
|
return not HIDE_LOCAL_LOGIN
|
|
|
|
def get_msal_config():
|
|
"""Get MSAL configuration if enabled"""
|
|
if not is_msal_enabled():
|
|
return None
|
|
|
|
return {
|
|
"client_id": os.getenv("AZURE_CLIENT_ID"),
|
|
"client_secret": os.getenv("AZURE_CLIENT_SECRET"),
|
|
"authority": os.getenv("AZURE_AUTHORITY"),
|
|
"redirect_uri": os.getenv("AZURE_REDIRECT_URI"),
|
|
} |