def test_indent_value_error(self, l): logger_initial_config(service_name='ras-frontstage-api') logger = wrap_logger(logging.getLogger()) logger.error('Test') message = l.records[0].msg self.assertTrue( '{"event": "Test", "level": "error", "service": "ras-frontstage-api"' in message)
def create_app(): app = create_app('TestingConfig') logger_initial_config(log_level=app.config['LOGGING_LEVEL']) app.config['PARTY_SCHEMA'] = party_schema.schema app.db = create_database(app.config['DATABASE_URI'], app.config['DATABASE_SCHEMA']) app.config['EMAIL_TOKEN_EXPIRY'] = 0 return app
def test_indent_type_error(self, l): os.environ['JSON_INDENT_LOGGING'] = 'abc' logger_initial_config(service_name='ras-frontstage-api') logger = wrap_logger(logging.getLogger()) logger.error('Test') message = l.records[0].msg self.assertTrue( '{"event": "Test", "level": "error", "service": "ras-frontstage-api"' in message)
from flask import Flask from flask_httpauth import HTTPBasicAuth from flask_restplus import Api, Namespace from logger_config import logger_initial_config app = Flask(__name__) app_config = 'config.{}'.format(os.environ.get('APP_SETTINGS', 'Config')) app.config.from_object(app_config) app.url_map.strict_slashes = False logger_initial_config(service_name='ras-frontstage-api', log_level=app.config['LOGGING_LEVEL']) auth = HTTPBasicAuth() api = Api(title='Frontstage-API', default='info', default_label=None) passwords_api = Namespace('passwords', path='/passwords') register_api = Namespace('register', path='/register') secure_messaging_api = Namespace('secure-messaging', path='/secure-messaging') sign_in_api = Namespace('sign-in', path='/sign-in') surveys_api = Namespace('surveys', path='/surveys') api.add_namespace(passwords_api) api.add_namespace(register_api) api.add_namespace(secure_messaging_api) api.add_namespace(sign_in_api)
exception, ProgrammingError) @retry(retry_on_exception=retry_if_database_error, wait_fixed=2000, stop_max_delay=30000, wrap_exception=True) def initialise_db(app): # TODO: this isn't entirely safe, use a get_db() lazy initializer instead... app.db = create_database(app.config['DATABASE_URI'], app.config['DATABASE_SCHEMA']) if __name__ == '__main__': app = create_app() with open(app.config['PARTY_SCHEMA']) as io: app.config['PARTY_SCHEMA'] = loads(io.read()) logger_initial_config(log_level=app.config['LOGGING_LEVEL']) try: initialise_db(app) except RetryError: logger.exception('Failed to initialise database') exit(1) scheme, host, port = app.config['SCHEME'], app.config['HOST'], int( app.config['PORT']) app.run(debug=app.config['DEBUG'], host=host, port=port)
import logging import os from flask import Flask from flask_restful import Api from flask_cors import CORS from structlog import wrap_logger from cloud.resources.info import Info from cloud.cloud_foundry import ONSCloudFoundry from logger_config import logger_initial_config logger_initial_config(service_name='clear_down') logger = wrap_logger(logging.getLogger(__name__)) # use cf env to extract Cloud Foundry environment cf = ONSCloudFoundry() app = Flask(__name__) api = Api(app) CORS(app) if cf.detected: logger.info('Cloud Foundry environment identified.', protocol=cf.protocol, database=cf.database()) app.config['SQLALCHEMY_DATABASE_URI'] = cf.credentials() else: app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv( 'SECURE_MESSAGING_DATABASE_URL', 'postgresql://*****:*****@localhost:5432')