parent
d9ce8fdf52
commit
f7f10f4a6d
2 changed files with 19 additions and 6 deletions
|
@ -1861,14 +1861,14 @@ def _tag_alive(query, now_ts=None):
|
||||||
(RepositoryTag.lifetime_end_ts > now_ts))
|
(RepositoryTag.lifetime_end_ts > now_ts))
|
||||||
|
|
||||||
|
|
||||||
def list_repository_tag_history(repository, limit=100, specific_tag=None):
|
def list_repository_tag_history(repository, page=1, size=100, specific_tag=None):
|
||||||
query = (RepositoryTag
|
query = (RepositoryTag
|
||||||
.select(RepositoryTag, Image)
|
.select(RepositoryTag, Image)
|
||||||
.join(Image)
|
.join(Image)
|
||||||
.where(RepositoryTag.repository == repository)
|
.where(RepositoryTag.repository == repository)
|
||||||
.where(RepositoryTag.hidden == False)
|
.where(RepositoryTag.hidden == False)
|
||||||
.order_by(RepositoryTag.lifetime_start_ts.desc())
|
.order_by(RepositoryTag.lifetime_start_ts.desc())
|
||||||
.limit(limit))
|
.paginate(page, size))
|
||||||
|
|
||||||
if specific_tag:
|
if specific_tag:
|
||||||
query = query.where(RepositoryTag.name == specific_tag)
|
query = query.where(RepositoryTag.name == specific_tag)
|
||||||
|
|
|
@ -16,12 +16,13 @@ from datetime import datetime
|
||||||
@resource('/v1/repository/<repopath:repository>/tag/')
|
@resource('/v1/repository/<repopath:repository>/tag/')
|
||||||
@path_param('repository', 'The full path of the repository. e.g. namespace/name')
|
@path_param('repository', 'The full path of the repository. e.g. namespace/name')
|
||||||
class ListRepositoryTags(RepositoryParamResource):
|
class ListRepositoryTags(RepositoryParamResource):
|
||||||
""" Resource for listing repository tags. """
|
""" Resource for listing full repository tag history, alive *and dead*. """
|
||||||
|
|
||||||
@require_repo_write
|
@require_repo_write
|
||||||
@parse_args
|
@parse_args
|
||||||
@query_param('specificTag', 'Filters the tags to the specific tag.', type=str, default='')
|
@query_param('specificTag', 'Filters the tags to the specific tag.', type=str, default='')
|
||||||
@query_param('limit', 'Limit to the number of results to return. Max 100.', type=int, default=50)
|
@query_param('limit', 'Limit to the number of results to return per page. Max 100.', type=int, default=50)
|
||||||
|
@query_param('page', 'Page index for the results. Default 1.', type=int, default=1)
|
||||||
@nickname('listRepoTags')
|
@nickname('listRepoTags')
|
||||||
def get(self, args, namespace, repository):
|
def get(self, args, namespace, repository):
|
||||||
repo = model.get_repository(namespace, repository)
|
repo = model.get_repository(namespace, repository)
|
||||||
|
@ -44,9 +45,21 @@ class ListRepositoryTags(RepositoryParamResource):
|
||||||
return tag_info
|
return tag_info
|
||||||
|
|
||||||
specific_tag = args.get('specificTag') or None
|
specific_tag = args.get('specificTag') or None
|
||||||
|
|
||||||
|
page = min(1, args.get('start', 1))
|
||||||
limit = min(100, max(1, args.get('limit', 50)))
|
limit = min(100, max(1, args.get('limit', 50)))
|
||||||
tags = model.list_repository_tag_history(repo, limit=limit, specific_tag=specific_tag)
|
|
||||||
return {'tags': [tag_view(tag) for tag in tags]}
|
# Note: We ask for limit+1 here, so we can check to see if there are
|
||||||
|
# additional pages of results.
|
||||||
|
tags = model.list_repository_tag_history(repo, page=page, size=limit+1,
|
||||||
|
specific_tag=specific_tag)
|
||||||
|
|
||||||
|
tags = list(tags)
|
||||||
|
return {
|
||||||
|
'tags': [tag_view(tag) for tag in tags[0:limit]],
|
||||||
|
'page': page,
|
||||||
|
'has_additional': len(tags) >= limit
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@resource('/v1/repository/<repopath:repository>/tag/<tag>')
|
@resource('/v1/repository/<repopath:repository>/tag/<tag>')
|
||||||
|
|
Reference in a new issue