Add a repository view with all images that has the list of tags for each image.
This commit is contained in:
parent
cffb906d64
commit
392307a937
1 changed files with 26 additions and 0 deletions
|
@ -4,6 +4,7 @@ import stripe
|
|||
from flask import request, make_response, jsonify, abort
|
||||
from flask.ext.login import login_required, current_user
|
||||
from functools import wraps
|
||||
from collections import defaultdict
|
||||
|
||||
from data import model
|
||||
from app import app
|
||||
|
@ -261,6 +262,31 @@ def role_view(repo_perm_obj):
|
|||
}
|
||||
|
||||
|
||||
@app.route('/api/repository/<path:repository>/image/', methods=['GET'])
|
||||
@parse_repository_name
|
||||
def list_repository_images(namespace, repository):
|
||||
permission = ReadRepositoryPermission(namespace, repository)
|
||||
if permission.can() or model.repository_is_public(namespace, repository):
|
||||
all_images = model.get_repository_images(namespace, repository)
|
||||
all_tags = model.list_repository_tags(namespace, repository)
|
||||
|
||||
tags_by_image_id = defaultdict(list)
|
||||
for tag in all_tags:
|
||||
tags_by_image_id[tag.image.docker_image_id].append(tag.name)
|
||||
|
||||
|
||||
def add_tags(image_json):
|
||||
image_json['tags'] = tags_by_image_id[image_json['id']]
|
||||
return image_json
|
||||
|
||||
|
||||
return jsonify({
|
||||
'images': [add_tags(image_view(image)) for image in all_images]
|
||||
})
|
||||
|
||||
abort(403)
|
||||
|
||||
|
||||
@app.route('/api/repository/<path:repository>/tag/<tag>/images',
|
||||
methods=['GET'])
|
||||
@parse_repository_name
|
||||
|
|
Reference in a new issue