Beispiel #1
0
    def pull(self, repository, tag=None, stream=False):
        registry, repo_name = auth.resolve_repository_name(repository)
        if repo_name.count(":") == 1:
            repository, tag = repository.rsplit(":", 1)

        params = {
            'tag': tag,
            'fromImage': repository
        }
        headers = {}

        if utils.compare_version('1.5', self._version) >= 0:
            if getattr(self, '_cfg', None) is None:
                self._cfg = auth.load_config()
            authcfg = auth.resolve_authconfig(self._cfg, registry)
            # do not fail if no atuhentication exists
            # for this specific registry as we can have a readonly pull
            if authcfg:
                headers['X-Registry-Auth'] = auth.encode_header(authcfg)
        u = self._url("/images/create")
        response = self._post(u, params=params, headers=headers, stream=stream,
                              timeout=None)

        if stream:
            return self._stream_helper(response)
        else:
            return self._result(response)
    def test_build_remote_with_registry_auth(self):
        self.client._auth_configs = {
            'https://example.com': {
                'user': '******',
                'password': '******',
                'email': '*****@*****.**'
            }
        }

        expected_params = {'t': None, 'q': False, 'dockerfile': None,
                           'rm': False, 'nocache': False, 'pull': False,
                           'forcerm': False,
                           'remote': 'https://github.com/docker-library/mongo'}
        expected_headers = {
            'X-Registry-Config': auth.encode_header(self.client._auth_configs)}

        self.client.build(path='https://github.com/docker-library/mongo')

        fake_request.assert_called_with(
            'POST',
            url_prefix + 'build',
            stream=True,
            data=None,
            headers=expected_headers,
            params=expected_params,
            timeout=None
        )
    def test_build_remote_with_registry_auth(self):
        self.client._auth_configs = auth.AuthConfig({
            'auths': {
                'https://example.com': {
                    'user': '******',
                    'password': '******',
                    'email': '*****@*****.**'
                }
            }
        })

        expected_params = {
            't': None,
            'q': False,
            'dockerfile': None,
            'rm': False,
            'nocache': False,
            'pull': False,
            'forcerm': False,
            'remote': 'https://github.com/docker-library/mongo'
        }
        expected_headers = {
            'X-Registry-Config':
            auth.encode_header(self.client._auth_configs.auths)
        }

        self.client.build(path='https://github.com/docker-library/mongo')

        fake_request.assert_called_with('POST',
                                        url_prefix + 'build',
                                        stream=True,
                                        data=None,
                                        headers=expected_headers,
                                        params=expected_params,
                                        timeout=None)
Beispiel #4
0
    def pull(self, repository, tag=None, stream=False):
        registry, repo_name = auth.resolve_repository_name(repository)
        if repo_name.count(":") == 1:
            repository, tag = repository.rsplit(":", 1)

        params = {'tag': tag, 'fromImage': repository}
        headers = {}

        if utils.compare_version('1.5', self._version) >= 0:
            if getattr(self, '_cfg', None) is None:
                self._cfg = auth.load_config()
            authcfg = auth.resolve_authconfig(self._cfg, registry)
            # do not fail if no atuhentication exists
            # for this specific registry as we can have a readonly pull
            if authcfg:
                headers['X-Registry-Auth'] = auth.encode_header(authcfg)
        u = self._url("/images/create")
        response = self._post(u,
                              params=params,
                              headers=headers,
                              stream=stream,
                              timeout=None)

        if stream:
            return self._stream_helper(response)
        else:
            return self._result(response)
Beispiel #5
0
 def test_803_urlsafe_encode(self):
     auth_data = {
         'username': '******',
         'password': '******'
     }
     encoded = auth.encode_header(auth_data)
     assert b'/' not in encoded
     assert b'_' in encoded
Beispiel #6
0
 def test_803_urlsafe_encode(self):
     auth_data = {
         'username': '******',
         'password': '******'
     }
     encoded = auth.encode_header(auth_data)
     assert b'/' not in encoded
     assert b'_' in encoded
Beispiel #7
0
 def push(self, repository):
     registry, repo_name = auth.resolve_repository_name(repository)
     u = self._url("/images/{0}/push".format(repository))
     headers = {}
     if getattr(self, '_cfg', None) is None:
         self._cfg = auth.load_config()
     authcfg = auth.resolve_authconfig(self._cfg, registry)
     if utils.compare_version('1.5', self._version) >= 0:
         # do not fail if no atuhentication exists
         # for this specific registry as we can have an anon push
         if authcfg:
             headers['X-Registry-Auth'] = auth.encode_header(authcfg)
         return self._result(self._post_json(u, None, headers=headers))
     return self._result(self._post_json(u, authcfg))
Beispiel #8
0
    def test_set_auth_headers_with_empty_dict_and_auth_configs(self):
        self.client._auth_configs = {
            'https://example.com': {
                'user': '******',
                'password': '******',
                'email': '*****@*****.**'
            }
        }

        headers = {}
        expected_headers = {
            'X-Registry-Config': auth.encode_header(self.client._auth_configs)}
        self.client._set_auth_headers(headers)
        self.assertEqual(headers, expected_headers)
    def test_set_auth_headers_with_empty_dict_and_auth_configs(self):
        self.client._auth_configs = {
            'https://example.com': {
                'user': '******',
                'password': '******',
                'email': '*****@*****.**'
            }
        }

        headers = {}
        expected_headers = {
            'X-Registry-Config': auth.encode_header(self.client._auth_configs)}
        self.client._set_auth_headers(headers)
        self.assertEqual(headers, expected_headers)
