Beispiel #1
0
 def test_authfile(self):
     image = 'alpine'
     dock = DockerV2ext(image)
     with self.assertRaises(OSError):
         dock._auth_file()
     opt = {'username': '******', 'password': '******'}
     dock = DockerV2ext(image, options=opt)
     dock._auth_file()
     fn = str(dock.auth_file)
     with open(fn) as f:
         data = f.read()
     js = json.loads(data)
     self.assertIn('auths', js)
     os.unlink(fn)
Beispiel #2
0
 def test_private(self):
     image = 'private'
     dock = DockerV2ext(image)
     with self.assertRaises(OSError):
         dock._auth_file()
     opt = {'username': '******', 
            'password': '******', 
            'policy_file': self.test_dir + 'policy.json'
            }
     dock = DockerV2ext(image, options=opt)
     dock._auth_file()
     fn = str(dock.auth_file)
     with open(fn) as f:
         data = f.read()
     js = json.loads(data)
     self.assertIn('auths', js)
Beispiel #3
0
def _pull_dockerv2(request, location, repo, tag, updater):
    """ Private method to pull a docker images. """
    cdir = CONFIG['CacheDirectory']
    edir = CONFIG['ExpandDirectory']
    params = CONFIG['Locations'][location]
    cacert = _get_cacert(location)

    url = 'https://%s' % location
    if 'url' in params:
        url = params['url']
    try:
        options = {}
        if cacert is not None:
            options['cacert'] = cacert
        options['baseUrl'] = url
        if 'authMethod' in params:
            options['authMethod'] = params['authMethod']

        if ('session' in request and 'tokens' in request['session']
                and request['session']['tokens']):
            if location in request['session']['tokens']:
                userpass = request['session']['tokens'][location]
                options['username'] = userpass.split(':')[0]
                options['password'] = ''.join(userpass.split(':')[1:])
            elif ('default' in request['session']['tokens']):
                userpass = request['session']['tokens']['default']
                options['username'] = userpass.split(':')[0]
                options['password'] = ''.join(userpass.split(':')[1:])
        imgid = '%s:%s' % (repo, tag)
        system = request['system']
        if system not in CONFIG['Platforms']:
            raise KeyError('%s is not in the configuration' % system)
        sysconf = CONFIG['Platforms'][system]
        if sysconf.get('use_external'):
            options['policy_file'] = sysconf.get("policy_file")
            dock = DockerV2ext(imgid, options, updater=updater, cachedir=cdir)
        else:
            dock = DockerV2(imgid, options, updater=updater, cachedir=cdir)
        updater.update_status("PULLING", 'Getting manifest')
        request['meta'] = dock.examine_manifest()
        request['id'] = str(request['meta']['id'])

        if check_image(request):
            return True

        dock.pull_layers()

        expandedpath = tempfile.mkdtemp(suffix='extract',
                                        prefix=request['id'],
                                        dir=edir)
        request['expandedpath'] = expandedpath

        updater.update_status("PULLING", 'Extracting Layers')
        dock.extract_docker_layers(expandedpath)
        return True
    except:
        logging.warn(sys.exc_value)
        raise

    return False
Beispiel #4
0
 def test_pull_public(self):
     cache = tempfile.mkdtemp()
     expand = tempfile.mkdtemp()
     image = 'alpine'
     self.cleanpaths.append(cache)
     self.cleanpaths.append(expand)
     dock = DockerV2ext(image, cachedir=cache, updater=self.updater)
     resp = dock.examine_manifest()
     self.assertIn('id', resp)
     self.assertIn('private', resp)
     resp = dock.pull_layers()
     self.assertTrue(resp)
     dock.extract_docker_layers(expand)
     self.assertTrue(os.path.exists(os.path.join(expand,"bin")))
Beispiel #5
0
 def test_pull_private(self):
     if self.tokens is None:
         return
     tok = base64.b64decode(self.tokens['index.docker.io'])
     username, password = tok.split(':')
     image = 'scanon/shaneprivate'
     options = {'username': username, 'password': password}
     cache = tempfile.mkdtemp()
     expand = tempfile.mkdtemp()
     self.cleanpaths.append(cache)
     self.cleanpaths.append(expand)
     dock = DockerV2ext(image, options=options, cachedir=cache,
                        updater=self.updater)
     resp = dock.examine_manifest()
     self.assertTrue(resp['private'])
     resp = dock.pull_layers()
     self.assertTrue(resp)
     dock.extract_docker_layers(expand)
     self.assertTrue(os.path.exists(os.path.join(expand, 'bin')))
Beispiel #6
0
 def test_policyfile(self):
     image = 'alpine'
     pf = self.test_dir + 'policy.json'
     opt = {'policy_file': pf}
     dock = DockerV2ext(image, options=opt)
     self.assertEquals(pf, dock.policy_file)
Beispiel #7
0
 def test_base_url(self):
     image = 'scanon/alpine'
     opt = {'baseUrl': 'https://foo.bar/'}
     dock = DockerV2ext(image, options=opt)
     self.assertEqual(dock.registry, 'foo.bar')