コード例 #1
0
    def _get_rpc_or_rest(self, api_format, request, start_response):
        """Sends back HTTP response with API directory.

    This calls start_response and returns the response body.  It will return
    the discovery doc for the requested api/version.

    Args:
      api_format: A string containing either 'rest' or 'rpc'.
      request: An ApiRequest, the transformed request sent to the Discovery SPI.
      start_response: A function with semantics defined in PEP-333.

    Returns:
      A string, the response body.
    """
        api = request.body_json['api']
        version = request.body_json['version']
        lookup_key = (api, version)
        api_config = self._config_manager.configs.get(lookup_key)
        if not api_config:
            logging.warn('No discovery doc for version %s of api %s', version,
                         api)
            return util.send_wsgi_not_found_response(start_response)
        doc = self._discovery_proxy.generate_discovery_doc(
            api_config, api_format)
        if not doc:
            error_msg = ('Failed to convert .api to discovery doc for '
                         'version %s of api %s') % (version, api)
            logging.error('%s', error_msg)
            return util.send_wsgi_error_response(error_msg, start_response)
        return self._send_success_response(doc, start_response)
コード例 #2
0
  def _get_rpc_or_rest(self, api_format, request, start_response):
    """Sends back HTTP response with API directory.

    This calls start_response and returns the response body.  It will return
    the discovery doc for the requested api/version.

    Args:
      api_format: A string containing either 'rest' or 'rpc'.
      request: An ApiRequest, the transformed request sent to the Discovery SPI.
      start_response: A function with semantics defined in PEP-333.

    Returns:
      A string, the response body.
    """
    api = request.body_json['api']
    version = request.body_json['version']
    lookup_key = (api, version)
    api_config = self._config_manager.configs.get(lookup_key)
    if not api_config:
      logging.warn('No discovery doc for version %s of api %s', version, api)
      return util.send_wsgi_not_found_response(start_response)
    doc = self._discovery_proxy.generate_discovery_doc(api_config, api_format)
    if not doc:
      error_msg = ('Failed to convert .api to discovery doc for '
                   'version %s of api %s') % (version, api)
      logging.error('%s', error_msg)
      return util.send_wsgi_error_response(error_msg, start_response)
    return self._send_success_response(doc, start_response)
コード例 #3
0
  def call_spi(self, orig_request, start_response):
    """Generate SPI call (from earlier-saved request).

    This calls start_response and returns the response body.

    Args:
      orig_request: An ApiRequest, the original request from the user.
      start_response: A function with semantics defined in PEP-333.

    Returns:
      A string containing the response body.
    """
    if orig_request.is_rpc():
      method_config = self.lookup_rpc_method(orig_request)
      params = None
    else:
      method_config, params = self.lookup_rest_method(orig_request)
    if not method_config:
      cors_handler = EndpointsDispatcher.__CheckCorsHeaders(orig_request)
      return util.send_wsgi_not_found_response(start_response,
                                               cors_handler=cors_handler)

    # Prepare the request for the back end.
    try:
      spi_request = self.transform_request(orig_request, params, method_config)
    except errors.RequestRejectionError, rejection_error:
      cors_handler = EndpointsDispatcher.__CheckCorsHeaders(orig_request)
      return util.send_wsgi_rejected_response(rejection_error, start_response,
                                              cors_handler=cors_handler)
