Fix image API for V2 images
This commit is contained in:
parent
bc4e07343e
commit
dead054b43
2 changed files with 13 additions and 16 deletions
|
@ -12,11 +12,10 @@ from util.cache import cache_control_flask_restful
|
||||||
|
|
||||||
|
|
||||||
def image_view(image, image_map, include_ancestors=True):
|
def image_view(image, image_map, include_ancestors=True):
|
||||||
extended_props = image
|
# TODO: Remove once we've migrated all storage data to the image records.
|
||||||
|
storage_props = image
|
||||||
if image.storage and image.storage.id:
|
if image.storage and image.storage.id:
|
||||||
extended_props = image.storage
|
storage_props = image.storage
|
||||||
|
|
||||||
command = extended_props.command
|
|
||||||
|
|
||||||
def docker_id(aid):
|
def docker_id(aid):
|
||||||
if not aid or not aid in image_map:
|
if not aid or not aid in image_map:
|
||||||
|
@ -24,12 +23,13 @@ def image_view(image, image_map, include_ancestors=True):
|
||||||
|
|
||||||
return image_map[aid].docker_image_id
|
return image_map[aid].docker_image_id
|
||||||
|
|
||||||
|
command = image.command or storage_props.command
|
||||||
image_data = {
|
image_data = {
|
||||||
'id': image.docker_image_id,
|
'id': image.docker_image_id,
|
||||||
'created': format_date(extended_props.created),
|
'created': format_date(image.created or storage_props.created),
|
||||||
'comment': extended_props.comment,
|
'comment': image.comment or storage_props.comment,
|
||||||
'command': json.loads(command) if command else None,
|
'command': json.loads(command) if command else None,
|
||||||
'size': extended_props.image_size,
|
'size': storage_props.image_size,
|
||||||
'uploading': image.storage.uploading,
|
'uploading': image.storage.uploading,
|
||||||
'sort_index': len(image.ancestors),
|
'sort_index': len(image.ancestors),
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,8 +109,8 @@ def download_blob(namespace, repo_name, digest):
|
||||||
return Response(storage.stream_read(found.locations, path), headers=headers)
|
return Response(storage.stream_read(found.locations, path), headers=headers)
|
||||||
|
|
||||||
|
|
||||||
def _render_range(end_byte, with_bytes_prefix=True):
|
def _render_range(num_uploaded_bytes, with_bytes_prefix=True):
|
||||||
return '{0}0-{1}'.format('bytes=' if with_bytes_prefix else '', end_byte - 1)
|
return '{0}0-{1}'.format('bytes=' if with_bytes_prefix else '', num_uploaded_bytes - 1)
|
||||||
|
|
||||||
|
|
||||||
@v2_bp.route('/<namespace>/<repo_name>/blobs/uploads/', methods=['POST'])
|
@v2_bp.route('/<namespace>/<repo_name>/blobs/uploads/', methods=['POST'])
|
||||||
|
@ -133,7 +133,7 @@ def start_blob_upload(namespace, repo_name):
|
||||||
return accepted
|
return accepted
|
||||||
else:
|
else:
|
||||||
# The user plans to send us the entire body right now
|
# The user plans to send us the entire body right now
|
||||||
uploaded = _upload_chunk(namespace, repo_name, new_upload_uuid, range_required=False)
|
uploaded = _upload_chunk(namespace, repo_name, new_upload_uuid)
|
||||||
uploaded.save()
|
uploaded.save()
|
||||||
|
|
||||||
return _finish_upload(namespace, repo_name, uploaded, digest)
|
return _finish_upload(namespace, repo_name, uploaded, digest)
|
||||||
|
@ -184,7 +184,7 @@ def _parse_range_header(range_header_text, valid_start):
|
||||||
return (start, length)
|
return (start, length)
|
||||||
|
|
||||||
|
|
||||||
def _upload_chunk(namespace, repo_name, upload_uuid, range_required):
|
def _upload_chunk(namespace, repo_name, upload_uuid):
|
||||||
""" Common code among the various uploading paths for appending data to blobs.
|
""" Common code among the various uploading paths for appending data to blobs.
|
||||||
Callers MUST call .save() or .delete_instance() on the returned database object.
|
Callers MUST call .save() or .delete_instance() on the returned database object.
|
||||||
"""
|
"""
|
||||||
|
@ -195,9 +195,6 @@ def _upload_chunk(namespace, repo_name, upload_uuid, range_required):
|
||||||
|
|
||||||
start_offset, length = 0, -1
|
start_offset, length = 0, -1
|
||||||
range_header = request.headers.get('range', None)
|
range_header = request.headers.get('range', None)
|
||||||
if range_required and range_header is None:
|
|
||||||
_range_not_satisfiable(found.byte_count)
|
|
||||||
|
|
||||||
if range_header is not None:
|
if range_header is not None:
|
||||||
try:
|
try:
|
||||||
start_offset, length = _parse_range_header(range_header, found.byte_count)
|
start_offset, length = _parse_range_header(range_header, found.byte_count)
|
||||||
|
@ -240,7 +237,7 @@ def _finish_upload(namespace, repo_name, upload_obj, expected_digest):
|
||||||
@require_repo_write
|
@require_repo_write
|
||||||
@anon_protect
|
@anon_protect
|
||||||
def upload_chunk(namespace, repo_name, upload_uuid):
|
def upload_chunk(namespace, repo_name, upload_uuid):
|
||||||
upload = _upload_chunk(namespace, repo_name, upload_uuid, range_required=False)
|
upload = _upload_chunk(namespace, repo_name, upload_uuid)
|
||||||
upload.save()
|
upload.save()
|
||||||
|
|
||||||
accepted = make_response('', 204)
|
accepted = make_response('', 204)
|
||||||
|
@ -259,7 +256,7 @@ def monolithic_upload_or_last_chunk(namespace, repo_name, upload_uuid):
|
||||||
if digest is None:
|
if digest is None:
|
||||||
raise BlobUploadInvalid()
|
raise BlobUploadInvalid()
|
||||||
|
|
||||||
found = _upload_chunk(namespace, repo_name, upload_uuid, range_required=False)
|
found = _upload_chunk(namespace, repo_name, upload_uuid)
|
||||||
return _finish_upload(namespace, repo_name, found, digest)
|
return _finish_upload(namespace, repo_name, found, digest)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue