-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·44 lines (33 loc) · 1.18 KB
/
app.py
File metadata and controls
executable file
·44 lines (33 loc) · 1.18 KB
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
#!/usr/bin/env python3
import connexion
from connexion.resolver import RestyResolver
from flask.helpers import get_debug_flag
from sqlalchemy.orm.exc import NoResultFound
import configs
from orm import db, User
import os
API_VERSION = "0.1.0"
def create_app(config_object=configs.ProdConfig):
app = connexion.App(__name__)
app.add_api("openapi.yml", resolver=RestyResolver("api"), strict_validation=True)
app.app.config.from_object(config_object)
db.init_app(app.app)
app.app.app_context().push()
db.create_all()
return app
def flask_app():
"""Returns an acutal flask app for using 'flask shell'"""
return create_app().app
if __name__ == "__main__":
CONFIG = configs.DevConfig if get_debug_flag() else configs.ProdConfig
app = create_app(CONFIG)
if CONFIG.USER and CONFIG.PASS:
try:
User.query.filter_by(name=CONFIG.USER).one()
except NoResultFound:
from argon2 import PasswordHasher
ph = PasswordHasher()
user = User(name=CONFIG.USER, password=ph.hash(CONFIG.PASS))
db.session.add(user)
db.session.commit()
app.run(port=os.environ['PORT'], debug=CONFIG.DEBUG)