Make abort return a json block, which is apparently what the client expects. Remove unused imports. Fix line length and kwarg problems.
This commit is contained in:
parent
0d84cfdf17
commit
f585430399
4 changed files with 58 additions and 39 deletions
|
@ -1,8 +1,8 @@
|
|||
import logging
|
||||
import json
|
||||
|
||||
from flask import (make_response, request, session, Response, abort as flask_abort,
|
||||
redirect, Blueprint)
|
||||
from flask import (make_response, request, session, Response, redirect,
|
||||
Blueprint)
|
||||
from functools import wraps
|
||||
from datetime import datetime
|
||||
from time import time
|
||||
|
@ -59,7 +59,8 @@ def require_completion(f):
|
|||
def wrapper(namespace, repository, *args, **kwargs):
|
||||
if store.exists(store.image_mark_path(namespace, repository,
|
||||
kwargs['image_id'])):
|
||||
abort(400, 'Image %(image_id)s is being uploaded, retry later', image_id=kwargs['image_id'])
|
||||
abort(400, 'Image %(image_id)s is being uploaded, retry later',
|
||||
image_id=kwargs['image_id'])
|
||||
|
||||
return f(namespace, repository, *args, **kwargs)
|
||||
return wrapper
|
||||
|
@ -194,7 +195,8 @@ def put_image_checksum(namespace, repository, image_id):
|
|||
abort(400, "Missing checksum for image %(image_id)s", image_id=image_id)
|
||||
|
||||
if not session.get('checksum'):
|
||||
abort(400, 'Checksum not found in Cookie for image %(imaage_id)s', image_id=image_id)
|
||||
abort(400, 'Checksum not found in Cookie for image %(imaage_id)s',
|
||||
image_id=image_id)
|
||||
|
||||
if not store.exists(store.image_json_path(namespace, repository, image_id)):
|
||||
abort(404, 'Image not found: %(image_id)s', image_id=image_id)
|
||||
|
@ -321,10 +323,12 @@ def put_image_json(namespace, repository, image_id):
|
|||
except json.JSONDecodeError:
|
||||
pass
|
||||
if not data or not isinstance(data, dict):
|
||||
abort(400, 'Invalid JSON for image: %(image_id)s\nJSON: %(json)s', image_id=image_id, json=request.data)
|
||||
abort(400, 'Invalid JSON for image: %(image_id)s\nJSON: %(json)s',
|
||||
image_id=image_id, json=request.data)
|
||||
|
||||
if 'id' not in data:
|
||||
abort(400, 'Missing key `id` in JSON for image: %(image_id)s', image_id=image_id)
|
||||
abort(400, 'Missing key `id` in JSON for image: %(image_id)s',
|
||||
image_id=image_id)
|
||||
|
||||
# Read the checksum
|
||||
checksum = request.headers.get('X-Docker-Checksum')
|
||||
|
@ -338,10 +342,12 @@ def put_image_json(namespace, repository, image_id):
|
|||
# We cleanup any old checksum in case it's a retry after a fail
|
||||
store.remove(store.image_checksum_path(namespace, repository, image_id))
|
||||
if image_id != data['id']:
|
||||
abort(400, 'JSON data contains invalid id for image: %(image_id)s', image_id=image_id)
|
||||
abort(400, 'JSON data contains invalid id for image: %(image_id)s',
|
||||
image_id=image_id)
|
||||
|
||||
parent_id = data.get('parent')
|
||||
if parent_id and not store.exists(store.image_json_path(namespace, repository, parent_id)):
|
||||
if (parent_id and not
|
||||
store.exists(store.image_json_path(namespace, repository, parent_id))):
|
||||
abort(400, 'Image %(image_id)s depends on non existing parent image %(parent_id)s',
|
||||
image_id=image_id, parent_id=parent_id)
|
||||
|
||||
|
|
Reference in a new issue