Пример #1
0
    def post(self):
        result, error = {}, None
        params = params_from_request(self.request)
        project = params.pop('project')
        method = params.pop('method')
        data = params.get('data')
        if data is not None:
            try:
                data = json_decode(data)
            except Exception as e:
                logger.error(e)
            else:
                params["data"] = data

        project = self.application.get_project(project)
        if not project:
            error = self.application.PROJECT_NOT_FOUND
        else:
            result, error = yield self.application.process_call(project, method, params)

        self.set_header("Content-Type", "application/json")
        self.finish(json_encode({
            "body": result,
            "error": error
        }))
Пример #2
0
    def handle_admin_message(self, message):
        message = json_encode(message)
        for uid, connection in six.iteritems(self.application.admin_connections):
            if uid not in self.application.admin_connections:
                continue
            connection.send(message)

        raise Return((True, None))
Пример #3
0
 def post(self):
     password = self.get_argument("password", None)
     if password and password == self.opts.get("password"):
         token = self.create_signed_value("token", "authorized")
         self.set_header("Content-Type", "application/json")
         self.finish(json_encode({"token": token}))
     else:
         raise tornado.web.HTTPError(400)
Пример #4
0
 def post(self):
     password = self.get_argument("password", None)
     if password and password == self.opts.get("password"):
         token = self.create_signed_value("token", "authorized")
         self.set_header("Content-Type", "application/json")
         self.finish(json_encode({"token": token}))
     else:
         raise tornado.web.HTTPError(400)
Пример #5
0
    def handle_admin_message(self, message):
        message = json_encode(message)
        for uid, connection in six.iteritems(
                self.application.admin_connections):
            if uid not in self.application.admin_connections:
                continue
            connection.send(message)

        raise Return((True, None))
Пример #6
0
 def set_flash_message(self, message, status='success'):
     """
     Stores a Flash object as a flash cookie under a given key.
     """
     flash = {
         'message': message,
         'status': status
     }
     self.set_secure_cookie(self.FLASH_COOKIE_NAME, json_encode(flash))
Пример #7
0
    def on_message(self, message):
        """
        The only method supported at moment - auth - used to
        authorize websocket connection.
        """
        try:
            data = json_decode(message)
        except ValueError:
            self.close()
            return

        try:
            method = data["method"]
            params = data["params"]
        except (TypeError, KeyError):
            self.close()
            return

        if method == "auth":
            try:
                token = params["token"]
            except (KeyError, TypeError):
                self.close()
                return
            else:
                user = decode_signed_value(
                    self.application.settings['cookie_secret'], 'token', token
                )
                if user:
                    self.subscribe()
                    self.send(json_encode({
                        "method": "auth",
                        "body": True
                    }))
                else:
                    self.send(json_encode({
                        "method": "auth",
                        "body": False
                    }))
                    self.close()
                    return
        else:
            self.close()
            return
Пример #8
0
 def get(self):
     projects, error = yield self.application.structure.project_list()
     if error:
         raise tornado.web.HTTPError(500, log_message=str(error))
     namespaces, error = yield self.application.structure.namespace_list()
     if error:
         raise tornado.web.HTTPError(500, log_message=str(error))
     data = {"projects": projects, "namespaces": namespaces}
     self.set_header("Content-Type", "application/json")
     self.finish(json_encode(data))
Пример #9
0
 def get(self):
     projects, error = yield self.application.structure.project_list()
     if error:
         raise tornado.web.HTTPError(500, log_message=str(error))
     namespaces, error = yield self.application.structure.namespace_list()
     if error:
         raise tornado.web.HTTPError(500, log_message=str(error))
     data = {
         "projects": projects,
         "namespaces": namespaces
     }
     self.set_header("Content-Type", "application/json")
     self.finish(json_encode(data))
Пример #10
0
 def get(self):
     config = self.application.settings.get("config", {})
     metrics_interval = config.get("metrics", {}).get("interval", self.application.METRICS_EXPORT_INTERVAL) * 1000
     context = {
         "structure": self.application.structure,
         "metrics_interval": metrics_interval,
         "version": centrifuge.__version__,
         "nodes": self.application.nodes,
         "engine": getattr(self.application.engine, "NAME", "unknown"),
         "node_name": self.application.name,
     }
     self.set_header("Content-Type", "application/json")
     self.finish(json_encode(context))
