本文整理汇总了Python中toolkit.api_error函数的典型用法代码示例。如果您正苦于以下问题:Python api_error函数的具体用法?Python api_error怎么用?Python api_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了api_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put_image_layer
def put_image_layer(image_id):
try:
json_data = store.get_content(store.image_json_path(image_id))
checksum = store.get_content(store.image_checksum_path(image_id))
except IOError:
return api_error('JSON\'s image not found', 404)
layer_path = store.image_layer_path(image_id)
mark_path = store.image_mark_path(image_id)
if store.exists(layer_path) and not store.exists(mark_path):
return api_error('Image already exists', 409)
input_stream = request.stream
if request.headers.get('transfer-encoding') == 'chunked':
# Careful, might work only with WSGI servers supporting chunked
# encoding (Gunicorn)
input_stream = request.environ['wsgi.input']
store.stream_write(layer_path, input_stream)
# FIXME(sam): Compute the checksum while uploading the image to save time
checksum_parts = checksum.split(':')
computed_checksum = compute_image_checksum(checksum_parts[0], image_id,
json_data)
if computed_checksum != checksum_parts[1].lower():
logger.debug('put_image_layer: Wrong checksum')
return api_error('Checksum mismatch, ignoring the layer')
# Checksum is ok, we remove the marker
store.remove(mark_path)
return response()
示例2: put_tag
def put_tag(namespace, repository, tag):
logger.debug("[put_tag] namespace={0}; repository={1}; tag={2}".format(
namespace, repository, tag))
data = None
try:
data = json.loads(flask.request.data)
except json.JSONDecodeError:
pass
if not data or not isinstance(data, basestring):
return toolkit.api_error('Invalid data')
if not store.exists(store.image_json_path(data)):
return toolkit.api_error('Image not found', 404)
store.put_content(store.tag_path(namespace, repository, tag), data)
sender = flask.current_app._get_current_object()
signals.tag_created.send(sender, namespace=namespace,
repository=repository, tag=tag, value=data)
# Write some meta-data about the repos
ua = flask.request.headers.get('user-agent', '')
data = create_tag_json(user_agent=ua)
json_path = store.repository_tag_json_path(namespace, repository, tag)
store.put_content(json_path, data)
if tag == "latest": # TODO(dustinlacewell) : deprecate this for v2
json_path = store.repository_json_path(namespace, repository)
store.put_content(json_path, data)
return toolkit.response()
示例3: put_image_layer
def put_image_layer(image_id):
try:
json_data = store.get_content(store.image_json_path(image_id))
except IOError:
return api_error('Image not found', 404)
layer_path = store.image_layer_path(image_id)
mark_path = store.image_mark_path(image_id)
if store.exists(layer_path) and not store.exists(mark_path):
return api_error('Image already exists', 409)
input_stream = request.stream
if request.headers.get('transfer-encoding') == 'chunked':
# Careful, might work only with WSGI servers supporting chunked
# encoding (Gunicorn)
input_stream = request.environ['wsgi.input']
store.stream_write(layer_path, input_stream)
# FIXME(sam): Compute the checksum while uploading the image to save time
try:
checksum = store.get_content(store.image_checksum_path(image_id))
except IOError:
# We don't have a checksum stored yet, that's fine skipping the check.
# Not removing the mark though, image is not downloadable yet.
return response()
if check_image_checksum(image_id, checksum, json_data) is False:
logger.debug('put_image_layer: Wrong checksum')
return api_error('Checksum mismatch, ignoring the layer')
# Checksum is ok, we remove the marker
store.remove(mark_path)
return response()
示例4: get_image_json
def get_image_json(image_id, headers):
try:
repository = toolkit.get_repository()
if repository and store.is_private(*repository):
return toolkit.api_error('Image not found', 404)
# If no auth token found, either standalone registry or privileged
# access. In both cases, access is always "public".
return _get_image_json(image_id, headers)
except IOError:
return toolkit.api_error('Image not found', 404)
示例5: put_image_layer
def put_image_layer(image_id):
try:
json_data = store.get_content(store.image_json_path(image_id))
except IOError:
return toolkit.api_error('Image not found', 404)
layer_path = store.image_layer_path(image_id)
mark_path = store.image_mark_path(image_id)
if store.exists(layer_path) and not store.exists(mark_path):
return toolkit.api_error('Image already exists', 409)
input_stream = flask.request.stream
if flask.request.headers.get('transfer-encoding') == 'chunked':
# Careful, might work only with WSGI servers supporting chunked
# encoding (Gunicorn)
input_stream = flask.request.environ['wsgi.input']
# compute checksums
csums = []
sr = toolkit.SocketReader(input_stream)
tmp, store_hndlr = storage.temp_store_handler()
sr.add_handler(store_hndlr)
h, sum_hndlr = checksums.simple_checksum_handler(json_data)
sr.add_handler(sum_hndlr)
store.stream_write(layer_path, sr)
# read layer files and cache them
try:
files_json = json.dumps(layers.get_image_files_from_fobj(tmp))
layers.set_image_files_cache(image_id, files_json)
except Exception as e:
logger.debug('put_image_layer: Error when caching layer file-tree:'
'{0}'.format(e))
csums.append('sha256:{0}'.format(h.hexdigest()))
try:
tmp.seek(0)
csums.append(checksums.compute_tarsum(tmp, json_data))
except (IOError, checksums.TarError) as e:
logger.debug('put_image_layer: Error when computing tarsum '
'{0}'.format(e))
try:
checksum = store.get_content(store.image_checksum_path(image_id))
except IOError:
# We don't have a checksum stored yet, that's fine skipping the check.
# Not removing the mark though, image is not downloadable yet.
flask.session['checksum'] = csums
return toolkit.response()
# We check if the checksums provided matches one the one we computed
if checksum not in csums:
logger.debug('put_image_layer: Wrong checksum')
return toolkit.api_error('Checksum mismatch, ignoring the layer')
tmp.close()
# Checksum is ok, we remove the marker
store.remove(mark_path)
return toolkit.response()
示例6: put_repository
def put_repository(namespace, repository, images=False):
data = None
try:
data = json.loads(flask.request.data)
except json.JSONDecodeError:
return toolkit.api_error('Error Decoding JSON', 400)
if not isinstance(data, list):
return toolkit.api_error('Invalid data')
update_index_images(namespace, repository, flask.request.data)
headers = generate_headers(namespace, repository, 'write')
code = 204 if images is True else 200
return toolkit.response('', code, headers)
示例7: get_private_image_json
def get_private_image_json(image_id):
repository = toolkit.get_repository()
if not repository:
# No auth token found, either standalone registry or privileged access
# In both cases, private images are "disabled"
return toolkit.api_error('Image not found', 404)
try:
if not store.is_private(*repository):
return toolkit.api_error('Image not found', 404)
return _get_image_json(image_id)
except IOError:
return toolkit.api_error('Image not found', 404)
示例8: put_tag
def put_tag(namespace, repository, tag):
data = None
try:
data = json.loads(request.data)
except json.JSONDecodeError:
pass
if not data or not isinstance(data, basestring):
return api_error('Invalid data')
if not store.exists(store.image_json_path(data)):
return api_error('Image not found', 404)
store.put_content(store.tag_path(namespace, repository, tag), data)
return response()
示例9: put_tag
def put_tag(namespace, repository, tag):
logger.debug("[put_tag] namespace={0}; repository={1}; tag={2}".format(namespace, repository, tag))
data = None
try:
data = json.loads(request.data)
except json.JSONDecodeError:
pass
if not data or not isinstance(data, basestring):
return api_error("Invalid data")
if not store.exists(store.image_json_path(data)):
return api_error("Image not found", 404)
store.put_content(store.tag_path(namespace, repository, tag), data)
return response()
示例10: get_image_files
def get_image_files(image_id, headers):
try:
repository = toolkit.get_repository()
if repository and store.is_private(*repository):
return toolkit.api_error('Image not found', 404)
# If no auth token found, either standalone registry or privileged
# access. In both cases, access is always "public".
data = layers.get_image_files_json(image_id)
return toolkit.response(data, headers=headers, raw=True)
except IOError:
return toolkit.api_error('Image not found', 404)
except tarfile.TarError:
return toolkit.api_error('Layer format not supported', 400)
示例11: get_image_layer
def get_image_layer(image_id, headers):
try:
bytes_range = None
if store.supports_bytes_range:
headers['Accept-Ranges'] = 'bytes'
bytes_range = _parse_bytes_range()
repository = toolkit.get_repository()
if repository and store.is_private(*repository):
return toolkit.api_error('Image not found', 404)
# If no auth token found, either standalone registry or privileged
# access. In both cases, access is always "public".
return _get_image_layer(image_id, headers, bytes_range)
except IOError:
return toolkit.api_error('Image not found', 404)
示例12: get_private_image_files
def get_private_image_files(image_id, headers):
repository = toolkit.get_repository()
if not repository:
# No auth token found, either standalone registry or privileged access
# In both cases, private images are "disabled"
return toolkit.api_error('Image not found', 404)
try:
if not store.is_private(*repository):
return toolkit.api_error('Image not found', 404)
data = layers.get_image_files_json(image_id)
return toolkit.response(data, headers=headers, raw=True)
except IOError:
return toolkit.api_error('Image not found', 404)
except tarfile.TarError:
return toolkit.api_error('Layer format not supported', 400)
示例13: get_tag
def get_tag(namespace, repository, tag):
data = None
try:
data = store.get_content(store.tag_path(namespace, repository, tag))
except IOError:
return api_error('Tag not found', 404)
return response(data)
示例14: delete_tag
def delete_tag(namespace, repository, tag):
logger.debug("[delete_tag] namespace={0}; repository={1}; tag={2}".format(namespace, repository, tag))
try:
store.remove(store.tag_path(namespace, repository, tag))
except OSError:
return api_error("Tag not found", 404)
return response()
示例15: delete_repository
def delete_repository(namespace, repository):
logger.debug("[delete_repository] namespace={0}; repository={1}".format(namespace, repository))
try:
store.remove(store.tag_path(namespace, repository))
except OSError:
return api_error("Repository not found", 404)
return response()