Exemple #1
0
    def _ProbeObjectAccessWithClient(self, key, client_email, gcs_path, logger,
                                     region):
        """Performs a head request against a signed url to check for read access."""

        # Choose a reasonable time in the future; if the user's system clock is
        # 60 or more seconds behind the server's this will generate an error.
        signed_url = _GenSignedUrl(key, client_email, 'HEAD',
                                   timedelta(seconds=60), gcs_path, logger,
                                   region)

        try:
            h = GetNewHttp()
            req = Request(signed_url, 'HEAD')
            response = MakeRequest(h, req)

            if response.status_code not in [200, 403, 404]:
                raise HttpError.FromResponse(response)

            return response.status_code
        except HttpError as http_error:
            if http_error.has_attr('response'):
                error_response = http_error.response
                error_string = (
                    'Unexpected HTTP response code %s while querying '
                    'object readability. Is your system clock accurate?' %
                    error_response.status_code)
                if error_response.content:
                    error_string += ' Content: %s' % error_response.content
            else:
                error_string = (
                    'Expected an HTTP response code of '
                    '200 while querying object readability, but received '
                    'an error: %s' % http_error)
            raise CommandException(error_string)
Exemple #2
0
    def _ProbeObjectAccessWithClient(self, key, client_email, gcs_path,
                                     logger):
        """Performs a head request against a signed url to check for read access."""

        # Choose a reasonable time in the future; if the user's system clock is
        # 60 or more seconds behind the server's this will generate an error.
        signed_url = _GenSignedUrl(key, client_email, 'HEAD', '', '',
                                   int(time.time()) + 60, gcs_path, logger)

        try:
            h = GetNewHttp()
            req = Request(signed_url, 'HEAD')
            response = MakeRequest(h, req)

            if response.status_code not in [200, 403, 404]:
                raise HttpError.FromResponse(response)

            return response.status_code
        except HttpError:
            error_string = (
                'Unexpected HTTP response code %s while querying '
                'object readability. Is your system clock accurate?' %
                response.status_code)
            if response.content:
                error_string += ' Content: %s' % response.content
            raise CommandException(error_string)
Exemple #3
0
  def _ProbeObjectAccessWithClient(self, key, client_email, gcs_path):
    """Performs a head request against a signed url to check for read access."""

    signed_url = _GenSignedUrl(key, client_email, 'HEAD', '', '',
                               int(time.time()) + 10, gcs_path)

    try:
      h = GetNewHttp()
      req = Request(signed_url, 'HEAD')
      response = MakeRequest(h, req)

      if response.status_code not in [200, 403, 404]:
        raise HttpError(response)

      return response.status_code
    except HttpError as e:
      raise CommandException('Unexpected response code while querying'
                             'object readability ({0})'.format(e.message))