Ensured credstash is located only with the wsgi/gunicorn code.

This commit is contained in:
Martyn Inglis
2016-01-11 09:59:31 +00:00
parent 42b62ce7cd
commit 7efa513777
3 changed files with 14 additions and 11 deletions

View File

@@ -13,7 +13,6 @@ from app.its_dangerous_session import ItsdangerousSessionInterface
import app.proxy_fix
from config import configs
from utils import logging
from credstash import getAllSecrets
db = SQLAlchemy()
login_manager = LoginManager()
@@ -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,17 +70,15 @@ 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 app.config['NOTIFY_ADMIN_ENVIRONMENT'] == 'live':
secrets = getAllSecrets(region="eu-west-1")
if config_overrides:
for key in app.config.keys():
if key in secrets:
app.config[key] = secrets[key]
if key in config_overrides:
app.config[key] = config_overrides[key]
@app.context_processor
def inject_global_template_variables():

5
db.py
View File

@@ -1,8 +1,11 @@
from flask.ext.script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
from app import create_app, db
from credstash import getAllSecrets
application = create_app('live')
secrets = getAllSecrets(region="eu-west-1")
application = create_app('live', secrets)
manager = Manager(application)
migrate = Migrate(application, db)

View File

@@ -1,6 +1,9 @@
from app import create_app
from credstash import getAllSecrets
application = create_app('live')
secrets = getAllSecrets(region="eu-west-1")
application = create_app('live', secrets)
if __name__ == "__main__":
application.run()