Merge pull request #200 from coreos-inc/tagapilimit

Add pagination support to tag history API
This commit is contained in:
josephschorr 2015-06-30 22:09:09 +03:00
commit 7aeaf2344e
2 changed files with 19 additions and 6 deletions

View file

@ -1861,14 +1861,14 @@ def _tag_alive(query, now_ts=None):
(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
.select(RepositoryTag, Image)
.join(Image)
.where(RepositoryTag.repository == repository)
.where(RepositoryTag.hidden == False)
.order_by(RepositoryTag.lifetime_start_ts.desc())
.limit(limit))
.paginate(page, size))
if specific_tag:
query = query.where(RepositoryTag.name == specific_tag)

View file

@ -16,12 +16,13 @@ from datetime import datetime
@resource('/v1/repository/<repopath:repository>/tag/')
@path_param('repository', 'The full path of the repository. e.g. namespace/name')
class ListRepositoryTags(RepositoryParamResource):
""" Resource for listing repository tags. """
""" Resource for listing full repository tag history, alive *and dead*. """
@require_repo_write
@parse_args
@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')
def get(self, args, namespace, repository):
repo = model.get_repository(namespace, repository)
@ -44,9 +45,21 @@ class ListRepositoryTags(RepositoryParamResource):
return tag_info
specific_tag = args.get('specificTag') or None
page = min(1, args.get('start', 1))
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>')