Skip to content

Commit f4b7296

Browse files
committed
Move Flask secret key to an environment variable
1 parent f313013 commit f4b7296

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: UTF-8 -*-
22

3+
from os import environ
34
from os.path import abspath, dirname, join
45
from time import strftime
56

@@ -36,7 +37,7 @@
3637
HOST = "127.0.0.1" # Dev
3738
# HOST = "0.0.0.0" # Production
3839
PORT = 4000
39-
SECRET_KEY = "12345" # TODO: move out the sensitive data
40+
SECRET_KEY = environ.get("FLASKAPP_KEY")
4041

4142
LOGGING = True
4243
LOG_FILE = join(LOG_DIR, "flaskapp_{}.log".format(strftime(TIMESTAMP_FORMAT).replace(' ', '_')))

main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from application.misc import parse_arguments, setup_logging
99
from application.shared.filesystem import ensure_dir
1010

11-
from config import LOG_DIR, HOST, PORT
11+
from config import LOG_DIR, HOST, PORT, SECRET_KEY
1212

1313

1414
def main() -> int:
@@ -19,6 +19,9 @@ def main() -> int:
1919
ensure_dir(LOG_DIR)
2020
log_level = DEBUG if args.verbose else INFO
2121
setup_logging(app, log_level)
22+
if SECRET_KEY is None:
23+
app.logger.error("Setup you FLASKAPP_KEY environment variable first in order to run the application!")
24+
return ExitCode.FAILURE.value
2225
# Run server
2326
app.run(host=HOST, port=PORT, debug=DEBUG)
2427

0 commit comments

Comments
 (0)