예제 #1
0
    def get_client_binary_info(self, instance, filename=None):
        """Returns URL to the client binary, its SHA1 hash and size.

    Used to get a direct URL to a client executable file. The file itself is
    uploaded by processing.ExtractCIPDClientProcessor step applied to packages
    for which client.is_cipd_client_package returns True ('infra/tools/cipd/*').

    Args:
      instance: PackageInstance entity corresponding to some registered and
          processed cipd client package.
      filename: if given, will be used to construct Content-Disposition header
          returned when fetching the binary. User agents are expected to name
          the downloaded file after the name specified here.

    Returns:
      Tuple (ClientBinaryInfo, error message) where:
        a) ClientBinaryInfo is not None, error message is None on success.
        b) ClientBinaryInfo is None, error message is not None on error.
        c) Both items are None if client binary is still being extracted.
    """
        assert client.is_cipd_client_package(instance.package_name)
        assert self.is_fetch_configured()
        processing_result = self.get_processing_result(
            instance.package_name, instance.instance_id,
            client.CIPD_BINARY_EXTRACT_PROCESSOR)
        if processing_result is None:
            return None, None
        if not processing_result.success:
            return None, 'Failed to extract the binary: %s' % processing_result.error
        # See processing.ExtractCIPDClientProcessor for code that puts this data.
        # CIPD_BINARY_EXTRACT_PROCESSOR includes a version number that is bumped
        # whenever format of the data changes, so assume the data is correct.
        data = processing_result.result.get('client_binary')
        assert isinstance(data['size'], (int, long))
        assert data['hash_algo'] == 'SHA1'
        assert cas.is_valid_hash_digest('SHA1', data['hash_digest'])
        fetch_url = self.cas_service.generate_fetch_url('SHA1',
                                                        data['hash_digest'],
                                                        filename=filename)
        return ClientBinaryInfo(sha1=data['hash_digest'],
                                size=data['size'],
                                fetch_url=fetch_url), None
예제 #2
0
  def get_client_binary_info(self, instance):
    """Returns URL to the client binary, its SHA1 hash and size.

    Used to get a direct URL to a client executable file. The file itself is
    uploaded by processing.ExtractCIPDClientProcessor step applied to packages
    for which client.is_cipd_client_package returns True ('infra/tools/cipd/*').

    Args:
      instance: PackageInstance entity corresponding to some registered and
          processed cipd client package.

    Returns:
      Tuple (ClientBinaryInfo, error message) where:
        a) ClientBinaryInfo is not None, error message is None on success.
        b) ClientBinaryInfo is None, error message is not None on error.
        c) Both items are None if client binary is still being extracted.
    """
    assert client.is_cipd_client_package(instance.package_name)
    assert self.is_fetch_configured()
    processing_result = self.get_processing_result(
        instance.package_name,
        instance.instance_id,
        client.CIPD_BINARY_EXTRACT_PROCESSOR)
    if processing_result is None:
      return None, None
    if not processing_result.success:
      return None, 'Failed to extract the binary: %s' % processing_result.error
    # See processing.ExtractCIPDClientProcessor for code that puts this data.
    # CIPD_BINARY_EXTRACT_PROCESSOR includes a version number that is bumped
    # whenever format of the data changes, so assume the data is correct.
    data = processing_result.result.get('client_binary')
    assert isinstance(data['size'], (int, long))
    assert data['hash_algo'] == 'SHA1'
    assert cas.is_valid_hash_digest('SHA1', data['hash_digest'])
    fetch_url = self.cas_service.generate_fetch_url('SHA1', data['hash_digest'])
    return ClientBinaryInfo(
        sha1=data['hash_digest'],
        size=data['size'],
        fetch_url=fetch_url), None
예제 #3
0
def is_valid_instance_id(instance_id):
    """True if string looks like a valid package instance ID."""
    return instance_id and cas.is_valid_hash_digest(DIGEST_ALGO, instance_id)
예제 #4
0
def is_valid_instance_id(instance_id):
  """True if string looks like a valid package instance ID."""
  return instance_id and cas.is_valid_hash_digest(DIGEST_ALGO, instance_id)