Beispiel #1
0
def get_relay_app(config=None):
    basicConfig(
        format=
        '[%(asctime)s] [%(process)d] [%(levelname)s] %(name)s %(message)s',
        level=logging.INFO,
        datefmt='%Y-%m-%d %H:%M:%S %z')

    if not config:
        config = read_config_from_argv()

    iclient = IrisClient(config['iris']['host'], config['iris']['port'],
                         config['iris'].get('relay_app_name', 'iris-relay'),
                         config['iris']['api_key'])
    gmail = Gmail(config.get('gmail'), config.get('proxy'))

    # Note that ReqBodyMiddleware must be run before AuthMiddleware, since
    # authentication uses the post body
    app = falcon.API(middleware=[ReqBodyMiddleware(), AuthMiddleware(config)])

    gmail_relay = GmailRelay(config, iclient, gmail)
    gmail_oneclick_relay = GmailOneClickRelay(config, iclient)
    twilio_calls_say = TwilioCallsSay()
    twilio_calls_gather = TwilioCallsGather(config)
    twilio_calls_relay = TwilioCallsRelay(config, iclient)
    twilio_messages_relay = TwilioMessagesRelay(config, iclient)
    slack_authenticate = SlackAuthenticate()
    slack_messages_relay = SlackMessagesRelay(config, iclient)
    twilio_delivery_status = TwilioDeliveryStatus(config, iclient)
    healthcheck = Healthcheck(config.get('healthcheck_path'))

    app.add_route('/api/v0/gmail/relay', gmail_relay)
    app.add_route('/api/v0/gmail-oneclick/relay', gmail_oneclick_relay)
    app.add_route('/api/v0/twilio/calls/say', twilio_calls_say)
    app.add_route('/api/v0/twilio/calls/gather', twilio_calls_gather)
    app.add_route('/api/v0/twilio/calls/relay', twilio_calls_relay)
    app.add_route('/api/v0/twilio/messages/relay', twilio_messages_relay)
    app.add_route('/api/v0/twilio/status', twilio_delivery_status)
    app.add_route('/api/v0/slack/authenticate', slack_authenticate)
    app.add_route('/api/v0/slack/messages/relay', slack_messages_relay)
    app.add_route('/healthcheck', healthcheck)
    if 'verification_code' in config['gmail']:
        vcode = config['gmail']['verification_code']
        app.add_route('/' + vcode, GmailVerification(vcode))

    return app
Beispiel #2
0
def get_relay_app(config=None):
    if not config:
        config = read_config_from_argv()

    iclient = IrisClient(config['iris']['host'],
                         config['iris']['port'],
                         'iris-relay', config['iris']['api_key'])
    gmail = Gmail(config.get('gmail'), config.get('proxy'))

    # Note that ReqBodyMiddleware must be run before AuthMiddleware, since authentication uses the post body
    app = falcon.API(middleware=[ReqBodyMiddleware(), AuthMiddleware(config)])

    gmail_relay = GmailRelay(config, iclient, gmail)
    gmail_oneclick_relay = GmailOneClickRelay(config, iclient)
    twilio_calls_say = TwilioCallsSay()
    twilio_calls_gather = TwilioCallsGather(config)
    twilio_calls_relay = TwilioCallsRelay(config, iclient)
    twilio_messages_relay = TwilioMessagesRelay(config, iclient)
    slack_authenticate = SlackAuthenticate()
    slack_messages_relay = SlackMessagesRelay(config)
    healthcheck = Healthcheck()

    version = 0
    app.add_route('/api/v%d/gmail/relay' % version, gmail_relay)
    app.add_route('/api/v%d/gmail-oneclick/relay' % version, gmail_oneclick_relay)
    app.add_route('/api/v%d/twilio/calls/say' % version, twilio_calls_say)
    app.add_route('/api/v%d/twilio/calls/gather' % version, twilio_calls_gather)
    app.add_route('/api/v%d/twilio/calls/relay' % version, twilio_calls_relay)
    app.add_route('/api/v%d/twilio/messages/relay' % version, twilio_messages_relay)
    app.add_route('/api/v%d/slack/authenticate' % version, slack_authenticate)
    app.add_route('/api/v%d/slack/messages/relay' % version, slack_messages_relay)
    app.add_route('/health', healthcheck)
    app.add_route('/healthcheck', healthcheck)
    if 'verification_code' in config['gmail']:
        vcode = config['gmail']['verification_code']
        gmail_verify = GmailVerification(vcode)
        app.add_route('/' + vcode, gmail_verify)

    basicConfig()
    return app
