2017-03-14 17:41:16 +00:00
|
|
|
import bitmath
|
|
|
|
|
2017-06-26 22:16:15 +00:00
|
|
|
|
2015-08-12 20:39:32 +00:00
|
|
|
class V2RegistryException(Exception):
|
2017-06-26 22:16:15 +00:00
|
|
|
def __init__(self, error_code_str, message, detail, http_status_code=400, repository=None,
|
|
|
|
scopes=None):
|
2015-08-12 20:39:32 +00:00
|
|
|
super(V2RegistryException, self).__init__(message)
|
|
|
|
self.http_status_code = http_status_code
|
2016-03-09 23:09:20 +00:00
|
|
|
self.repository = repository
|
|
|
|
self.scopes = scopes
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
self._error_code_str = error_code_str
|
|
|
|
self._detail = detail
|
|
|
|
|
|
|
|
def as_dict(self):
|
|
|
|
return {
|
|
|
|
'code': self._error_code_str,
|
|
|
|
'message': self.message,
|
2017-06-26 22:16:15 +00:00
|
|
|
'detail': self._detail if self._detail is not None else {},}
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BlobUnknown(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(BlobUnknown, self).__init__('BLOB_UNKNOWN', 'blob unknown to registry', detail, 404)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BlobUploadInvalid(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(BlobUploadInvalid, self).__init__('BLOB_UPLOAD_INVALID', 'blob upload invalid', detail)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BlobUploadUnknown(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
|
|
|
super(BlobUploadUnknown, self).__init__('BLOB_UPLOAD_UNKNOWN',
|
2017-06-26 22:16:15 +00:00
|
|
|
'blob upload unknown to registry', detail, 404)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DigestInvalid(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
|
|
|
super(DigestInvalid, self).__init__('DIGEST_INVALID',
|
2017-06-26 22:16:15 +00:00
|
|
|
'provided digest did not match uploaded content', detail)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ManifestBlobUnknown(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
|
|
|
super(ManifestBlobUnknown, self).__init__('MANIFEST_BLOB_UNKNOWN',
|
2017-06-26 22:16:15 +00:00
|
|
|
'manifest blob unknown to registry', detail)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ManifestInvalid(V2RegistryException):
|
2016-02-09 19:16:39 +00:00
|
|
|
def __init__(self, detail=None, http_status_code=400):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(ManifestInvalid, self).__init__('MANIFEST_INVALID', 'manifest invalid', detail,
|
2016-02-09 19:16:39 +00:00
|
|
|
http_status_code)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ManifestUnknown(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(ManifestUnknown, self).__init__('MANIFEST_UNKNOWN', 'manifest unknown', detail, 404)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
2017-06-22 01:58:16 +00:00
|
|
|
class TagExpired(V2RegistryException):
|
|
|
|
def __init__(self, message=None, detail=None):
|
|
|
|
super(TagExpired, self).__init__('TAG_EXPIRED',
|
|
|
|
message or 'Tag has expired',
|
|
|
|
detail,
|
|
|
|
404)
|
|
|
|
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
class ManifestUnverified(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
|
|
|
super(ManifestUnverified, self).__init__('MANIFEST_UNVERIFIED',
|
2017-06-26 22:16:15 +00:00
|
|
|
'manifest failed signature verification', detail)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NameInvalid(V2RegistryException):
|
2017-03-30 20:12:27 +00:00
|
|
|
def __init__(self, detail=None, message=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(NameInvalid, self).__init__('NAME_INVALID', message or 'invalid repository name', detail)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NameUnknown(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(NameUnknown, self).__init__('NAME_UNKNOWN', 'repository name not known to registry',
|
|
|
|
detail, 404)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SizeInvalid(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
|
|
|
super(SizeInvalid, self).__init__('SIZE_INVALID',
|
2017-06-26 22:16:15 +00:00
|
|
|
'provided length did not match content length', detail)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
2016-08-29 15:58:18 +00:00
|
|
|
class TagAlreadyExists(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(TagAlreadyExists, self).__init__('TAG_ALREADY_EXISTS', 'tag was already pushed', detail,
|
2016-08-29 15:58:18 +00:00
|
|
|
409)
|
|
|
|
|
2017-06-26 22:16:15 +00:00
|
|
|
|
2015-08-12 20:39:32 +00:00
|
|
|
class TagInvalid(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(TagInvalid, self).__init__('TAG_INVALID', 'manifest tag did not match URI', detail)
|
|
|
|
|
2015-08-12 20:39:32 +00:00
|
|
|
|
2017-02-27 18:32:09 +00:00
|
|
|
class LayerTooLarge(V2RegistryException):
|
2017-03-14 17:41:16 +00:00
|
|
|
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,
|
2017-06-26 22:16:15 +00:00
|
|
|
'uploaded': uploaded,}
|
2017-03-14 17:41:16 +00:00
|
|
|
|
|
|
|
up_str = bitmath.Byte(uploaded).best_prefix().format("{value:.2f} {unit}")
|
|
|
|
max_str = bitmath.Byte(max_allowed).best_prefix().format("{value:.2f} {unit}")
|
2017-06-26 22:16:15 +00:00
|
|
|
message = 'Uploaded blob of %s is larger than %s allowed by this registry' % (up_str,
|
|
|
|
max_str)
|
|
|
|
|
2017-03-14 17:41:16 +00:00
|
|
|
|
2015-08-12 20:39:32 +00:00
|
|
|
class Unauthorized(V2RegistryException):
|
2016-03-09 23:09:20 +00:00
|
|
|
def __init__(self, detail=None, repository=None, scopes=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(Unauthorized,
|
|
|
|
self).__init__('UNAUTHORIZED', 'access to the requested resource is not authorized',
|
|
|
|
detail, 401, repository=repository, scopes=scopes)
|
2015-08-12 20:39:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Unsupported(V2RegistryException):
|
2017-03-30 20:12:27 +00:00
|
|
|
def __init__(self, detail=None, message=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(Unsupported, self).__init__('UNSUPPORTED', message or 'The operation is unsupported.',
|
|
|
|
detail, 405)
|
2017-03-16 21:06:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
class InvalidLogin(V2RegistryException):
|
|
|
|
def __init__(self, message=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(InvalidLogin, self).__init__('UNAUTHORIZED', message or
|
|
|
|
'Specified credentials are invalid', {}, 401)
|
2017-03-30 20:12:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class InvalidRequest(V2RegistryException):
|
|
|
|
def __init__(self, message=None):
|
2017-06-26 22:16:15 +00:00
|
|
|
super(InvalidRequest, self).__init__('INVALID_REQUEST', message or 'Invalid request', {}, 400)
|
2018-05-22 22:36:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
class NamespaceDisabled(V2RegistryException):
|
|
|
|
def __init__(self, message=None):
|
|
|
|
message = message or 'This namespace is disabled. Please contact your system administrator.'
|
|
|
|
super(NamespaceDisabled, self).__init__('NAMESPACE_DISABLED', message, {}, 400)
|
2018-12-05 20:19:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BlobDownloadGeoBlocked(V2RegistryException):
|
|
|
|
def __init__(self, detail=None):
|
|
|
|
message = ('The region from which you are pulling has been geo-ip blocked. ' +
|
|
|
|
'Please contact the namespace owner.')
|
|
|
|
super(BlobDownloadGeoBlocked, self).__init__('BLOB_DOWNLOAD_GEO_BLOCKED', message, detail, 403)
|