22 lines
670 B
Python
22 lines
670 B
Python
import os
|
|
|
|
|
|
def is_production():
|
|
return not os.environ.get('DEV_MODE', '').lower() in ('1', 'true', 'yes')
|
|
|
|
|
|
def is_pro():
|
|
return bool(os.environ.get('LICENSE', '').strip())
|
|
|
|
|
|
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."""
|
|
import base64
|
|
import hashlib
|
|
key_str = os.environ.get('CREDENTIALS_KEY', '')
|
|
if not key_str:
|
|
return None
|
|
raw = hashlib.sha256(key_str.encode()).digest()
|
|
return base64.urlsafe_b64encode(raw)
|