def get_image_files(image_id, headers): try: repository = toolkit.get_repository() if repository and store.is_private(*repository): return toolkit.api_error('Image not found', 404) # If no auth token found, either standalone registry or privileged # access. In both cases, access is always "public". data = layers.get_image_files_json(image_id) return toolkit.response(data, headers=headers, raw=True) except IOError: return toolkit.api_error('Image not found', 404) except tarfile.TarError: return toolkit.api_error('Layer format not supported', 400)
def get_private_image_files(image_id, headers): repository = toolkit.get_repository() if not repository: # No auth token found, either standalone registry or privileged access # In both cases, private images are "disabled" return toolkit.api_error('Image not found', 404) try: if not store.is_private(*repository): return toolkit.api_error('Image not found', 404) data = layers.get_image_files_json(image_id) return toolkit.response(data, headers=headers, raw=True) except IOError: return toolkit.api_error('Image not found', 404) except tarfile.TarError: return toolkit.api_error('Layer format not supported', 400)
def test_get_image_files_json(self): layer_id = rndstr(16) tfobj = _get_tarfile(self.filenames) layer_path = self.store.image_layer_path(layer_id) layer_path = os.path.join(self.store._root_path, layer_path) path_parts = layer_path.split(os.sep) path_parts[0] = '/' layer_parent = os.path.join(*path_parts[:-1]) os.makedirs(layer_parent) with open(layer_path, 'w') as fobj: fobj.write(tfobj.read()) files_json = layers.get_image_files_json(layer_id) file_infos = json.loads(files_json) for info in file_infos: self.assertIn(info[0], self.filenames) self.assertTrue(info[1:] == [u"f", False, 512, 0, 420, 0, 0])
def test_get_image_files_json_cached(self): layer_id = rndstr(16) layers.set_image_files_cache(layer_id, "{}") files_json = layers.get_image_files_json(layer_id) self.assertTrue(files_json, "{}")