WIP: Towards sec demo

This commit is contained in:
Joseph Schorr 2015-10-27 17:38:48 -04:00 committed by Jimmy Zelinskie
parent fb3d0fa27d
commit 407eaae137
6 changed files with 164 additions and 14 deletions

View file

@ -12,6 +12,19 @@ from data.database import (Image, Repository, ImageStoragePlacement, Namespace,
logger = logging.getLogger(__name__)
def get_repository_images_recursive(docker_image_ids):
""" Returns a query matching the given docker image IDs, along with any which have the image IDs
as parents.
Note: This is a DB intensive operation and should be used sparingly.
"""
inner_images = Image.select('%/' + Image.id + '/%').where(Image.docker_image_id << docker_image_ids)
images = Image.select(Image.id).where(Image.docker_image_id << docker_image_ids)
recursive_images = Image.select(Image.id).where(Image.ancestors ** inner_images)
return recursive_images | images
def get_parent_images(namespace_name, repository_name, image_obj):
""" Returns a list of parent Image objects in chronilogical order. """
parents = image_obj.ancestors

View file

@ -12,6 +12,16 @@ def _tag_alive(query, now_ts=None):
(RepositoryTag.lifetime_end_ts > now_ts))
def get_matching_tags(docker_image_ids, *args):
""" Returns a query pointing to all tags that contain the given image(s). """
return (RepositoryTag
.select(*args)
.distinct()
.join(Image)
.where(Image.id << image.get_repository_images_recursive(docker_image_ids),
RepositoryTag.lifetime_end_ts >> None))
def list_repository_tags(namespace_name, repository_name, include_hidden=False,
include_storage=False):
to_select = (RepositoryTag, Image)