Add secret key config and generate_secret command
This commit is contained in:
parent
3629f91bf4
commit
ed106cf787
|
@ -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):
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"secret_key": null,
|
||||
"address": "127.0.0.1",
|
||||
"port": "5000",
|
||||
"lexicon_data": "./lexicon",
|
||||
|
|
Loading…
Reference in New Issue