36 lines
875 B
Python
36 lines
875 B
Python
#!/usr/bin/env python3
|
|
"""Deploy-time master password (emergency fallback for web + Qt).
|
|
|
|
Read order:
|
|
1. BUTTONTASK_MASTER_PASSWORD environment variable
|
|
2. <config>/.master file (created once at deploy via bt-set-master)
|
|
|
|
The file is not part of OTA packages and is not committed to git.
|
|
"""
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from config_store import config_path
|
|
|
|
MASTER_FILENAME = ".master"
|
|
|
|
|
|
def master_password_path():
|
|
env = os.environ.get("BUTTONTASK_MASTER_FILE")
|
|
if env:
|
|
return Path(env)
|
|
return config_path().parent / MASTER_FILENAME
|
|
|
|
|
|
def load_master_password():
|
|
env = (os.environ.get("BUTTONTASK_MASTER_PASSWORD") or "").strip()
|
|
if env:
|
|
return env
|
|
path = master_password_path()
|
|
try:
|
|
if path.is_file():
|
|
return path.read_text(encoding="utf-8").strip()
|
|
except OSError:
|
|
pass
|
|
return ""
|