コード例 #4
0
    def call_spi(self, orig_request, start_response):
        """Generate SPI call (from earlier-saved request).

    This calls start_response and returns the response body.

    Args:
      orig_request: An ApiRequest, the original request from the user.
      start_response: A function with semantics defined in PEP-333.

    Returns:
      A string containing the response body.
    """
        if orig_request.is_rpc():
            method_config = self.lookup_rpc_method(orig_request)
            params = None
        else:
            method_config, params = self.lookup_rest_method(orig_request)
        if not method_config:
            cors_handler = EndpointsDispatcher.__CheckCorsHeaders(orig_request)
            return util.send_wsgi_not_found_response(start_response,
                                                     cors_handler=cors_handler)

        # Prepare the request for the back end.
        spi_request = self.transform_request(orig_request, params,
                                             method_config)

        # Check if this SPI call is for the Discovery service.  If so, route
        # it to our Discovery handler.
        discovery = discovery_service.DiscoveryService(self.config_manager)
        discovery_response = discovery.handle_discovery_request(
            spi_request.path, spi_request, start_response)
        if discovery_response:
            return discovery_response

        # Send the request to the user's SPI handlers.
        url = _SPI_ROOT_FORMAT % spi_request.path
        spi_request.headers['Content-Type'] = 'application/json'
        response = self._dispatcher.add_request('POST', url,
                                                spi_request.headers.items(),
                                                spi_request.body,
                                                spi_request.source_ip)
        return self.handle_spi_response(orig_request, spi_request, response,
                                        start_response)
コード例 #5
0
ファイル: endpoints_server.py プロジェクト: AppScale/appscale
  def call_spi(self, orig_request, start_response):
    """Generate SPI call (from earlier-saved request).

    This calls start_response and returns the response body.

    Args:
      orig_request: An ApiRequest, the original request from the user.
      start_response: A function with semantics defined in PEP-333.

    Returns:
      A string containing the response body.
    """
    if orig_request.is_rpc():
      method_config = self.lookup_rpc_method(orig_request)
      params = None
    else:
      method_config, params = self.lookup_rest_method(orig_request)
    if not method_config:
      cors_handler = EndpointsDispatcher.__CheckCorsHeaders(orig_request)
      return util.send_wsgi_not_found_response(start_response,
                                               cors_handler=cors_handler)

    # Prepare the request for the back end.
    spi_request = self.transform_request(orig_request, params, method_config)

    # Check if this SPI call is for the Discovery service.  If so, route
    # it to our Discovery handler.
    discovery = discovery_service.DiscoveryService(self.config_manager)
    discovery_response = discovery.handle_discovery_request(
        spi_request.path, spi_request, start_response)
    if discovery_response:
      return discovery_response

    # Send the request to the user's SPI handlers.
    url = _SPI_ROOT_FORMAT % spi_request.path
    spi_request.headers['Content-Type'] = 'application/json'
    response = self._dispatcher.add_request('POST', url,
                                            spi_request.headers.items(),
                                            spi_request.body,
                                            spi_request.source_ip)
    return self.handle_spi_response(orig_request, spi_request, response,
                                    method_config, start_response)
コード例 #6
0
    def _list(self, start_response):
        """Sends HTTP response containing the API directory.

    This calls start_response and returns the response body.

    Args:
      start_response: A function with semantics defined in PEP-333.

    Returns:
      A string containing the response body.
    """
        api_configs = []
        for api_config in six.itervalues(self._config_manager.configs):
            if not api_config == self.API_CONFIG:
                api_configs.append(json.dumps(api_config))
        directory = self._discovery_proxy.generate_directory(api_configs)
        if not directory:
            logging.error('Failed to get API directory')
            # By returning a 404, code explorer still works if you select the
            # API in the URL
            return util.send_wsgi_not_found_response(start_response)
        return self._send_success_response(directory, start_response)
コード例 #7
0
  def _list(self, start_response):
    """Sends HTTP response containing the API directory.

    This calls start_response and returns the response body.

    Args:
      start_response: A function with semantics defined in PEP-333.

    Returns:
      A string containing the response body.
    """
    api_configs = []
    for api_config in self._config_manager.configs.values():
      if not api_config == self.API_CONFIG:
        api_configs.append(json.dumps(api_config))
    directory = self._discovery_proxy.generate_directory(api_configs)
    if not directory:
      logging.error('Failed to get API directory')
      # By returning a 404, code explorer still works if you select the
      # API in the URL
      return util.send_wsgi_not_found_response(start_response)
    return self._send_success_response(directory, start_response)