Beispiel #10
0
 def push(self, repository):
     registry, repo_name = auth.resolve_repository_name(repository)
     u = self._url("/images/{0}/push".format(repository))
     headers = {}
     if getattr(self, '_cfg', None) is None:
         self._cfg = auth.load_config()
     authcfg = auth.resolve_authconfig(self._cfg, registry)
     if utils.compare_version('1.5', self._version) >= 0:
         # do not fail if no atuhentication exists
         # for this specific registry as we can have an anon push
         if authcfg:
             headers['X-Registry-Auth'] = auth.encode_header(authcfg)
         return self._result(self._post_json(u, None, headers=headers))
     return self._result(self._post_json(u, authcfg))
    def test_set_auth_headers_with_empty_dict_and_auth_configs(self):
        self.client._auth_configs = auth.AuthConfig({
            'auths': {
                'https://example.com': {
                    'user': '******',
                    'password': '******',
                    'email': '*****@*****.**'
                }
            }
        })

        headers = {}
        expected_headers = {
            'X-Registry-Config':
            auth.encode_header(self.client._auth_configs.auths)
        }

        self.client._set_auth_headers(headers)
        assert headers == expected_headers
Beispiel #12
0
 def push(self, repository, authcfg=None):
     registry, _ = auth.resolve_repository_name(repository)
     u = self._url("/images/{0}/push".format(repository))
     headers = {}
     if authcfg is None:
         if getattr(self, '_cfg', None) is None:
             self._cfg = auth.load_config()
         authcfg = auth.resolve_authconfig(self._cfg, registry)
     if utils.compare_version('1.5', self._version) >= 0:
         # do not fail if no atuhentication exists
         # for this specific registry as we can have an anon push
         if authcfg:
             headers['X-Registry-Auth'] = auth.encode_header(authcfg)
         response = self._post_json(u, None, headers=headers,
                                    stream=True)
     else:
         response = self._post_json(u, authcfg, stream=True)
     response.raise_for_status()
     return response.iter_content(1)
Beispiel #13
0
    def test_set_auth_headers_with_dict_and_auth_configs(self):
        self.client._auth_configs = {
            'auths': {
                'https://example.com': {
                    'user': '******',
                    'password': '******',
                    'email': '*****@*****.**'
                }
            }
        }

        headers = {'foo': 'bar'}
        expected_headers = {
            'X-Registry-Config':
            auth.encode_header(self.client._auth_configs['auths']),
            'foo':
            'bar'
        }

        self.client._set_auth_headers(headers)
        assert headers == expected_headers
Beispiel #14
0
    def push(self, repository, stream=False):
        registry, repo_name = auth.resolve_repository_name(repository)
        u = self._url("/images/{0}/push".format(repository))
        headers = {}
        if getattr(self, "_cfg", None) is None:
            self._cfg = auth.load_config()
        authcfg = auth.resolve_authconfig(self._cfg, registry)
        if utils.compare_version("1.5", self._version) >= 0:
            # do not fail if no atuhentication exists
            # for this specific registry as we can have an anon push
            if authcfg:
                headers["X-Registry-Auth"] = auth.encode_header(authcfg)

            if stream:
                return self._stream_helper(self._post_json(u, None, headers=headers, stream=True))
            else:
                return self._result(self._post_json(u, None, headers=headers, stream=False))
        if stream:
            return self._stream_helper(self._post_json(u, authcfg, stream=True))
        else:
            return self._result(self._post_json(u, authcfg, stream=False))
    def test_set_auth_headers_with_dict_and_auth_configs(self):
        self.client._auth_configs = {
            'auths': {
                'https://example.com': {
                    'user': '******',
                    'password': '******',
                    'email': '*****@*****.**'
                }
            }
        }

        headers = {'foo': 'bar'}
        expected_headers = {
            'X-Registry-Config': auth.encode_header(
                self.client._auth_configs['auths']
            ),
            'foo': 'bar'
        }

        self.client._set_auth_headers(headers)
        assert headers == expected_headers
Beispiel #16
0
    def test_push_image_with_auth(self):
        auth_config = {
            'username': "******",
            'password': "******",
            'serveraddress': "test_server",
        }
        encoded_auth = auth.encode_header(auth_config)
        self.client.push(fake_api.FAKE_IMAGE_NAME,
                         tag=fake_api.FAKE_TAG_NAME,
                         auth_config=auth_config)

        fake_request.assert_called_with('POST',
                                        url_prefix + 'images/test_image/push',
                                        params={
                                            'tag': fake_api.FAKE_TAG_NAME,
                                        },
                                        data='{}',
                                        headers={
                                            'Content-Type': 'application/json',
                                            'X-Registry-Auth': encoded_auth
                                        },
                                        stream=False,
                                        timeout=DEFAULT_TIMEOUT_SECONDS)
Beispiel #17
0
    def test_push_image_with_auth(self):
        auth_config = {
            'username': "******",
            'password': "******",
            'serveraddress': "test_server",
        }
        encoded_auth = auth.encode_header(auth_config)
        self.client.push(
            fake_api.FAKE_IMAGE_NAME, tag=fake_api.FAKE_TAG_NAME,
            auth_config=auth_config
        )

        fake_request.assert_called_with(
            'POST',
            url_prefix + 'images/test_image/push',
            params={
                'tag': fake_api.FAKE_TAG_NAME,
            },
            data='{}',
            headers={'Content-Type': 'application/json',
                     'X-Registry-Auth': encoded_auth},
            stream=False,
            timeout=DEFAULT_TIMEOUT_SECONDS
        )
Beispiel #18
0
 def test_803_urlsafe_encode(self):
     auth_data = {"username": "******", "password": "******"}
     encoded = auth.encode_header(auth_data)
     assert b"/" not in encoded
     assert b"_" in encoded