New tests and small fixes while comparing against the V2 spec
Fixes #391
This commit is contained in:
parent
41bfe2ffde
commit
decdaa4c79
6 changed files with 232 additions and 33 deletions
|
@ -1,19 +1,48 @@
|
|||
# XXX This code is not yet ready to be run in production, and should remain disabled until such
|
||||
# XXX time as this notice is removed.
|
||||
|
||||
from flask import jsonify
|
||||
from flask import jsonify, request, url_for
|
||||
|
||||
from app import get_app_url
|
||||
from endpoints.v2 import v2_bp, require_repo_read
|
||||
from endpoints.v2.errors import NameUnknown
|
||||
from auth.jwt_auth import process_jwt_auth
|
||||
from endpoints.decorators import anon_protect
|
||||
from data import model
|
||||
|
||||
def _add_pagination(query, url):
|
||||
limit = request.args.get('n', None)
|
||||
page = request.args.get('page', 1)
|
||||
|
||||
if limit is None:
|
||||
return None, query
|
||||
|
||||
url = get_app_url() + url
|
||||
query = query.paginate(page, limit)
|
||||
link = url + '?n=%s&last=%s; rel="next"' % (limit, page + 1)
|
||||
return link, query
|
||||
|
||||
|
||||
@v2_bp.route('/<namespace>/<repo_name>/tags/list', methods=['GET'])
|
||||
@process_jwt_auth
|
||||
@require_repo_read
|
||||
@anon_protect
|
||||
def list_all_tags(namespace, repo_name):
|
||||
return jsonify({
|
||||
repository = model.repository.get_repository(namespace, repo_name)
|
||||
if repository is None:
|
||||
raise NameUnknown()
|
||||
|
||||
query = model.tag.list_repository_tags(namespace, repo_name)
|
||||
|
||||
url = url_for('v2.list_all_tags', namespace=namespace, repo_name=repo_name)
|
||||
link, query = _add_pagination(query, url)
|
||||
|
||||
response = jsonify({
|
||||
'name': '{0}/{1}'.format(namespace, repo_name),
|
||||
'tags': [tag.name for tag in model.tag.list_repository_tags(namespace, repo_name)],
|
||||
'tags': [tag.name for tag in query],
|
||||
})
|
||||
|
||||
if link is not None:
|
||||
response.headers['Link'] = link
|
||||
|
||||
return response
|
||||
|
|
Reference in a new issue