Added AWS files to

- upgrade database
- use credstash for secret overrides
This commit is contained in:
Martyn Inglis
2016-01-19 14:50:42 +00:00
parent 6141a11e7f
commit 742a567036
5 changed files with 31 additions and 4 deletions

View File

@@ -15,7 +15,7 @@ ma = Marshmallow()
api_user = LocalProxy(lambda: _request_ctx_stack.top.api_user)
def create_app(config_name):
def create_app(config_name, config_overrides=None):
application = Flask(__name__)
application.config['NOTIFY_API_ENVIRONMENT'] = config_name
@@ -23,7 +23,7 @@ def create_app(config_name):
db.init_app(application)
ma.init_app(application)
init_app(application)
init_app(application, config_overrides)
logging.init_app(application)
from app.service.rest import service as service_blueprint
@@ -41,11 +41,16 @@ def create_app(config_name):
return application
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.before_request
def required_authentication():
from app.authentication import auth

15
db.py Normal file
View File

@@ -0,0 +1,15 @@
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('live', secrets)
manager = Manager(application)
migrate = Migrate(application, db)
manager.add_command('db', MigrateCommand)
if __name__ == '__main__':
manager.run()

View File

@@ -11,6 +11,7 @@ marshmallow-sqlalchemy==0.8.0
flask-marshmallow==0.6.2
itsdangerous==0.24
Flask-Bcrypt==0.6.2
credstash==1.8.0
git+https://github.com/alphagov/notifications-python-client.git@0.1.5#egg=notifications-python-client==0.1.5

View File

@@ -1 +1,4 @@
echo "Install dependencies"
cd /home/ubuntu/notifications-api;
pip3 install -r /home/ubuntu/notifications-api/requirements.txt
python3 db.py db upgrade

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