Exemplo n.º 1
0
def run_app():
    # configure logging level
    if settings.VERBOSE:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    ThunderRouter = SockJSRouter(ThunderSocketHandler, "/connect")
    urls = ThunderRouter.urls + api.urls
    application = tornado.web.Application(urls, settings.DEBUG)

    ss = SortingStation.instance()

    # Single-client only at the moment.
    ss.create_messenger(settings.APIKEY, settings.APISECRET)

    logger.info("Starting Thunderpush server at %s:%d", settings.HOST,
                settings.PORT)

    application.listen(settings.PORT, settings.HOST)

    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        logger.info("Shutting down...")
Exemplo n.º 2
0
def run_app():
    # configure logging level
    if settings.VERBOSE:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    ThunderRouter = SockJSRouter(ThunderSocketHandler, "/connect")
    urls = ThunderRouter.urls + api.urls
    application = tornado.web.Application(urls, settings.DEBUG)

    ss = SortingStation.instance()

    # Single-client only at the moment.
    ss.create_messenger(settings.APIKEY, settings.APISECRET)

    logger.info("Starting Thunderpush server at %s:%d",
                settings.HOST, settings.PORT)

    application.listen(settings.PORT, settings.HOST)

    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        logger.info("Shutting down...")
Exemplo n.º 3
0
    def handle_connect(self, args):
        if self.connected:
            logger.warning("User already connected.")
            return

        try:
            self.userid, self.apikey = args.split(":")
        except ValueError:
            logger.warning("Invalid message syntax.")
            return

        # get singleton instance of SortingStation
        ss = SortingStation.instance()

        # get and store the messenger object for given apikey
        self.messenger = ss.get_messenger_by_apikey(self.apikey)

        if self.messenger:
            self.messenger.register_user(self)
        else:
            logger.warning("Invalid API key.")

            # inform client that the key was not good
            self.send("WRONGKEY")
            self.close()
Exemplo n.º 4
0
def run_app():
    # configure logging level
    if settings.VERBOSE:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    ThunderRouter = SockJSRouter(ThunderSocketHandler, "/connect")

    # api urls
    urls = [
        (r"/api/1\.0\.0/(?P<apikey>.+)/users/",
            api.UserCountHandler),
        (r"/api/1\.0\.0/(?P<apikey>.+)/users/(?P<user>.+)/",
            api.UserHandler),
        (r"/api/1\.0\.0/(?P<apikey>.+)/channels/(?P<channel>.+)/",
            api.ChannelHandler),
    ]

    # include sockjs urls
    urls += ThunderRouter.urls

    application = tornado.web.Application(urls, settings.DEBUG)

    ss = SortingStation()

    # Single-client only at the moment.
    ss.create_messenger(settings.APIKEY, settings.APISECRET)
    
    #ss.create_messenger("user374", "1234")
    
    #ss.import_messenger()    

    logger.info("Starting Thunderpush server at %s:%d",
        settings.HOST, settings.PORT)

    application.listen(settings.PORT, settings.HOST)

    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        logger.info("Shutting down...")
Exemplo n.º 5
0
 def setUp(self):
     super(APITestCase, self).setUp()
     self.user1 = DummyThunderSocketHandler()
     self.user2 = DummyThunderSocketHandler()
     self.messenger = SortingStation.instance().create_messenger(
         API_PUBLIC, API_SECRET)
     self.messenger.register_user(self.user1)
     self.messenger.register_user(self.user2)
     self.messenger.subscribe_user_to_channel(self.user1, 'test1')
     self.messenger.subscribe_user_to_channel(self.user2, 'test1')
     self.messenger.subscribe_user_to_channel(self.user1, 'test2')
Exemplo n.º 6
0
    def run_check(self, *args, **kwargs):
        ss = SortingStation.instance()
        apikey = kwargs.pop('apikey', None)
        apisecret = self.request.headers.get('X-Thunder-Secret-Key', None)
        messenger = ss.get_messenger_by_apikey(apikey)

        if not messenger or apisecret != messenger.apisecret:
            self.error('Wrong API key/secret.', 401)
            return

        f(self, *args, messenger=messenger, **kwargs)
