2018-05-21 21:02:38 +00:00
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
|
2018-06-05 17:43:01 +00:00
|
|
|
from flask import Flask
|
2018-05-24 14:52:42 +00:00
|
|
|
|
2018-06-19 17:46:34 +00:00
|
|
|
from data import database, model
|
2018-05-24 14:52:42 +00:00
|
|
|
from util.config.superusermanager import SuperUserManager
|
2018-06-05 17:43:01 +00:00
|
|
|
from util.ipresolver import NoopIPResolver
|
|
|
|
|
2018-08-06 14:52:56 +00:00
|
|
|
from config_app._init_config import ROOT_DIR, IS_KUBERNETES
|
2018-06-05 17:43:01 +00:00
|
|
|
from config_app.config_util.config import get_config_provider
|
2018-06-21 18:48:40 +00:00
|
|
|
from util.security.instancekeys import InstanceKeys
|
2018-05-24 14:52:42 +00:00
|
|
|
|
2018-05-21 21:02:38 +00:00
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2018-06-04 18:14:19 +00:00
|
|
|
OVERRIDE_CONFIG_DIRECTORY = os.path.join(ROOT_DIR, 'config_app/conf/stack')
|
2018-07-11 20:03:36 +00:00
|
|
|
INIT_SCRIPTS_LOCATION = '/conf/init/'
|
2018-05-21 21:02:38 +00:00
|
|
|
|
|
|
|
is_testing = 'TEST' in os.environ
|
2018-08-06 14:52:56 +00:00
|
|
|
is_kubernetes = IS_KUBERNETES
|
|
|
|
|
|
|
|
logger.debug('Configuration is on a kubernetes deployment: %s' % IS_KUBERNETES)
|
2018-05-21 21:02:38 +00:00
|
|
|
|
2018-06-05 17:43:01 +00:00
|
|
|
config_provider = get_config_provider(OVERRIDE_CONFIG_DIRECTORY, 'config.yaml', 'config.py',
|
2018-08-08 18:22:28 +00:00
|
|
|
testing=is_testing)
|
2018-05-21 21:02:38 +00:00
|
|
|
|
|
|
|
if is_testing:
|
2018-08-15 19:32:24 +00:00
|
|
|
from test.testconfig import TestConfig
|
|
|
|
|
|
|
|
logger.debug('Loading test config.')
|
|
|
|
app.config.from_object(TestConfig())
|
2018-05-21 21:02:38 +00:00
|
|
|
else:
|
2018-08-15 19:32:24 +00:00
|
|
|
from config import DefaultConfig
|
|
|
|
|
|
|
|
logger.debug('Loading default config.')
|
|
|
|
app.config.from_object(DefaultConfig())
|
|
|
|
app.teardown_request(database.close_db_filter)
|
2018-05-21 21:02:38 +00:00
|
|
|
|
|
|
|
# Load the override config via the provider.
|
|
|
|
config_provider.update_app_config(app.config)
|
2018-05-24 14:52:42 +00:00
|
|
|
superusers = SuperUserManager(app)
|
2018-06-05 17:43:01 +00:00
|
|
|
ip_resolver = NoopIPResolver()
|
2018-06-21 18:48:40 +00:00
|
|
|
instance_keys = InstanceKeys(app)
|
2018-06-19 17:46:34 +00:00
|
|
|
|
|
|
|
model.config.app_config = app.config
|