diff --git a/app/__init__.py b/app/__init__.py index 4ce430175..ca9fe9414 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -14,7 +14,6 @@ import app.proxy_fix from config import configs from utils import logging - db = SQLAlchemy() login_manager = LoginManager() csrf = CsrfProtect() @@ -22,13 +21,13 @@ csrf = CsrfProtect() admin_api_client = AdminAPIClient() -def create_app(config_name): +def create_app(config_name, config_overrides=None): application = Flask(__name__) application.config['NOTIFY_ADMIN_ENVIRONMENT'] = config_name application.config.from_object(configs[config_name]) + init_app(application, config_overrides) db.init_app(application) - init_app(application) init_csrf(application) logging.init_app(application) @@ -71,11 +70,16 @@ def init_csrf(application): abort(400, reason) -def init_app(app): +def init_app(app, config_overrides): for key, value in app.config.items(): if key in os.environ: app.config[key] = convert_to_boolean(os.environ[key]) + if config_overrides: + for key in app.config.keys(): + if key in config_overrides: + app.config[key] = config_overrides[key] + @app.context_processor def inject_global_template_variables(): return {'asset_path': '/static/'} diff --git a/db.py b/db.py index 40ed2511c..4aa190099 100644 --- a/db.py +++ b/db.py @@ -1,18 +1,11 @@ -from app import create_app -import os -from credstash import getAllSecrets from flask.ext.script import Manager, Server from flask_migrate import Migrate, MigrateCommand from app import create_app, db +from credstash import getAllSecrets secrets = getAllSecrets(region="eu-west-1") -application = create_app(os.getenv('NOTIFICATIONS_ADMIN_ENVIRONMENT') or 'live') - -for key in application.config.keys(): - if key in secrets: - application.config[key] = secrets[key] - +application = create_app('live', secrets) manager = Manager(application) migrate = Migrate(application, db) diff --git a/wsgi.py b/wsgi.py index f394112fe..138a48c6f 100644 --- a/wsgi.py +++ b/wsgi.py @@ -1,22 +1,9 @@ from app import create_app -import os from credstash import getAllSecrets -from flask.ext.script import Manager, Server -from flask_migrate import Migrate, MigrateCommand -from app import create_app, db secrets = getAllSecrets(region="eu-west-1") -application = create_app(os.getenv('NOTIFICATIONS_ADMIN_ENVIRONMENT') or 'live') - -for key in application.config.keys(): - if key in secrets: - application.config[key] = secrets[key] - - -manager = Manager(application) -migrate = Migrate(application, db) -manager.add_command('db', MigrateCommand) +application = create_app('live', secrets) if __name__ == "__main__": application.run()