Beispiel #3
0
def get_relay_app(config=None):
    basicConfig(
        format=
        '[%(asctime)s] [%(process)d] [%(levelname)s] %(name)s %(message)s',
        level=logging.INFO,
        datefmt='%Y-%m-%d %H:%M:%S %z')

    if not config:
        config = read_config_from_argv()

    oncall_client = OncallClient(app=config['oncall'].get(
        'relay_app_name', 'iris-relay'),
                                 key=config['oncall']['api_key'],
                                 api_host=config['oncall']['url'])

    iclient = IrisClient(config['iris']['host'], config['iris']['port'],
                         config['iris'].get('relay_app_name', 'iris-relay'),
                         config['iris']['api_key'])
    saml = SAML(config.get('saml'))

    # Note that ReqBodyMiddleware must be run before AuthMiddleware, since
    # authentication uses the post body
    cors = CORS(config.get('allow_origins_list', []))
    app = falcon.API(
        middleware=[ReqBodyMiddleware(),
                    AuthMiddleware(config), cors])

    ical_relay = OncallCalendarRelay(oncall_client, config['oncall']['url'])
    app.add_route('/api/v0/ical/{ical_key}', ical_relay)

    gmail_config = config.get('gmail')
    if gmail_config:
        gmail = Gmail(gmail_config, config.get('proxy'))
        gmail_relay = GmailRelay(config, iclient, gmail)
        gmail_oneclick_relay = GmailOneClickRelay(config, iclient)
        app.add_route('/api/v0/gmail/relay', gmail_relay)
        app.add_route('/api/v0/gmail-oneclick/relay', gmail_oneclick_relay)
        if 'verification_code' in gmail_config:
            vcode = config['gmail']['verification_code']
            app.add_route('/' + vcode, GmailVerification(vcode))

    twilio_calls_say = TwilioCallsSay()
    twilio_calls_gather = TwilioCallsGather(config)
    twilio_calls_relay = TwilioCallsRelay(config, iclient)
    twilio_messages_relay = TwilioMessagesRelay(config, iclient)
    slack_authenticate = SlackAuthenticate()
    slack_messages_relay = SlackMessagesRelay(config, iclient)
    twilio_delivery_status = TwilioDeliveryStatus(config, iclient)
    healthcheck = Healthcheck(config.get('healthcheck_path'))

    app.add_route('/api/v0/twilio/calls/say', twilio_calls_say)
    app.add_route('/api/v0/twilio/calls/gather', twilio_calls_gather)
    app.add_route('/api/v0/twilio/calls/relay', twilio_calls_relay)
    app.add_route('/api/v0/twilio/messages/relay', twilio_messages_relay)
    app.add_route('/api/v0/twilio/status', twilio_delivery_status)
    app.add_route('/api/v0/slack/authenticate', slack_authenticate)
    app.add_route('/api/v0/slack/messages/relay', slack_messages_relay)
    app.add_route('/healthcheck', healthcheck)
    mobile_cfg = config.get('iris-mobile', {})
    if mobile_cfg.get('activated'):
        db.init(config['db'])
        mobile_iris_client = IrisMobileClient(app=mobile_cfg.get(
            'relay_app_name', 'iris-relay'),
                                              api_host=mobile_cfg['host'],
                                              key=mobile_cfg['api_key'])

        mobile_oncall_client = OncallClient(
            app=mobile_cfg.get('relay_app_name', 'iris-relay'),
            key=mobile_cfg['oncall']['api_key'],
            api_host=mobile_cfg['oncall']['url'])

        iris_mobile_sink = IrisMobileSink(mobile_iris_client,
                                          mobile_cfg['host'])
        oncall_mobile_sink = OncallMobileSink(mobile_oncall_client,
                                              mobile_cfg['oncall']['url'])
        app.add_sink(oncall_mobile_sink, prefix='/api/v0/oncall/')
        app.add_sink(iris_mobile_sink, prefix='/api/v0/mobile/')
        app.add_route('/saml/login/{idp_name}', SPInitiated(saml))
        app.add_route('/saml/sso/{idp_name}',
                      IDPInitiated(mobile_cfg.get('auth'), saml))
        app.add_route('/api/v0/mobile/refresh',
                      TokenRefresh(mobile_cfg.get('auth')))
        app.add_route('/api/v0/mobile/device', RegisterDevice(iclient))

    for hook in config.get('post_init_hook', []):
        try:
            logger.debug('loading post init hook <%s>', hook)
            getattr(import_module(hook), 'init')(app, config)
        except Exception:
            logger.exception('Failed loading post init hook <%s>', hook)

    return app
