mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
Introduce config file for application
This commit is contained in:
@@ -1,12 +1,33 @@
|
||||
import os
|
||||
from flask import Flask
|
||||
from config import configs
|
||||
from flask._compat import string_types
|
||||
|
||||
|
||||
def create_app():
|
||||
def create_app(config_name):
|
||||
application = Flask(__name__)
|
||||
|
||||
# application.config['NOTIFY_API_ENVIRONMENT'] = config_name
|
||||
# application.config.from_object(configs[config_name])
|
||||
application.config['NOTIFY_API_ENVIRONMENT'] = config_name
|
||||
application.config.from_object(configs[config_name])
|
||||
init_app(application)
|
||||
|
||||
from app.main import main as main_blueprint
|
||||
application.register_blueprint(main_blueprint)
|
||||
|
||||
return application
|
||||
|
||||
|
||||
def init_app(app):
|
||||
for key, value in app.config.items():
|
||||
if key in os.environ:
|
||||
app.config[key] = convert_to_boolean(os.environ[key])
|
||||
|
||||
|
||||
def convert_to_boolean(value):
|
||||
if isinstance(value, string_types):
|
||||
if value.lower() in ['t', 'true', 'on', 'yes', '1']:
|
||||
return True
|
||||
elif value.lower() in ['f', 'false', 'off', 'no', '0']:
|
||||
return False
|
||||
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user