Merge pull request #54 from alphagov/credstash-integration

Integrated credstash as a live properties setting in the app.py class
This commit is contained in:
minglis
2016-01-11 10:11:24 +00:00
3 changed files with 11 additions and 27 deletions

View File

@@ -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/'}

11
db.py
View File

@@ -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)

15
wsgi.py
View File

@@ -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()