Пример #11
0
 def get(self):
     config = self.application.settings.get('config', {})
     metrics_interval = config.get('metrics', {}).get(
         'interval', self.application.METRICS_EXPORT_INTERVAL)*1000
     context = {
         'structure':  self.application.structure,
         'metrics_interval': metrics_interval,
         'version': centrifuge.__version__,
         'nodes': self.application.nodes,
         'engine': getattr(self.application.engine, 'NAME', 'unknown'),
         'node_name': self.application.name
     }
     self.set_header("Content-Type", "application/json")
     self.finish(json_encode(context))
Пример #12
0
 def add_history_message(self, project_key, channel, message, history_size, history_lifetime):
     history_list_key = self.get_history_list_key(project_key, channel)
     try:
         pipeline = self.worker.pipeline()
         pipeline.lpush(history_list_key, json_encode(message))
         pipeline.ltrim(history_list_key, 0, history_size - 1)
         if history_lifetime:
             pipeline.expire(history_list_key, history_lifetime)
         else:
             pipeline.persist(history_list_key)
         yield Task(pipeline.send)
     except StreamClosedError as e:
         raise Return((None, e))
     else:
         raise Return((True, None))
Пример #13
0
 def add_history_message(self, project_id, channel, message, history_size=None, history_expire=0):
     history_size = history_size or self.history_size
     history_list_key = self.get_history_list_key(project_id, channel)
     try:
         pipeline = self.worker.pipeline()
         pipeline.lpush(history_list_key, json_encode(message))
         pipeline.ltrim(history_list_key, 0, history_size - 1)
         if history_expire:
             pipeline.expire(history_list_key, history_expire)
         else:
             pipeline.persist(history_list_key)
         yield Task(pipeline.send)
     except StreamClosedError as e:
         raise Return((None, e))
     else:
         raise Return((True, None))
Пример #14
0
 def add_presence(self, project_id, channel, uid, user_info, presence_timeout=None):
     now = int(time.time())
     expire_at = now + (presence_timeout or self.presence_timeout)
     hash_key = self.get_presence_hash_key(project_id, channel)
     set_key = self.get_presence_set_key(project_id, channel)
     try:
         pipeline = self.worker.pipeline()
         pipeline.multi()
         pipeline.zadd(set_key, {uid: expire_at})
         pipeline.hset(hash_key, uid, json_encode(user_info))
         pipeline.execute()
         yield Task(pipeline.send)
     except StreamClosedError as e:
         raise Return((None, e))
     else:
         raise Return((True, None))
Пример #15
0
    def post_actions(self):
        params = params_from_request(self.request)
        method = params.pop('method')
        params.pop('_xsrf')
        data = params.get('data', None)
        if data is not None:
            try:
                data = json_decode(data)
            except Exception as e:
                logger.error(e)
            else:
                params["data"] = data

        result, error = yield self.application.process_call(
            self.project, method, params)

        self.set_header("Content-Type", "application/json")
        self.finish(json_encode({"body": result, "error": error}))
Пример #16
0
    def post_actions(self):
        params = params_from_request(self.request)
        method = params.pop('method')
        params.pop('_xsrf')
        data = params.get('data', None)
        if data is not None:
            try:
                data = json_decode(data)
            except Exception as e:
                logger.error(e)
            else:
                params["data"] = data

        result, error = yield self.application.process_call(self.project, method, params)

        self.set_header("Content-Type", "application/json")
        self.finish(json_encode({
            "body": result,
            "error": error
        }))
Пример #17
0
 def as_message(self):
     return json_encode(self.as_dict())
Пример #18
0
 def set_flash_message(self, message, status='success'):
     """
     Stores a Flash object as a flash cookie under a given key.
     """
     flash = {'message': message, 'status': status}
     self.set_secure_cookie(self.FLASH_COOKIE_NAME, json_encode(flash))
Пример #19
0
 def as_message(self):
     return json_encode(self.as_dict())
Пример #20
0
 def as_message(self):
     return json_encode(self.as_list_of_dicts())
Пример #21
0
 def publish_admin_message(self, message):
     result = self._publish(self.admin_channel_name, json_encode(message))
     raise Return((result, None))
Пример #22
0
 def publish_admin_message(self, message):
     result = self._publish(self.admin_channel_name, json_encode(message))
     raise Return((result, None))
Пример #23
0
 def as_message(self):
     return json_encode(self.as_list_of_dicts())