예제 #1
0
파일: update_deps.py 프로젝트: 0x1Fu/bazel
def main():
    args = parser.parse_args()

    creds = docker_creds.Anonymous()
    transport = httplib2.Http()

    repo = docker_name.Repository(args.repository)

    latest = docker_name.Tag(str(repo) + ":latest")
    with docker_image.FromRegistry(latest, creds, transport) as img:
        latest_digest = img.digest()

    debug = docker_name.Tag(str(repo) + ":debug")
    with docker_image.FromRegistry(debug, creds, transport) as img:
        if img.exists():
            debug_digest = img.digest()
        else:
            debug_digest = latest_digest

    with open(args.output, 'w') as f:
        f.write("""\
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
\"\"\" Generated file with dependencies for language rule.\"\"\"

# !!!! THIS IS A GENERATED FILE TO NOT EDIT IT BY HAND !!!!
#
# To regenerate this file, run ./update_deps.sh from the root of the
# git repository.

DIGESTS = {{
    # "{debug_tag}" circa {date}
    "debug": "{debug}",
    # "{latest_tag}" circa {date}
    "latest": "{latest}",
}}
""".format(debug_tag=debug,
           debug=debug_digest,
           latest_tag=latest,
           latest=latest_digest,
           date=time.strftime("%Y-%m-%d %H:%M %z")))
예제 #2
0
    def _Ping(self):
        """Ping the v2 Registry.

    Only called during transport construction, this pings the listed
    v2 registry.  The point of this ping is to establish the "realm"
    and "service" to use for Basic for Bearer-Token exchanges.
    """
        # This initiates the pull by issuing a v2 ping:
        #   GET H:P/v2/
        headers = {
            'content-type': 'application/json',
            'user-agent': docker_name.USER_AGENT,
        }
        resp, unused_content = self._transport.request(
            '{scheme}://{registry}/v2/'.format(scheme=Scheme(
                self._name.registry),
                                               registry=self._name.registry),
            'GET',
            body=None,
            headers=headers)

        # We expect a www-authenticate challenge.
        _CheckState(resp.status in [httplib.OK, httplib.UNAUTHORIZED],
                    'Unexpected status: %d' % resp.status)

        # The registry is authenticated iff we have an authentication challenge.
        self._authenticated = (resp.status == httplib.UNAUTHORIZED)
        if resp.status == httplib.OK:
            self._bearer_creds = docker_creds.Anonymous()
            self._service = 'none'
            self._realm = 'none'
            return

        challenge = resp['www-authenticate']
        _CheckState(challenge.startswith(_CHALLENGE),
                    'Unexpected "www-authenticate" header: %s' % challenge)

        # Default "_service" to the registry
        self._service = self._name.registry

        tokens = challenge[len(_CHALLENGE):].split(',')
        for t in tokens:
            if t.startswith(_REALM_PFX):
                self._realm = t[len(_REALM_PFX):].strip('"')
            elif t.startswith(_SERVICE_PFX):
                self._service = t[len(_SERVICE_PFX):].strip('"')

        # Make sure these got set.
        _CheckState(
            self._realm, 'Expected a "%s" in "www-authenticate" '
            'header: %s' % (_REALM_PFX, challenge))
예제 #3
0
    def __init__(self, name, creds, transport, action):
        self._name = name
        self._basic_creds = creds
        self._transport = transport
        self._action = action
        self._lock = threading.Lock()

        _CheckState(
            action in ACTIONS,
            'Invalid action supplied to docker_http.Transport: %s' % action)

        # Ping once to establish realm, and then get a good credential
        # for use with this transport.
        self._Ping()
        if self._authentication == _BEARER:
            self._Refresh()
        elif self._authentication == _BASIC:
            self._creds = self._basic_creds
        else:
            self._creds = docker_creds.Anonymous()
예제 #4
0
def main():
    args = parser.parse_args()

    creds = docker_creds.Anonymous()
    transport = transport_pool.Http(httplib2.Http, size=8)

    name = docker_name.Tag(args.name)

    with tarfile.open(name=args.tarball, mode='w') as tar:
        with v2_2_image.FromRegistry(name, creds, transport) as v2_2_img:
            if v2_2_img.exists():
                with v2_compat.V2FromV22(v2_2_img) as v2_img:
                    with v1_compat.V1FromV2(v2_img) as v1_img:
                        v1_image.save(name, v1_img, tar)
                        return

        with v2_image.FromRegistry(name, creds, transport) as v2_img:
            with v1_compat.V1FromV2(v2_img) as v1_img:
                v1_image.save(name, v1_img, tar)
                return