Make LayerTooLarge error more informative
This commit is contained in:
parent
dd7f254f96
commit
239b6d7cf8
2 changed files with 20 additions and 14 deletions
|
@ -362,12 +362,7 @@ def _upload_chunk(blob_upload, range_header):
|
|||
# Check if we should raise 413 before accepting the data.
|
||||
uploaded = bitmath.Byte(length + start_offset)
|
||||
if length > -1 and uploaded > max_layer_size:
|
||||
detail = {
|
||||
'reason': '%s is greater than maximum allowed size %s' % (uploaded, max_layer_size),
|
||||
'max_allowed': max_layer_size.bytes,
|
||||
'uploaded': uploaded.bytes,
|
||||
}
|
||||
raise LayerTooLarge(detail=detail)
|
||||
raise LayerTooLarge(uploaded=uploaded.bytes, max_allowed=max_layer_size.bytes)
|
||||
|
||||
location_set = {blob_upload.location_name}
|
||||
|
||||
|
@ -451,12 +446,7 @@ def _upload_chunk(blob_upload, range_header):
|
|||
# Ensure we have not gone beyond the max layer size.
|
||||
upload_size = bitmath.Byte(blob_upload.byte_count)
|
||||
if upload_size > max_layer_size:
|
||||
detail = {
|
||||
'reason': '%s is greater than maximum allowed size %s' % (upload_size, max_layer_size),
|
||||
'max_allowed': max_layer_size.bytes,
|
||||
'uploaded': upload_size.bytes,
|
||||
}
|
||||
raise LayerTooLarge(detail=detail)
|
||||
raise LayerTooLarge(uploaded=upload_size.bytes, max_allowed=max_layer_size.bytes)
|
||||
|
||||
return blob_upload
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import bitmath
|
||||
|
||||
class V2RegistryException(Exception):
|
||||
def __init__(self, error_code_str, message, detail, http_status_code=400,
|
||||
repository=None, scopes=None):
|
||||
|
@ -113,9 +115,23 @@ class TagInvalid(V2RegistryException):
|
|||
detail)
|
||||
|
||||
class LayerTooLarge(V2RegistryException):
|
||||
def __init__(self, detail=None):
|
||||
def __init__(self, uploaded=None, max_allowed=None):
|
||||
detail = {}
|
||||
message = 'Uploaded blob is larger than allowed by this registry'
|
||||
|
||||
if uploaded is not None and max_allowed is not None:
|
||||
detail = {
|
||||
'reason': '%s is greater than maximum allowed size %s' % (uploaded, max_allowed),
|
||||
'max_allowed': max_allowed,
|
||||
'uploaded': uploaded,
|
||||
}
|
||||
|
||||
up_str = bitmath.Byte(uploaded).best_prefix().format("{value:.2f} {unit}")
|
||||
max_str = bitmath.Byte(max_allowed).best_prefix().format("{value:.2f} {unit}")
|
||||
message = 'Uploaded blob of %s is larger than %s allowed by this registry' % (up_str, max_str)
|
||||
|
||||
super(LayerTooLarge, self).__init__('BLOB_UPLOAD_INVALID',
|
||||
'Uploaded layer is larger than allowed by this registry',
|
||||
message,
|
||||
detail)
|
||||
|
||||
|
||||
|
|
Reference in a new issue