Exemplo n.º 7
0
    def run_check(self, *args, **kwargs):
        ss = SortingStation.instance()
        apikey = kwargs.pop('apikey', None)
        apisecret = self.request.headers.get('X-Thunder-Secret-Key', None)
        messenger = ss.get_messenger_by_apikey(apikey)

        if not messenger or apisecret != messenger.apisecret:
            self.error('Wrong API key/secret.', 401)
            return

        f(self, *args, messenger=messenger, **kwargs)
Exemplo n.º 8
0
 def setUp(self):
     super(APITestCase, self).setUp()
     self.user1 = DummyThunderSocketHandler()
     self.user2 = DummyThunderSocketHandler()
     self.messenger = SortingStation.instance().create_messenger(
         API_PUBLIC, API_SECRET
     )
     self.messenger.register_user(self.user1)
     self.messenger.register_user(self.user2)
     self.messenger.subscribe_user_to_channel(self.user1, "test1")
     self.messenger.subscribe_user_to_channel(self.user2, "test1")
     self.messenger.subscribe_user_to_channel(self.user1, "test2")
Exemplo n.º 9
0
def run_app():
    # configure logging level
    if settings.VERBOSE:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    ThunderRouter = SockJSRouter(ThunderSocketHandler, "/connect")

    # api urls
    urls = [
        (r"/api/1\.0\.0/(?P<apikey>.+)/users/",
            api.UserCountHandler),
        (r"/api/1\.0\.0/(?P<apikey>.+)/users/(?P<user>.+)/",
            api.UserHandler),
        (r"/api/1\.0\.0/(?P<apikey>.+)/channels/(?P<channel>.+)/",
            api.ChannelHandler),
    ]

    # include sockjs urls
    urls += ThunderRouter.urls

    application = tornado.web.Application(urls, settings.DEBUG)

    ss = SortingStation()

    # Single-client only at the moment.
    ss.create_messenger(settings.APIKEY, settings.APISECRET)

    logger.info("Starting Thunderpush server at %s:%d",
        settings.HOST, settings.PORT)

    application.listen(settings.PORT, settings.HOST)

    try:
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        logger.info("Shutting down...")
Exemplo n.º 10
0
    def run_check(self, *args, **kwargs):
        ss = SortingStation.instance()

        apisecret = self.request.headers.get('X-Thunder-Secret-Key', None)
        messenger = ss.get_messenger_by_apikey(kwargs['apikey'])

        if not messenger or apisecret != messenger.apisecret:  
            self.error("Wrong API key/secret.", 401)
            return

        # pass messenger instance to handler
        kwargs['messenger'] = messenger

        f(self, *args, **kwargs)
Exemplo n.º 11
0
    def run_check(self, *args, **kwargs):
        ss = SortingStation.instance()

        apisecret = self.request.headers.get('X-Thunder-Secret-Key', None)
        messenger = ss.get_messenger_by_apikey(kwargs['apikey'])

        if not messenger or apisecret != messenger.apisecret:
            self.error("Wrong API key/secret.", 401)
            return

        # pass messenger instance to handler
        kwargs['messenger'] = messenger

        f(self, *args, **kwargs)
Exemplo n.º 12
0
    def handle_connect(self, args):
        if self.connected:
            logger.warning("User already connected.")
            return

        try:
            self.userid, self.apikey = args.split(":")
        except ValueError:
            logger.warning("Invalid message syntax.")
            return

        # get singleton instance of SortingStation
        ss = SortingStation.instance()

        # get and store the messenger object for given apikey
        self.messenger = ss.get_messenger_by_apikey(self.apikey)

        if self.messenger:
            self.messenger.register_user(self)
        else:
            self.close(9000, "Invalid API key.")
Exemplo n.º 13
0
    def handle_connect(self, args):
        if self.connected:
            logger.warning('User already connected.')
            return

        try:
            self.userid, self.apikey = args.split(':')
        except ValueError:
            logger.warning('Invalid message syntax.')
            return

        # get singleton instance of SortingStation
        ss = SortingStation.instance()

        # get and store the messenger object for given apikey
        self.messenger = ss.get_messenger_by_apikey(self.apikey)

        if self.messenger:
            self.messenger.register_user(self)
        else:
            self.close(9000, 'Invalid API key.')
Exemplo n.º 14
0
 def tearDown(self):
     super(APITestCase, self).tearDown()
     SortingStation.instance().delete_messenger(self.messenger)
Exemplo n.º 15
0
 def tearDown(self):
     super(APITestCase, self).tearDown()
     SortingStation.instance().delete_messenger(self.messenger)