Fix image API for V2 images

This commit is contained in:
Joseph Schorr 2015-08-13 15:43:49 -04:00
parent bc4e07343e
commit dead054b43
2 changed files with 13 additions and 16 deletions

View file

@ -12,11 +12,10 @@ from util.cache import cache_control_flask_restful
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:
extended_props = image.storage
command = extended_props.command
storage_props = image.storage
def docker_id(aid):
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
command = image.command or storage_props.command
image_data = {
'id': image.docker_image_id,
'created': format_date(extended_props.created),
'comment': extended_props.comment,
'created': format_date(image.created or storage_props.created),
'comment': image.comment or storage_props.comment,
'command': json.loads(command) if command else None,
'size': extended_props.image_size,
'size': storage_props.image_size,
'uploading': image.storage.uploading,
'sort_index': len(image.ancestors),
}

View file

@ -109,8 +109,8 @@ def download_blob(namespace, repo_name, digest):
return Response(storage.stream_read(found.locations, path), headers=headers)
def _render_range(end_byte, with_bytes_prefix=True):
return '{0}0-{1}'.format('bytes=' if with_bytes_prefix else '', end_byte - 1)
def _render_range(num_uploaded_bytes, with_bytes_prefix=True):
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'])
@ -133,7 +133,7 @@ def start_blob_upload(namespace, repo_name):
return accepted
else:
# 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()
return _finish_upload(namespace, repo_name, uploaded, digest)
@ -184,7 +184,7 @@ def _parse_range_header(range_header_text, valid_start):
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.
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
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:
try:
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
@anon_protect
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()
accepted = make_response('', 204)
@ -259,7 +256,7 @@ def monolithic_upload_or_last_chunk(namespace, repo_name, upload_uuid):
if digest is None:
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)