コード例 #1
0
ファイル: test_logging.py プロジェクト: darrencoles/autopush
 def test_custom_type(self):
     setup_logging("Autopush")
     with patch("sys.stdout") as mock_stdout:
         log.msg("omg!", Type=7)
         eq_(len(mock_stdout.mock_calls), 1)
         kwargs = mock_stdout.mock_calls[0][1][0]
     ok_("Type" in kwargs)
コード例 #2
0
ファイル: test_logging.py プロジェクト: jrconlin/autopush
 def test_custom_type(self):
     setup_logging("Autopush")
     with patch("sys.stdout") as mock_stdout:
         log.msg("omg!", Type=7)
         eq_(len(mock_stdout.mock_calls), 1)
         kwargs = mock_stdout.mock_calls[0][1][0]
     ok_("Type" in kwargs)
コード例 #3
0
ファイル: test_logging.py プロジェクト: darrencoles/autopush
 def test_human_logs(self):
     setup_logging("Autopush", True)
     with patch("sys.stdout") as mock_stdout:
         mock_stdout.reset_mock()
         log.msg("omg!", Type=7)
         eq_(len(mock_stdout.mock_calls), 4)
         mock_stdout.reset_mock()
         log.err("wtf!", Type=7)
         eq_(len(mock_stdout.mock_calls), 4)
コード例 #4
0
ファイル: test_logging.py プロジェクト: crodjer/autopush
    def test_sentry_logging(self):
        os.environ["SENTRY_DSN"] = "some_locale"
        setup_logging("Autopush")
        eq_(len(self.mock_raven.mock_calls), 2)

        log.err(failure.Failure(Exception("eek")))
        self.flushLoggedErrors()
        eq_(len(self.mock_client.mock_calls), 1)
        del os.environ["SENTRY_DSN"]
コード例 #5
0
ファイル: test_logging.py プロジェクト: jrconlin/autopush
 def test_human_logs(self):
     setup_logging("Autopush", True)
     with patch("sys.stdout") as mock_stdout:
         mock_stdout.reset_mock()
         log.msg("omg!", Type=7)
         eq_(len(mock_stdout.mock_calls), 4)
         mock_stdout.reset_mock()
         log.err("wtf!", Type=7)
         eq_(len(mock_stdout.mock_calls), 4)
コード例 #6
0
ファイル: test_logging.py プロジェクト: jrconlin/autopush
    def test_sentry_logging(self):
        os.environ["SENTRY_DSN"] = "some_locale"
        setup_logging("Autopush")
        eq_(len(self.mock_raven.mock_calls), 2)

        log.err(failure.Failure(Exception("eek")))
        self.flushLoggedErrors()
        eq_(len(self.mock_client.mock_calls), 1)
        del os.environ["SENTRY_DSN"]
コード例 #7
0
ファイル: test_logging.py プロジェクト: darrencoles/autopush
    def test_sentry_logging(self):
        os.environ["SENTRY_DSN"] = "some_locale"
        setup_logging("Autopush")
        eq_(len(self.mock_raven.mock_calls), 2)

        log.err(failure.Failure(Exception("eek")))
        self.flushLoggedErrors()
        d = Deferred()

        def check():
            if len(self.mock_client.mock_calls):
                eq_(len(self.mock_client.mock_calls), 1)
                d.callback(True)
            else:  # pragma: nocover
                reactor.callLater(0, check)
        del os.environ["SENTRY_DSN"]
        reactor.callLater(0, check)
        return d
