Add secret key config and generate_secret command

This commit is contained in:
Tim Van Baak 2020-01-03 17:05:36 -08:00
parent 3629f91bf4
commit ed106cf787
2 changed files with 15 additions and 2 deletions

View File

@ -43,8 +43,7 @@ def no_argument(command):
@add_argument("--update", action="store_true", help="Refresh an existing config directory")
def command_init(args):
"""Initialize an Amanuensis config directory at the directory given by
--config-dir"""
"""Initialize a config directory at the directory given by --config-dir"""
from collections import OrderedDict
import fcntl
import json
@ -93,6 +92,19 @@ def command_init(args):
if not os.path.isdir(os.path.join(cfd, "user")):
os.mkdir(os.path.join(cfd, "user"))
@no_argument
def command_generate_secret(args):
"""Generate a secret key for Flask"""
import os
import config
from config.loader import WritableConfig
secret_key = os.urandom(32)
with WritableConfig(os.path.join(config.CONFIG_DIR, "config.json")) as cfg:
cfg['secret_key'] = secret_key.hex()
config.logger.info("Regenerated Flask secret key")
@add_argument("-a", "--address", default="127.0.0.1")
@add_argument("-p", "--port", default="5000")
def command_run(args):

View File

@ -1,4 +1,5 @@
{
"secret_key": null,
"address": "127.0.0.1",
"port": "5000",
"lexicon_data": "./lexicon",