本文整理汇总了Python中toolkit.api_error函数的典型用法代码示例。如果您正苦于以下问题:Python api_error函数的具体用法?Python api_error怎么用?Python api_error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了api_error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:inthecloud247,项目名称:docker-registry,代码行数:26,代码来源:images.py
示例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()
开发者ID:SandipSingh14,项目名称:docker-registry,代码行数:25,代码来源:tags.py
示例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()
开发者ID:xdissent,项目名称:docker-registry,代码行数:28,代码来源:images.py
示例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)
开发者ID:DominikTo,项目名称:docker-registry,代码行数:10,代码来源:images.py
示例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()
开发者ID:adduc,项目名称:docker-registry,代码行数:55,代码来源:images.py
示例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)
开发者ID:SandipSingh14,项目名称:docker-registry,代码行数:12,代码来源:index.py
示例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)
开发者ID:DominikTo,项目名称:docker-registry,代码行数:12,代码来源:images.py
示例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()
开发者ID:ehazlett,项目名称:docker-registry,代码行数:12,代码来源:tags.py
示例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()
开发者ID:hardiku,项目名称:docker-registry,代码行数:13,代码来源:tags.py
示例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)
开发者ID:DominikTo,项目名称:docker-registry,代码行数:13,代码来源:images.py
示例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)
开发者ID:DominikTo,项目名称:docker-registry,代码行数:14,代码来源:images.py
示例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)
开发者ID:DominikTo,项目名称:docker-registry,代码行数:15,代码来源:images.py
示例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)
开发者ID:ehazlett,项目名称:docker-registry,代码行数:7,代码来源:tags.py
示例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()
开发者ID:hardiku,项目名称:docker-registry,代码行数:7,代码来源:tags.py
示例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()
开发者ID:hardiku,项目名称:docker-registry,代码行数:7,代码来源:tags.py
示例16: get_image_ancestry
def get_image_ancestry(image_id, headers):
ancestry_path = store.image_ancestry_path(image_id)
try:
data = store.get_content(ancestry_path)
except IOError:
return toolkit.api_error('Image not found', 404)
return toolkit.response(json.loads(data), headers=headers)
开发者ID:jonasfj,项目名称:docker-registry,代码行数:7,代码来源:images.py
示例17: delete_repository
def delete_repository(namespace, repository):
"""Remove a repository from storage
This endpoint exists in both the registry API [1] and the indexer
API [2], but has the same semantics in each instance. It's in the
tags module (instead of the index module which handles most
repository tasks) because it should be available regardless of
whether the rest of the index-module endpoints are enabled via the
'standalone' config setting.
[1]: http://docs.docker.io/en/latest/reference/api/registry_api/#delete--v1-repositories-%28namespace%29-%28repository%29- # nopep8
[2]: http://docs.docker.io/en/latest/reference/api/index_api/#delete--v1-repositories-%28namespace%29-%28repo_name%29- # nopep8
"""
logger.debug("[delete_repository] namespace={0}; repository={1}".format(
namespace, repository))
try:
for tag_name, tag_content in get_tags(
namespace=namespace, repository=repository):
delete_tag(
namespace=namespace, repository=repository, tag=tag_name)
# TODO(wking): remove images, but may need refcounting
store.remove(store.repository_path(
namespace=namespace, repository=repository))
except OSError:
return toolkit.api_error('Repository not found', 404)
else:
sender = flask.current_app._get_current_object()
signals.repository_deleted.send(
sender, namespace=namespace, repository=repository)
return toolkit.response()
开发者ID:SandipSingh14,项目名称:docker-registry,代码行数:30,代码来源:tags.py
示例18: get_post_users
def get_post_users():
if flask.request.method == 'GET':
return toolkit.response('OK', 200)
try:
json.loads(flask.request.data)
except json.JSONDecodeError:
return toolkit.api_error('Error Decoding JSON', 400)
return toolkit.response('User Created', 201)
开发者ID:SandipSingh14,项目名称:docker-registry,代码行数:8,代码来源:index.py
示例19: 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)
return toolkit.response()
开发者ID:23critters,项目名称:docker-registry,代码行数:17,代码来源:tags.py
示例20: get_tag
def get_tag(namespace, repository, tag):
logger.debug("[get_tag] namespace={0}; repository={1}; tag={2}".format(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)
开发者ID:hardiku,项目名称:docker-registry,代码行数:8,代码来源:tags.py
注:本文中的toolkit.api_error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论