Development
This commit is contained in:
parent
5b1f905ed0
commit
44261e5b5c
6 changed files with 87 additions and 33 deletions
|
|
@ -1,5 +1,24 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
_APP_CONFIG_PATH = '/data/app_config.json'
|
||||
_app_config_cache = None
|
||||
_app_config_mtime = None
|
||||
|
||||
|
||||
def _load_app_config():
|
||||
global _app_config_cache, _app_config_mtime
|
||||
try:
|
||||
mtime = os.path.getmtime(_APP_CONFIG_PATH)
|
||||
if _app_config_cache is not None and mtime == _app_config_mtime:
|
||||
return _app_config_cache
|
||||
with open(_APP_CONFIG_PATH) as f:
|
||||
_app_config_cache = json.load(f)
|
||||
_app_config_mtime = mtime
|
||||
return _app_config_cache
|
||||
except Exception:
|
||||
return {}
|
||||
|
||||
|
||||
def product_name():
|
||||
return os.environ.get('PRODUCT_NAME', 'routlin')
|
||||
|
|
@ -54,14 +73,34 @@ def get_host_timezone():
|
|||
return ''
|
||||
|
||||
|
||||
def get_initial_manager_email():
|
||||
cfg = _load_app_config()
|
||||
return str(cfg.get('initial_manager_email') or os.environ.get('INITIAL_MANAGER_EMAIL', '')).strip().lower()
|
||||
|
||||
|
||||
def get_credentials_key():
|
||||
"""Return a Fernet-compatible key derived from the CREDENTIALS_KEY environment variable,
|
||||
or None if not set. SHA-256 hashes the raw string to produce 32 bytes, which are then
|
||||
URL-safe base64-encoded as required by Fernet."""
|
||||
"""Return a Fernet-compatible key derived from the credentials_key in app_config.json
|
||||
(or CREDENTIALS_KEY env var as fallback), or None if not set. SHA-256 hashes the raw
|
||||
string to produce 32 bytes, URL-safe base64-encoded as required by Fernet."""
|
||||
import base64
|
||||
import hashlib
|
||||
key_str = os.environ.get('CREDENTIALS_KEY', '')
|
||||
cfg = _load_app_config()
|
||||
key_str = str(cfg.get('credentials_key') or os.environ.get('CREDENTIALS_KEY', '')).strip()
|
||||
if not key_str:
|
||||
return None
|
||||
raw = hashlib.sha256(key_str.encode()).digest()
|
||||
return base64.urlsafe_b64encode(raw)
|
||||
|
||||
|
||||
def get_smtp_config():
|
||||
"""Return SMTP settings from app_config.json, falling back to env vars."""
|
||||
cfg = _load_app_config()
|
||||
smtp = cfg.get('smtp', {})
|
||||
user = str(smtp.get('user') or os.environ.get('SMTP_USER', '')).strip()
|
||||
return {
|
||||
'host': str(smtp.get('host') or os.environ.get('SMTP_HOST', '')).strip(),
|
||||
'port': int(smtp.get('port') or os.environ.get('SMTP_PORT', 587)),
|
||||
'user': user,
|
||||
'password': str(smtp.get('password') or os.environ.get('SMTP_PASSWORD', '')).strip(),
|
||||
'from': str(smtp.get('from') or os.environ.get('SMTP_FROM', user)).strip(),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue