diff --git a/auth/auth.py b/auth/auth.py index 9c6281aef..f751d6814 100644 --- a/auth/auth.py +++ b/auth/auth.py @@ -1,7 +1,7 @@ import logging from functools import wraps -from flask import request, _request_ctx_stack, abort, session +from flask import request, _request_ctx_stack, abort as flask_abort, session from flask.ext.principal import identity_changed, Identity from base64 import b64decode @@ -10,6 +10,7 @@ from app import app from permissions import QuayDeferredPermissionUser from util.names import parse_namespace_repository +from util.http import abort logger = logging.getLogger(__name__) @@ -89,13 +90,13 @@ def process_token(auth): if len(token_details) != 1: logger.warning('Invalid token format: %s' % auth) - abort(401) + abort(401, message="Invalid token format: %(auth)", issue='invalid-auth-token', auth=auth) token_vals = {val[0]: val[1] for val in (detail.split('=') for detail in token_details)} if 'signature' not in token_vals: logger.warning('Token does not contain signature: %s' % auth) - abort(401) + abort(401, message="Token does not contain a valid signature: %(auth)", issue='invalid-auth-token', auth=auth) try: token_data = model.load_token_data(token_vals['signature']) @@ -103,7 +104,7 @@ def process_token(auth): except model.InvalidTokenException: logger.warning('Token could not be validated: %s' % token_vals['signature']) - abort(401) + abort(401, message="Token could not be validated: %(auth)", issue='invalid-auth-token', auth=auth) logger.debug('Successfully validated token: %s' % token_data.code) ctx = _request_ctx_stack.top @@ -134,7 +135,7 @@ def extract_namespace_repo_from_session(f): if 'namespace' not in session or 'repository' not in session: logger.error('Unable to load namespace or repository from session: %s' % session) - abort(400) + abort(400, message="Missing namespace in request") return f(session['namespace'], session['repository'], *args, **kwargs) return wrapper diff --git a/endpoints/registry.py b/endpoints/registry.py index 9727d5ccb..211c2e12b 100644 --- a/endpoints/registry.py +++ b/endpoints/registry.py @@ -259,7 +259,7 @@ def get_image_json(namespace, repository, image_id, headers): data = store.get_content(store.image_json_path(namespace, repository, image_id, uuid)) except IOError: - flask_abort(404) + abort(404, message='Image data not found') try: size = store.get_size(store.image_layer_path(namespace, repository, diff --git a/util/http.py b/util/http.py index 6592768cc..a678c97ec 100644 --- a/util/http.py +++ b/util/http.py @@ -2,7 +2,6 @@ import logging from app import mixpanel from flask import request, abort as flask_abort, jsonify -from auth.auth import get_authenticated_user, get_validated_token logger = logging.getLogger(__name__) @@ -16,6 +15,8 @@ DEFAULT_MESSAGE[409] = 'Conflict' DEFAULT_MESSAGE[501] = 'Not Implemented' def abort(status_code, message=None, issue=None, **kwargs): + from auth.auth import get_authenticated_user, get_validated_token + message = (str(message) % kwargs if message else DEFAULT_MESSAGE.get(status_code, ''))