コード例 #8
0
ファイル: main.py プロジェクト: crodjer/autopush
def endpoint_main(sysargs=None):
    """Main entry point to setup an endpoint node, aka the autoendpoint
    script"""
    args, parser = _parse_endpoint(sysargs)
    settings = make_settings(
        args,
        endpoint_scheme="https" if args.ssl_key else "http",
        endpoint_hostname=args.hostname,
        endpoint_port=args.port,
        enable_cors=args.cors
    )

    setup_logging("Autoendpoint")

    # Endpoint HTTP router
    site = cyclone.web.Application([
        (r"/push/([^\/]+)", EndpointHandler, dict(ap_settings=settings)),
        # PUT /register/ => connect info
        # GET /register/uaid => chid + endpoint
        (r"/register(?:/(.+))?", RegistrationHandler,
         dict(ap_settings=settings)),
    ],
        default_host=settings.hostname, debug=args.debug,
        log_function=skip_request_logging
    )
    mount_health_handlers(site, settings)

    settings.metrics.start()

    if args.ssl_key:
        contextFactory = AutopushSSLContextFactory(args.ssl_key,
                                                   args.ssl_cert)
        if args.ssl_dh_param:
            contextFactory.getContext().load_tmp_dh(args.ssl_dh_param)
        reactor.listenSSL(args.port, site, contextFactory)
    else:
        reactor.listenTCP(args.port, site)

    reactor.suggestThreadPoolSize(50)
    reactor.run()
コード例 #9
0
ファイル: main.py プロジェクト: martinthomson/autopush
def connection_main(sysargs=None):
    """Main entry point to setup a connection node, aka the autopush script"""
    args, parser = _parse_connection(sysargs)
    setup_logging("Autopush", args.human_logs)
    settings = make_settings(
        args,
        port=args.port,
        endpoint_scheme=args.endpoint_scheme,
        endpoint_hostname=args.endpoint_hostname,
        endpoint_port=args.endpoint_port,
        router_scheme="https" if args.router_ssl_key else "http",
        router_hostname=args.router_hostname,
        router_port=args.router_port,
        env=args.env,
        hello_timeout=args.hello_timeout,
    )

    r = RouterHandler
    r.ap_settings = settings
    n = NotificationHandler
    n.ap_settings = settings

    # Internal HTTP notification router
    site = cyclone.web.Application([
        (r"/push/([^\/]+)", r),
        (r"/notif/([^\/]+)(/([^\/]+))?", n),
    ],
        default_host=settings.router_hostname, debug=args.debug,
        log_function=skip_request_logging
    )
    mount_health_handlers(site, settings)

    # Public websocket server
    proto = "wss" if args.ssl_key else "ws"
    factory = WebSocketServerFactory(
        "%s://%s:%s/" % (proto, args.hostname, args.port),
        debug=args.debug,
        debugCodePaths=args.debug,
    )
    factory.protocol = PushServerProtocol
    factory.protocol.ap_settings = settings
    factory.setProtocolOptions(
        webStatus=False,
        maxFramePayloadSize=args.max_message_size,
        maxMessagePayloadSize=args.max_message_size,
        openHandshakeTimeout=5,
        autoPingInterval=args.auto_ping_interval,
        autoPingTimeout=args.auto_ping_timeout,
        maxConnections=args.max_connections,
        closeHandshakeTimeout=args.close_handshake_timeout,
    )
    settings.factory = factory

    settings.metrics.start()

    # Wrap the WebSocket server in a default resource that exposes the
    # `/status` handler, and delegates to the WebSocket resource for all
    # other requests.
    resource = DefaultResource(WebSocketResource(factory))
    resource.putChild("status", StatusResource())
    siteFactory = Site(resource)

    # Start the WebSocket listener.
    if args.ssl_key:
        contextFactory = AutopushSSLContextFactory(args.ssl_key,
                                                   args.ssl_cert)
        if args.ssl_dh_param:
            contextFactory.getContext().load_tmp_dh(args.ssl_dh_param)

        reactor.listenSSL(args.port, siteFactory, contextFactory)
    else:
        reactor.listenTCP(args.port, siteFactory)

    # Start the internal routing listener.
    if args.router_ssl_key:
        contextFactory = AutopushSSLContextFactory(args.router_ssl_key,
                                                   args.router_ssl_cert)
        if args.ssl_dh_param:
            contextFactory.getContext().load_tmp_dh(args.ssl_dh_param)
        reactor.listenSSL(args.router_port, site, contextFactory)
    else:
        reactor.listenTCP(args.router_port, site)

    reactor.suggestThreadPoolSize(50)

    l = task.LoopingCall(periodic_reporter, settings)
    l.start(1.0)

    # Start the table rotation checker/updater
    l = task.LoopingCall(settings.update_rotating_tables)
    l.start(60)
    reactor.run()
