mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 21:18:26 -04:00
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:
@@ -14,7 +14,6 @@ import app.proxy_fix
|
|||||||
from config import configs
|
from config import configs
|
||||||
from utils import logging
|
from utils import logging
|
||||||
|
|
||||||
|
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
login_manager = LoginManager()
|
login_manager = LoginManager()
|
||||||
csrf = CsrfProtect()
|
csrf = CsrfProtect()
|
||||||
@@ -22,13 +21,13 @@ csrf = CsrfProtect()
|
|||||||
admin_api_client = AdminAPIClient()
|
admin_api_client = AdminAPIClient()
|
||||||
|
|
||||||
|
|
||||||
def create_app(config_name):
|
def create_app(config_name, config_overrides=None):
|
||||||
application = Flask(__name__)
|
application = Flask(__name__)
|
||||||
|
|
||||||
application.config['NOTIFY_ADMIN_ENVIRONMENT'] = config_name
|
application.config['NOTIFY_ADMIN_ENVIRONMENT'] = config_name
|
||||||
application.config.from_object(configs[config_name])
|
application.config.from_object(configs[config_name])
|
||||||
|
init_app(application, config_overrides)
|
||||||
db.init_app(application)
|
db.init_app(application)
|
||||||
init_app(application)
|
|
||||||
init_csrf(application)
|
init_csrf(application)
|
||||||
logging.init_app(application)
|
logging.init_app(application)
|
||||||
|
|
||||||
@@ -71,11 +70,16 @@ def init_csrf(application):
|
|||||||
abort(400, reason)
|
abort(400, reason)
|
||||||
|
|
||||||
|
|
||||||
def init_app(app):
|
def init_app(app, config_overrides):
|
||||||
for key, value in app.config.items():
|
for key, value in app.config.items():
|
||||||
if key in os.environ:
|
if key in os.environ:
|
||||||
app.config[key] = convert_to_boolean(os.environ[key])
|
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
|
@app.context_processor
|
||||||
def inject_global_template_variables():
|
def inject_global_template_variables():
|
||||||
return {'asset_path': '/static/'}
|
return {'asset_path': '/static/'}
|
||||||
|
|||||||
11
db.py
11
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.ext.script import Manager, Server
|
||||||
from flask_migrate import Migrate, MigrateCommand
|
from flask_migrate import Migrate, MigrateCommand
|
||||||
from app import create_app, db
|
from app import create_app, db
|
||||||
|
from credstash import getAllSecrets
|
||||||
|
|
||||||
secrets = getAllSecrets(region="eu-west-1")
|
secrets = getAllSecrets(region="eu-west-1")
|
||||||
|
|
||||||
application = create_app(os.getenv('NOTIFICATIONS_ADMIN_ENVIRONMENT') or 'live')
|
application = create_app('live', secrets)
|
||||||
|
|
||||||
for key in application.config.keys():
|
|
||||||
if key in secrets:
|
|
||||||
application.config[key] = secrets[key]
|
|
||||||
|
|
||||||
|
|
||||||
manager = Manager(application)
|
manager = Manager(application)
|
||||||
migrate = Migrate(application, db)
|
migrate = Migrate(application, db)
|
||||||
|
|||||||
15
wsgi.py
15
wsgi.py
@@ -1,22 +1,9 @@
|
|||||||
from app import create_app
|
from app import create_app
|
||||||
import os
|
|
||||||
from credstash import getAllSecrets
|
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")
|
secrets = getAllSecrets(region="eu-west-1")
|
||||||
|
|
||||||
application = create_app(os.getenv('NOTIFICATIONS_ADMIN_ENVIRONMENT') or 'live')
|
application = create_app('live', secrets)
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
application.run()
|
application.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user