Beispiel #4
0
def get_relay_app(config=None):
    basicConfig(
        format=
        '[%(asctime)s] [%(process)d] [%(levelname)s] %(name)s %(message)s',
        level=logging.INFO,
        datefmt='%Y-%m-%d %H:%M:%S %z')

    if not config:
        config = read_config_from_argv()

    iclient = IrisClient(config['iris']['host'], config['iris']['port'],
                         config['iris'].get('relay_app_name', 'iris-relay'),
                         config['iris']['api_key'])
    gmail = Gmail(config.get('gmail'), config.get('proxy'))
    saml = SAML(config.get('saml'))

    # Note that ReqBodyMiddleware must be run before AuthMiddleware, since
    # authentication uses the post body
    app = falcon.API(middleware=[ReqBodyMiddleware(), AuthMiddleware(config)])

    gmail_relay = GmailRelay(config, iclient, gmail)
    gmail_oneclick_relay = GmailOneClickRelay(config, iclient)
    twilio_calls_say = TwilioCallsSay()
    twilio_calls_gather = TwilioCallsGather(config)
    twilio_calls_relay = TwilioCallsRelay(config, iclient)
    twilio_messages_relay = TwilioMessagesRelay(config, iclient)
    slack_authenticate = SlackAuthenticate()
    slack_messages_relay = SlackMessagesRelay(config, iclient)
    twilio_delivery_status = TwilioDeliveryStatus(config, iclient)
    healthcheck = Healthcheck(config.get('healthcheck_path'))

    app.add_route('/api/v0/gmail/relay', gmail_relay)
    app.add_route('/api/v0/gmail-oneclick/relay', gmail_oneclick_relay)
    app.add_route('/api/v0/twilio/calls/say', twilio_calls_say)
    app.add_route('/api/v0/twilio/calls/gather', twilio_calls_gather)
    app.add_route('/api/v0/twilio/calls/relay', twilio_calls_relay)
    app.add_route('/api/v0/twilio/messages/relay', twilio_messages_relay)
    app.add_route('/api/v0/twilio/status', twilio_delivery_status)
    app.add_route('/api/v0/slack/authenticate', slack_authenticate)
    app.add_route('/api/v0/slack/messages/relay', slack_messages_relay)
    app.add_route('/healthcheck', healthcheck)
    mobile_cfg = config.get('iris-mobile', {})
    if mobile_cfg.get('activated'):
        db.init(config['db'])
        mobile_client = IrisClient(mobile_cfg['host'],
                                   mobile_cfg['port'],
                                   mobile_cfg.get('relay_app_name',
                                                  'iris-relay'),
                                   mobile_cfg['api_key'],
                                   version=None)
        mobile_sink = MobileSink(mobile_client)
        app.add_sink(mobile_sink, prefix='/api/v0/mobile/')
        app.add_route('/saml/login/{idp_name}', SPInitiated(saml))
        app.add_route('/saml/sso/{idp_name}',
                      IDPInitiated(mobile_cfg.get('auth'), saml))
        app.add_route('/api/v0/mobile/refresh',
                      TokenRefresh(mobile_cfg.get('auth')))
        app.add_route('/api/v0/mobile/device', RegisterDevice(iclient))

    if 'verification_code' in config['gmail']:
        vcode = config['gmail']['verification_code']
        app.add_route('/' + vcode, GmailVerification(vcode))

    return app