Development
This commit is contained in:
parent
f5722f3c7b
commit
d60bf15ce4
15 changed files with 367 additions and 285 deletions
|
|
@ -33,7 +33,8 @@ from session_interface import SqliteSessionInterface
|
|||
|
||||
app = Flask(__name__)
|
||||
app.secret_key = os.environ.get('SECRET_KEY', os.urandom(24))
|
||||
app.session_interface = SqliteSessionInterface(config_utils.SESSIONS_DB)
|
||||
app.session_interface = SqliteSessionInterface(config_utils.ACCOUNTS_DB)
|
||||
config_utils.init_accounts_db()
|
||||
|
||||
# Static www/ serving =================================================
|
||||
|
||||
|
|
@ -151,33 +152,26 @@ app.register_blueprint(api_apply_health_bp)
|
|||
|
||||
|
||||
def _seed_initial_account():
|
||||
import uuid as _uuid, time as _t
|
||||
email = os.environ.get('INITIAL_MANAGER_EMAIL', '').strip().lower()
|
||||
if not email:
|
||||
try:
|
||||
with open(config_utils.ACCOUNTS_FILE) as f:
|
||||
data = json.load(f)
|
||||
except Exception:
|
||||
data = {'accounts': []}
|
||||
if not data.get('accounts'):
|
||||
if not config_utils.list_accounts():
|
||||
print('[main] WARNING: No accounts exist and INITIAL_MANAGER_EMAIL is not set. '
|
||||
'Set it in docker-compose.yml to seed the initial manager account.', file=sys.stderr)
|
||||
return
|
||||
try:
|
||||
with open(config_utils.ACCOUNTS_FILE) as f:
|
||||
data = json.load(f)
|
||||
except Exception:
|
||||
data = {'accounts': []}
|
||||
if data.get('accounts'):
|
||||
if config_utils.list_accounts():
|
||||
return
|
||||
data['accounts'] = [{
|
||||
'email_address': email,
|
||||
'access_level': 'manager',
|
||||
'hashed_password': '',
|
||||
'timezone': '',
|
||||
}]
|
||||
with open(config_utils.ACCOUNTS_FILE, 'w') as f:
|
||||
json.dump(data, f, indent=2)
|
||||
print(f'[main] Seeded initial manager account: {email}', file=sys.stderr)
|
||||
try:
|
||||
con = config_utils.open_accounts_db()
|
||||
con.execute(
|
||||
'INSERT INTO accounts(account_id,email,access_level,created_ts,created_by) VALUES(?,?,?,?,?)',
|
||||
(str(_uuid.uuid4()), email, 3, int(_t.time()), 'system')
|
||||
)
|
||||
con.commit()
|
||||
con.close()
|
||||
print(f'[main] Seeded initial manager account: {email}', file=sys.stderr)
|
||||
except Exception as exc:
|
||||
print(f'[main] WARNING: Could not seed initial account: {exc}', file=sys.stderr)
|
||||
|
||||
_seed_initial_account()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue