Esempio n. 1
0
    def handle_rpc_request(self, request):
        """Handle common rpc request and return raw response.

        @param request: the rpc request to be processed.
        """
        remote_ip = self._get_remote_ip(request)
        user = models.User.current_user()
        json_request = self.raw_request_data(request)
        decoded_request = self.decode_request(json_request)

        # Validate whether method can be called by the remote_ip
        try:
            meth_id = decoded_request['id']
            meth_name = decoded_request['method']
            self._rpc_validator.validate_rpc_only_called_by_master(
                meth_name, remote_ip)
        except KeyError:
            raise serviceHandler.BadServiceRequest(decoded_request)
        except error.RPCException as e:
            return self._rpc_validator.encode_validate_result(meth_id, e)

        decoded_request['remote_ip'] = remote_ip
        decoded_result = self.dispatch_request(decoded_request)
        result = self.encode_result(decoded_result)
        if rpcserver_logging.LOGGING_ENABLED:
            self.log_request(user, decoded_request, decoded_result, remote_ip)
        return rpc_utils.raw_http_response(result)
Esempio n. 2
0
 def handle_rpc_request(self, request):
     user = models.User.current_user()
     json_request = self.raw_request_data(request)
     decoded_request = self.decode_request(json_request)
     decoded_result = self.dispatch_request(decoded_request)
     result = self.encode_result(decoded_result)
     if rpcserver_logging.LOGGING_ENABLED:
         self.log_request(user, decoded_request, decoded_result)
     return rpc_utils.raw_http_response(result)
Esempio n. 3
0
 def handle_rpc_request(self, request):
     user = models.User.current_user()
     json_request = self.raw_request_data(request)
     decoded_request = self.decode_request(json_request)
     decoded_result = self.dispatch_request(decoded_request)
     result = self.encode_result(decoded_result)
     if rpcserver_logging.LOGGING_ENABLED:
         self.log_request(user, decoded_request, decoded_result)
     return rpc_utils.raw_http_response(result)
    def handle_jsonp_rpc_request(self, request):
        request_data = request.GET['request']
        callback_name = request.GET['callback']
        # callback_name must be a simple identifier
        assert re.search(r'^\w+$', callback_name)

        result = self.execute_request(request_data)
        padded_result = '%s(%s)' % (callback_name, result)
        return rpc_utils.raw_http_response(padded_result,
                                           content_type='text/javascript')
Esempio n. 5
0
    def handle_jsonp_rpc_request(self, request):
        request_data = request.GET['request']
        callback_name = request.GET['callback']
        # callback_name must be a simple identifier
        assert re.search(r'^\w+$', callback_name)

        result = self.execute_request(request_data)
        padded_result = '%s(%s)' % (callback_name, result)
        return rpc_utils.raw_http_response(padded_result,
                                           content_type='text/javascript')
Esempio n. 6
0
    def encode_validate_result(self, meth_id, err):
        """Encode the return results for validator.

        It is used for encoding return response for RPC handler if caller of an
        RPC is refused by validator.

        @param meth_id: the id of the request for an RPC method.
        @param err: The error raised by validator.

        @return: a raw http response including the encoded error result. It
            will be parsed by service proxy.
        """
        error_result = serviceHandler.ServiceHandler.blank_result_dict()
        error_result['id'] = meth_id
        error_result['err'] = err
        error_result['err_traceback'] = traceback.format_exc()
        result = self.encode_result(error_result)
        return rpc_utils.raw_http_response(result)
Esempio n. 7
0
 def get_rpc_documentation(self):
     """Get raw response from an http documentation."""
     return rpc_utils.raw_http_response(self.html_doc)
 def get_rpc_documentation(self):
     return rpc_utils.raw_http_response(self.html_doc)
Esempio n. 9
0
 def encode(self):
     return rpc_utils.raw_http_response(
         'Unhandled method %s (this indicates a bug)\r\n' %
         self._request['method'])
Esempio n. 10
0
 def encode(self):
     return rpc_utils.raw_http_response(
         'Unhandled method %s (this indicates a bug)\r\n' %
         self._request['method'])
Esempio n. 11
0
 def get_rpc_documentation(self):
     return rpc_utils.raw_http_response(self.html_doc)