Example #1
0
def build_statsd_client(app, mocker):
    client = StatsdClient()
    app.config['NOTIFY_ENVIRONMENT'] = "test"
    app.config['NOTIFY_APP_NAME'] = "api"
    app.config['STATSD_HOST'] = "localhost"
    app.config['STATSD_PORT'] = "8000"
    app.config['STATSD_PREFIX'] = "prefix"
    client.init_app(app)
    if not app.config['STATSD_ENABLED']:
        # statsd_client not initialised if statsd not enabled, so lets mock it
        client.statsd_client = Mock()
    mocker.patch.object(client.statsd_client, "incr")
    mocker.patch.object(client.statsd_client, "gauge")
    mocker.patch.object(client.statsd_client, "timing")
    return client
def create_app():
    application = Flask(__name__)

    init_app(application)

    load_config(application)

    from app.precompiled import precompiled_blueprint
    from app.preview import preview_blueprint
    from app.status import status_blueprint
    application.register_blueprint(status_blueprint)
    application.register_blueprint(preview_blueprint)
    application.register_blueprint(precompiled_blueprint)

    application.statsd_client = StatsdClient()
    application.statsd_client.init_app(application)
    application.encryption_client = Encryption()
    application.encryption_client.init_app(application)
    utils_logging.init_app(application, application.statsd_client)
    weasyprint_hack.init_app(application)
    request_helper.init_app(application)
    notify_celery.init_app(application)

    application.cache = init_cache(application)

    @auth.verify_token
    def verify_token(token):
        return token in application.config['TEMPLATE_PREVIEW_INTERNAL_SECRETS']

    return application
 def __init__(self):
     self.config = {}
     self.config.update({
         'STATSD_ENABLED':
         config['GENERAL']['STATSD_ENABLED'],
         'NOTIFY_ENVIRONMENT':
         config['GENERAL']['CF_SPACE'],
         'NOTIFY_APP_NAME':
         'autoscaler',
         'STATSD_HOST':
         os.environ.get('STATSD_HOST', 'testing.local'),
         'STATSD_PORT':
         8125,
     })
     self.statsd_client = StatsdClient()
     self.statsd_client.init_app(self)
Example #4
0
 def __init__(self):
     self.config = {}
     self.config.update({
         'STATSD_ENABLED':
         config['GENERAL']['STATSD_ENABLED'],
         'NOTIFY_ENVIRONMENT':
         config['GENERAL']['CF_SPACE'],
         'NOTIFY_APP_NAME':
         'autoscaler',
         'STATSD_HOST':
         'statsd.hostedgraphite.com',
         'STATSD_PORT':
         '8125',
         'STATSD_PREFIX':
         os.environ['STATSD_PREFIX']
     })
     self.statsd_client = StatsdClient()
     self.statsd_client.init_app(self)
Example #5
0
def create_app():
    application = Flask(__name__)

    init_app(application)

    load_config(application)

    notify_celery.init_app(application)

    from app.preview import preview_blueprint
    from app.status import status_blueprint
    from app.precompiled import precompiled_blueprint
    application.register_blueprint(status_blueprint)
    application.register_blueprint(preview_blueprint)
    application.register_blueprint(precompiled_blueprint)

    application.statsd_client = StatsdClient()
    application.statsd_client.init_app(application)
    application.encryption_client = Encryption()
    application.encryption_client.init_app(application)
    utils_logging.init_app(application, application.statsd_client)

    def evil_error(msg, *args, **kwargs):
        if msg.startswith('Failed to load image'):
            application.logger.exception(msg % tuple(args))
            abort(502)
        else:
            return weasyprint_logs.log(logging.ERROR, msg, *args, **kwargs)

    weasyprint_logs.error = evil_error

    application.cache = init_cache(application)

    @auth.verify_token
    def verify_token(token):
        return token in application.config['TEMPLATE_PREVIEW_INTERNAL_SECRETS']

    return application
Example #6
0
    client_secret=os.getenv('TELSTRA_MESSAGING_CLIENT_SECRET'),
)
twilio_sms_client = TwilioSMSClient(
    account_sid=os.getenv('TWILIO_ACCOUNT_SID'),
    auth_token=os.getenv('TWILIO_AUTH_TOKEN'),
    from_number=os.getenv('TWILIO_FROM_NUMBER'),
)
smtp_client = SMTPClient(
    addr=os.getenv('SMTP_ADDR'),
    user=os.getenv('SMTP_USER'),
    password=os.getenv('SMTP_PASSWORD'),
)
aws_ses_client = AwsSesClient()
encryption = Encryption()
deskpro_client = DeskproClient()
statsd_client = StatsdClient()
redis_store = RedisClient()
performance_platform_client = PerformancePlatformClient()

clients = Clients()

api_user = LocalProxy(lambda: _request_ctx_stack.top.api_user)
authenticated_service = LocalProxy(
    lambda: _request_ctx_stack.top.authenticated_service)


def create_app(application):
    from app.config import configs

    notify_environment = os.environ['NOTIFY_ENVIRONMENT']