-
Notifications
You must be signed in to change notification settings - Fork 44
/
app.py
62 lines (45 loc) · 1.97 KB
/
app.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
53
54
55
56
57
58
59
60
61
62
import logging.config
import settings
import utils
from flask import Flask, Blueprint
from flask_restplus import Resource, Api
from api.restplus import api
from api.gan.endpoints.client import ns as gan_client_namespace
# create Flask application
application = Flask(__name__)
# load logging confoguration and create log object
logging.config.fileConfig('logging.conf')
log = logging.getLogger(__name__)
def __get_flask_server_params__():
'''
Returns connection parameters of the Flask application
:return: Tripple of server name, server port and debug settings
'''
server_name = utils.get_env_var_setting('FLASK_SERVER_NAME', settings.DEFAULT_FLASK_SERVER_NAME)
server_port = int(utils.get_env_var_setting('FLASK_SERVER_PORT', settings.DEFAULT_FLASK_SERVER_PORT))
flask_debug = utils.get_env_var_setting('FLASK_DEBUG', settings.DEFAULT_FLASK_DEBUG)
flask_debug = True if flask_debug == '1' else False
return server_name, server_port, flask_debug
def configure_app(flask_app):
'''
Configure Flask application
:param flask_app: instance of Flask() class
'''
flask_app.config['SWAGGER_UI_DOC_EXPANSION'] = settings.RESTPLUS_SWAGGER_UI_DOC_EXPANSION
flask_app.config['RESTPLUS_VALIDATE'] = settings.RESTPLUS_VALIDATE
flask_app.config['RESTPLUS_MASK_SWAGGER'] = settings.RESTPLUS_MASK_SWAGGER
flask_app.config['ERROR_404_HELP'] = settings.RESTPLUS_ERROR_404_HELP
def initialize_app(flask_app):
'''
Initialize Flask application with Flask-RestPlus
:param flask_app: instance of Flask() class
'''
blueprint = Blueprint('tf_api', __name__, url_prefix='/tf_api')
configure_app(flask_app)
api.init_app(blueprint)
api.add_namespace(gan_client_namespace)
flask_app.register_blueprint(blueprint)
if __name__ == '__main__':
server_name, server_port, flask_debug = __get_flask_server_params__()
initialize_app(application)
application.run(debug=flask_debug, host=server_name, port=server_port)