-
Notifications
You must be signed in to change notification settings - Fork 3
/
flask_server.py
executable file
·52 lines (39 loc) · 1.32 KB
/
flask_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""This file is the main module which contains the app.
"""
from app import create_app, db
from app.auth.auth_cli import getToken
from decouple import config
from flask.cli import AppGroup
import click
import config as configs
# Figure out which config we want based on the `ENV` env variable, default to local
from app.utils.backfill import backfill
env_config = config("ENV", cast=str, default="localpsql")
config_dict = {
'production': configs.Production,
'localpsql': configs.LocalPSQLConfig,
'develop': configs.Develop,
'testing': configs.Testing,
}
app = create_app(config_dict[env_config]())
# for production, require a real SECRET_KEY to be set
if env_config == 'production':
assert app.config['SECRET_KEY'] != "12345", "You must set a secure SECRET_KEY"
# register a custom command to get authentication tokens
auth_cli = AppGroup('auth')
@auth_cli.command("getToken")
@click.argument('name')
def getToken_cli(name):
click.echo(getToken(name))
app.cli.add_command(auth_cli)
@app.cli.command()
def deploy():
"""Run deployment tasks"""
# e.g. this _used_ to be where a database migration would run via `upgrade()`
pass
utils_cli = AppGroup('utils')
@utils_cli.command("backfill")
@click.argument('input_file')
def backfill_cli(input_file):
backfill(input_file)
app.cli.add_command(utils_cli)