Exemplo n.º 1
0
def Delete(name, creds, transport):
  """Delete a tag or digest.

  Args:
    name: a docker_name.{Tag,Digest} to be deleted.
    creds: the docker_creds to use for deletion.
    transport: the transport to use to contact the registry.
  """
  docker_transport = docker_http.Transport(
      name, creds, transport, docker_http.DELETE)

  if isinstance(name, docker_name.Tag):
    entity = name.tag
  else:
    assert isinstance(name, docker_name.Digest)
    entity = name.digest

  resp, unused_content = docker_transport.Request(
      '{scheme}://{registry}/v2/{repository}/manifests/{entity}'.format(
          scheme=docker_http.Scheme(name.registry),
          registry=name.registry,
          repository=name.repository,
          entity=entity),
      method='DELETE',
      accepted_codes=[httplib.OK])
Exemplo n.º 2
0
    def _content(self, suffix):
        """Fetches content of the resources from registry by http calls."""
        if isinstance(self._name, docker_name.Repository):
            suffix = '{repository}/{suffix}'.format(
                repository=self._name.repository, suffix=suffix)

        if suffix not in self._response:
            _, self._response[suffix] = self._transport.Request(
                '{scheme}://{registry}/v2/{suffix}'.format(
                    scheme=docker_http.Scheme(self._name.registry),
                    registry=self._name.registry,
                    suffix=suffix),
                accepted_codes=[httplib.OK])
        return self._response[suffix]
Exemplo n.º 3
0
    def blob_size(self, digest):
        """The byte size of the raw blob."""
        suffix = 'blobs/' + digest
        if isinstance(self._name, docker_name.Repository):
            suffix = '{repository}/{suffix}'.format(
                repository=self._name.repository, suffix=suffix)

        resp, unused_content = self._transport.Request(
            '{scheme}://{registry}/v2/{suffix}'.format(
                scheme=docker_http.Scheme(self._name.registry),
                registry=self._name.registry,
                suffix=suffix),
            method='HEAD',
            accepted_codes=[httplib.OK])

        return int(resp['content-length'])
Exemplo n.º 4
0
  def _content(self, suffix, cache = True):
    """Fetches content of the resources from registry by http calls."""
    if isinstance(self._name, docker_name.Repository):
      suffix = '{repository}/{suffix}'.format(
          repository=self._name.repository, suffix=suffix)

    if suffix in self._response:
      return self._response[suffix]

    _, content = self._transport.Request(
        '{scheme}://{registry}/v2/{suffix}'.format(
            scheme=docker_http.Scheme(self._name.registry),
            registry=self._name.registry,
            suffix=suffix),
        accepted_codes=[six.moves.http_client.OK])
    if cache:
      self._response[suffix] = content
    return content
Exemplo n.º 5
0
def Delete(name, creds, transport):
    """Delete a tag or digest.

  Args:
    name: a tag or digest to be deleted.
    creds: the credentials to use for deletion.
    transport: the transport to use to contact the registry.
  """
    docker_transport = docker_http.Transport(name, creds, transport,
                                             docker_http.DELETE)

    _, unused_content = docker_transport.Request(
        '{scheme}://{registry}/v2/{repository}/manifests/{entity}'.format(
            scheme=docker_http.Scheme(name.registry),
            registry=name.registry,
            repository=name.repository,
            entity=_tag_or_digest(name)),
        method='DELETE',
        accepted_codes=[httplib.OK, httplib.ACCEPTED])
Exemplo n.º 6
0
  def catalog(self, page_size=100):
    # TODO(user): Handle docker_name.Repository for /v2/<name>/_catalog
    if isinstance(self._name, docker_name.Repository):
      raise ValueError('Expected docker_name.Registry for "name"')

    url = '{scheme}://{registry}/v2/_catalog?n={page_size}'.format(
        scheme=docker_http.Scheme(self._name.registry),
        registry=self._name.registry,
        page_size=page_size)

    for _, content in self._transport.PaginatedRequest(
        url, accepted_codes=[httplib.OK]):
      wrapper_object = json.loads(content)

      if 'repositories' not in wrapper_object:
        raise docker_http.BadStateException(
            'Malformed JSON response: %s' % content)

      for repo in wrapper_object['repositories']:
        yield repo
Exemplo n.º 7
0
 def _scheme_and_host(self):
   return '{scheme}://{registry}'.format(
       scheme=docker_http.Scheme(self._name.registry),
       registry=self._name.registry)
Exemplo n.º 8
0
 def _base_url(self):
   return '{scheme}://{registry}/v2/{repository}'.format(
       scheme=docker_http.Scheme(self._name.registry),
       registry=self._name.registry,
       repository=self._name.repository)