Esempio n. 1
0
  def __enter__(self):
    # This initiates the pull by issuing:
    #   GET H:P/v1/repositories/R/images
    resp, unused_content = docker_http.Request(
        self._transport,
        '{scheme}://{registry}/v1/repositories/{repository_name}/images'.format(
            scheme=docker_http.Scheme(self._name.registry),
            registry=self._name.registry,
            repository_name=self._name.repository),
        self._creds, [httplib.OK])

    # The response should have an X-Docker-Token header, which
    # we should extract and annotate subsequent requests with:
    #   Authorization: Token {extracted value}
    self._creds = v1_creds.Token(resp['x-docker-token'])

    self._endpoint = resp['x-docker-endpoints']
    # TODO(user): Consider also supporting cookies, which are
    # used by Quay.io for authenticated sessions.

    # Next, fetch the set of tags in this repository.
    #   GET server1/v1/repositories/R/tags
    resp, content = docker_http.Request(
        self._transport,
        '{scheme}://{endpoint}/v1/repositories/{repository_name}/tags'.format(
            scheme=docker_http.Scheme(self._endpoint),
            endpoint=self._endpoint,
            repository_name=self._name.repository),
        self._creds, [httplib.OK])

    self._tags = json.loads(content)
    return self
Esempio n. 2
0
    def __enter__(self):
        # This initiates the upload by issuing:
        #   PUT H:P/v1/repositories/R/
        # In that request, we specify the headers:
        #   Content-Type: application/json
        #   Authorization: Basic {base64 encoded auth token}
        #   X-Docker-Token: true
        resp, unused_content = docker_http.Request(
            self._transport,
            '{scheme}://{registry}/v1/repositories/{repository}/'.format(
                scheme=docker_http.Scheme(self._name.registry),
                registry=self._name.registry,
                repository=self._name.repository),
            self._basic_creds,
            accepted_codes=[httplib.OK, httplib.CREATED],
            body='[]')

        # The response should have an X-Docker-Token header, which
        # we should extract and annotate subsequent requests with:
        #   Authorization: Token {extracted value}
        self._token_creds = docker_creds.Token(resp['x-docker-token'])

        self._endpoint = resp['x-docker-endpoints']
        # TODO(user): Consider also supporting cookies, which are
        # used by Quay.io for authenticated sessions.

        logging.info('Initiated upload of: %s', self._name)
        return self
Esempio n. 3
0
 def _content(self, suffix):
   if suffix not in self._response:
     _, self._response[suffix] = docker_http.Request(
         self._transport, '{scheme}://{endpoint}/v1/images/{suffix}'.format(
             scheme=docker_http.Scheme(self._endpoint),
             endpoint=self._endpoint,
             suffix=suffix), self._creds, [httplib.OK])
   return self._response[suffix]
Esempio n. 4
0
 def _put_json(self, image, layer_id):
     """Upload the json for a single layer."""
     docker_http.Request(
         self._transport,
         '{scheme}://{endpoint}/v1/images/{layer}/json'.format(
             scheme=docker_http.Scheme(self._endpoint),
             endpoint=self._endpoint,
             layer=layer_id),
         self._token_creds,
         accepted_codes=[httplib.OK],
         body=image.json(layer_id))
Esempio n. 5
0
 def _exists(self, layer_id):
     """Check the remote for the given layer."""
     resp, unused_content = docker_http.Request(
         self._transport,
         '{scheme}://{endpoint}/v1/images/{layer}/json'.format(
             scheme=docker_http.Scheme(self._endpoint),
             endpoint=self._endpoint,
             layer=layer_id),
         self._token_creds,
         accepted_codes=[httplib.OK, httplib.NOT_FOUND])
     return resp.status == httplib.OK
Esempio n. 6
0
 def _put_images(self):
     """Close the session by putting to the .../images endpoint."""
     docker_http.Request(
         self._transport,
         '{scheme}://{registry}/v1/repositories/{repository}/images'.format(
             scheme=docker_http.Scheme(self._name.registry),
             registry=self._name.registry,
             repository=self._name.repository),
         self._basic_creds,
         accepted_codes=[httplib.NO_CONTENT],
         body='[]')
Esempio n. 7
0
 def _put_tag(self):
     """Upload the new value of the tag we are pushing."""
     docker_http.Request(
         self._transport,
         '{scheme}://{endpoint}/v1/repositories/{repository}/tags/{tag}'.
         format(scheme=docker_http.Scheme(self._endpoint),
                endpoint=self._endpoint,
                repository=self._name.repository,
                tag=self._name.tag),
         self._token_creds,
         accepted_codes=[httplib.OK],
         body='"%s"' % self._top)
Esempio n. 8
0
 def _put_layer(self, image, layer_id):
     """Upload the aufs tarball for a single layer."""
     # TODO(user): We should stream this instead of loading
     # it into memory.
     docker_http.Request(
         self._transport,
         '{scheme}://{endpoint}/v1/images/{layer}/layer'.format(
             scheme=docker_http.Scheme(self._endpoint),
             endpoint=self._endpoint,
             layer=layer_id),
         self._token_creds,
         accepted_codes=[httplib.OK],
         body=image.layer(layer_id),
         content_type='application/octet-stream')