コード例 #10
0
ファイル: main.py プロジェクト: martinthomson/autopush
    reactor.run()


def endpoint_main(sysargs=None):
    """Main entry point to setup an endpoint node, aka the autoendpoint
    script"""
    args, parser = _parse_endpoint(sysargs)
    senderid_list = None
    if args.senderid_list:
        try:
            senderid_list = json.loads(args.senderid_list)
        except (ValueError, TypeError), x:
            log.err("Invalid JSON specified for senderid_list.", x)
            return

    setup_logging("Autoendpoint", args.human_logs)

    settings = make_settings(
        args,
        endpoint_scheme=args.endpoint_scheme,
        endpoint_hostname=args.endpoint_hostname or args.hostname,
        endpoint_port=args.endpoint_port,
        enable_cors=not args.no_cors,
        s3_bucket=args.s3_bucket,
        senderid_expry=args.senderid_expry,
        senderid_list=senderid_list,
        auth_key=args.auth_key,
    )

    # Endpoint HTTP router
    site = cyclone.web.Application([
コード例 #11
0
ファイル: main.py プロジェクト: crodjer/autopush
def connection_main(sysargs=None):
    """Main entry point to setup a connection node, aka the autopush script"""
    args, parser = _parse_connection(sysargs)
    settings = make_settings(
        args,
        port=args.port,
        endpoint_scheme=args.endpoint_scheme,
        endpoint_hostname=args.endpoint_hostname,
        endpoint_port=args.endpoint_port,
        router_scheme="https" if args.router_ssl_key else "http",
        router_hostname=args.router_hostname,
        router_port=args.router_port,
    )
    setup_logging("Autopush")

    r = RouterHandler
    r.ap_settings = settings
    n = NotificationHandler
    n.ap_settings = settings

    # Internal HTTP notification router
    site = cyclone.web.Application([
        (r"/push/([^\/]+)", r),
        (r"/notif/([^\/]+)(/([^\/]+))?", n),
    ],
        default_host=settings.router_hostname, debug=args.debug,
        log_function=skip_request_logging
    )
    mount_health_handlers(site, settings)

    # Public websocket server
    proto = "wss" if args.ssl_key else "ws"
    factory = WebSocketServerFactory(
        "%s://%s:%s/" % (proto, args.hostname, args.port),
        debug=args.debug,
        debugCodePaths=args.debug,
    )
    factory.protocol = SimplePushServerProtocol
    factory.protocol.ap_settings = settings
    factory.setProtocolOptions(
        webStatus=False,
        maxFramePayloadSize=2048,
        maxMessagePayloadSize=2048,
        openHandshakeTimeout=5,
        autoPingInterval=args.auto_ping_interval,
        autoPingTimeout=args.auto_ping_timeout,
        maxConnections=args.max_connections
    )
    settings.factory = factory

    settings.metrics.start()

    # Start the WebSocket listener.
    if args.ssl_key:
        contextFactory = AutopushSSLContextFactory(args.ssl_key,
                                                   args.ssl_cert)
        if args.ssl_dh_param:
            contextFactory.getContext().load_tmp_dh(args.ssl_dh_param)
        listenWS(factory, contextFactory)
    else:
        reactor.listenTCP(args.port, factory)

    # Start the internal routing listener.
    if args.router_ssl_key:
        contextFactory = AutopushSSLContextFactory(args.router_ssl_key,
                                                   args.router_ssl_cert)
        if args.ssl_dh_param:
            contextFactory.getContext().load_tmp_dh(args.ssl_dh_param)
        reactor.listenSSL(args.router_port, site, contextFactory)
    else:
        reactor.listenTCP(args.router_port, site)

    reactor.suggestThreadPoolSize(50)

    l = task.LoopingCall(periodic_reporter, settings)
    l.start(1.0)
    reactor.run()
コード例 #12
0
def connection_main(sysargs=None):
    """Main entry point to setup a connection node, aka the autopush script"""
    args, parser = _parse_connection(sysargs)
    setup_logging("Autopush", args.human_logs)
    settings = make_settings(
        args,
        port=args.port,
        endpoint_scheme=args.endpoint_scheme,
        endpoint_hostname=args.endpoint_hostname,
        endpoint_port=args.endpoint_port,
        router_scheme="https" if args.router_ssl_key else "http",
        router_hostname=args.router_hostname,
        router_port=args.router_port,
        env=args.env,
        hello_timeout=args.hello_timeout,
    )

    r = RouterHandler
    r.ap_settings = settings
    n = NotificationHandler
    n.ap_settings = settings

    # Internal HTTP notification router
    site = cyclone.web.Application([
        (r"/push/([^\/]+)", r),
        (r"/notif/([^\/]+)(/([^\/]+))?", n),
    ],
                                   default_host=settings.router_hostname,
                                   debug=args.debug,
                                   log_function=skip_request_logging)
    mount_health_handlers(site, settings)

    # Public websocket server
    proto = "wss" if args.ssl_key else "ws"
    factory = WebSocketServerFactory(
        "%s://%s:%s/" % (proto, args.hostname, args.port),
        debug=args.debug,
        debugCodePaths=args.debug,
    )
    factory.protocol = PushServerProtocol
    factory.protocol.ap_settings = settings
    factory.setProtocolOptions(
        webStatus=False,
        maxFramePayloadSize=args.max_message_size,
        maxMessagePayloadSize=args.max_message_size,
        openHandshakeTimeout=5,
        autoPingInterval=args.auto_ping_interval,
        autoPingTimeout=args.auto_ping_timeout,
        maxConnections=args.max_connections,
        closeHandshakeTimeout=args.close_handshake_timeout,
    )
    settings.factory = factory

    settings.metrics.start()

    # Wrap the WebSocket server in a default resource that exposes the
    # `/status` handler, and delegates to the WebSocket resource for all
    # other requests.
    resource = DefaultResource(WebSocketResource(factory))
    resource.putChild("status", StatusResource())
    siteFactory = Site(resource)

    # Start the WebSocket listener.
    if args.ssl_key:
        contextFactory = AutopushSSLContextFactory(args.ssl_key, args.ssl_cert)
        if args.ssl_dh_param:
            contextFactory.getContext().load_tmp_dh(args.ssl_dh_param)

        reactor.listenSSL(args.port, siteFactory, contextFactory)
    else:
        reactor.listenTCP(args.port, siteFactory)

    # Start the internal routing listener.
    if args.router_ssl_key:
        contextFactory = AutopushSSLContextFactory(args.router_ssl_key,
                                                   args.router_ssl_cert)
        if args.ssl_dh_param:
            contextFactory.getContext().load_tmp_dh(args.ssl_dh_param)
        reactor.listenSSL(args.router_port, site, contextFactory)
    else:
        reactor.listenTCP(args.router_port, site)

    reactor.suggestThreadPoolSize(50)

    l = task.LoopingCall(periodic_reporter, settings)
    l.start(1.0)
    reactor.run()
コード例 #13
0
def endpoint_main(sysargs=None):
    """Main entry point to setup an endpoint node, aka the autoendpoint
    script"""
    args, parser = _parse_endpoint(sysargs)
    scheme = args.endpoint_scheme or \
        "https" if args.ssl_key else "http"
    senderid_list = None
    if args.senderid_list:
        try:
            senderid_list = json.loads(args.senderid_list)
        except (ValueError, TypeError), x:
            log.err("Invalid JSON specified for senderid_list.", x)
            return

    setup_logging("Autoendpoint", args.human_logs)

    settings = make_settings(
        args,
        endpoint_scheme=scheme,
        endpoint_hostname=args.endpoint_hostname or args.hostname,
        endpoint_port=args.port,
        enable_cors=not args.no_cors,
        s3_bucket=args.s3_bucket,
        senderid_expry=args.senderid_expry,
        senderid_list=senderid_list,
    )

    # Endpoint HTTP router
    site = cyclone.web.Application(
        [