Example #1
0
def lambda_handler(event, context=None):

    # Periodic
    if event.get('detail-type') == 'Scheduled Event':
        debug(event, context)
        return app.on_timer(event)

    # SNS / Dynamodb / Kinesis
    elif event.get('Records'):
        records = event['Records']
        if records and records[0]['EventSource'] == 'aws:sns':
            return app.on_config_message(records)
        else:
            return debug(event, context)
    elif not event.get('path'):
        return debug(event, context)

    # API Gateway
    if app.config.get('sentry-dsn'):
        from raven import Client
        from raven.contrib.bottle import Sentry
        client = Client(app.config['sentry-dsn'])
        app.app.catchall = False
        wrapped_app = Sentry(app.app, client)
    else:
        wrapped_app = app.app

    return wsgigw.invoke(wrapped_app, event)
Example #2
0
    def activate(self):
        if not self.config:
            self.log.info('Webserver is not configured. Forbid activation')
            return

        host = self.config['HOST']
        port = self.config['PORT']
        ssl = self.config['SSL']
        interfaces = [(host, port)]
        if ssl['enabled']:
            # noinspection PyTypeChecker
            interfaces.append(
                (ssl['host'], ssl['port'], ssl['key'], ssl['certificate']))
        self.log.info('Firing up the Rocket')

        from errbot.bootstrap import sentry_client

        if sentry_client is None:
            wsgi_app = bottle_app
        else:
            from raven.contrib.bottle import Sentry

            bottle_app.catchall = False
            wsgi_app = Sentry(bottle_app, sentry_client)

        self.webserver = Rocket(
            interfaces=interfaces,
            app_info={'wsgi_app': wsgi_app},
        )
        self.webserver.start(background=True)
        self.log.debug('Liftoff!')

        super().activate()
Example #3
0
def create_app(raven):
    import os

    app = bottle.app()
    app.catchall = False
    app = Sentry(app, client=raven)
    tapp = TestApp(app)

    @bottle.route('/error/', ['GET', 'POST'])
    def an_error():
        raise ValueError('hello world')

    @bottle.route('/capture/', ['GET', 'POST'])
    def capture_exception():
        try:
            raise ValueError('Boom')
        except:
            tapp.app.captureException()
        return 'Hello'

    @bottle.route('/message/', ['GET', 'POST'])
    def capture_message():
        tapp.app.captureMessage('Interesting')
        return 'World'

    return tapp
Example #4
0
    def install(self):
        """ install(self)

            Instantiates and installs the Raven DSN into the Bottle
            framework for error reporting to Sentry.
        """

        if not self.__base.install():
            return False

        try:
            self.__base.get_app().catchall = False
            self.__wrapper = Sentry(self.__base.get_app(), self.__client)
        except Exception as e:
            self.__logger.error(
                " --> Encountered Exception while installing DSN:")
            self.__logger.error(" --> {}".format(e))
            return False

        return True
Example #5
0
        return format_result({
            'token': result,
        })


@app.route('/crossdomain.xml')
def crossdomain():
    response.content_type = 'application/xml'
    return template('crossdomain')


app.install(validate_format)
app_v1.install(validate_format)
app.install(EnableCORS())
app_v1.install(EnableCORS())
app.mount('/v1', app_v1)

SENTRY_DSN = os.getenv('SENTRY_DSN')
if SENTRY_DSN:
    sentry_client = Client(SENTRY_DSN)
    app = Sentry(app, sentry_client)
    app_v1 = Sentry(app_v1, sentry_client)


def _standalone(port=9876):
    run(app=app, host='0.0.0.0', port=port)


if __name__ == "__main__":
    _standalone()
Example #6
0
app = bottle.Bottle()
app.config.update({
    'mongodb.uri': 'mongodb://*****:*****@app.hook('after_request')
    def add_cors_response_headers():
        if bottle.request.method in ('GET', 'OPTIONS'):
            bottle.response.set_header('Access-Control-Allow-Origin', '*')
            bottle.response.set_header('Access-Control-Allow-Headers', ','.join(CORS_HEADERS))
Example #7
0
def run_webserver():
	app = bottle.app()
	app.catchall = False
	app = Sentry(app, raven.Client(SENTRY_DSN))
	bottle.run(app, server='paste', host='0.0.0.0', port=3350)
Example #8
0
import bottle
from bottle import route, run, template
from raven import Client
from raven.contrib.bottle import Sentry

app = bottle.app()
app.catchall = False

client = Client('https://*****:*****@sentry.io/175151')
app = Sentry(app, client)

@route('/hello/<name>')
def index(name):
    x / 0
    return template('<b>Hello {{name}}</b>!', name=name)

run(app=app, host='localhost', port=8000)
Example #9
0
                    rawmsg,
                    sdktype=sdktype)
    if "success" in result:
        return "success"
    logger.error('[sdk moge] pay failed %r' % params)
    return "error"


if __name__ == "__main__":
    import gevent.monkey
    gevent.monkey.patch_all()
    from gevent.pywsgi import WSGIServer

    logger.info('listening %s:%d', settings.SDKAPP['host'],
                settings.SDKAPP['port'])

    # {{{ Sentry
    if hasattr(settings, 'SENTRY_DSN'):
        from raven import Client
        from raven.contrib.bottle import Sentry
        if settings.SENTRY_DSN:
            client = Client(settings.SENTRY_DSN)
            application = Sentry(application, client)
        logger.info('setup sentry with {}'.format(settings.SENTRY_DSN))
    # }}}

    WSGIServer((settings.SDKAPP['host'], settings.SDKAPP['port']),
               application).serve_forever()

# vim: set fdm=marker: