From dfdf4802ed6a258d3fd97280793225ec43f56ba6 Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki Date: Tue, 19 Jun 2012 19:37:37 +0300 Subject: [PATCH] fix feedback response in case of URLError --- snf-pithos-app/pithos/api/delegate.py | 4 +++- snf-pithos-app/pithos/api/functions.py | 17 ++++------------- snf-pithos-app/pithos/api/util.py | 20 ++++++++++++++++---- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/snf-pithos-app/pithos/api/delegate.py b/snf-pithos-app/pithos/api/delegate.py index c3083ea..e665723 100644 --- a/snf-pithos-app/pithos/api/delegate.py +++ b/snf-pithos-app/pithos/api/delegate.py @@ -82,7 +82,9 @@ def delegate_to_feedback_service(request): try: urllib2.urlopen(req) except urllib2.HTTPError, e: + logger.exception(e) return HttpResponse(status=e.code) except urllib2.URLError, e: - return HttpResponseNotFound(e) + logger.exception(e) + return HttpResponse(status=e.reason) return HttpResponse() \ No newline at end of file diff --git a/snf-pithos-app/pithos/api/functions.py b/snf-pithos-app/pithos/api/functions.py index f1488b8..9909cd2 100644 --- a/snf-pithos-app/pithos/api/functions.py +++ b/snf-pithos-app/pithos/api/functions.py @@ -52,7 +52,7 @@ from pithos.api.util import (json_encode_decimal, rename_meta_key, format_header validate_modification_preconditions, validate_matching_preconditions, split_container_object_string, copy_or_move_object, get_int_parameter, get_content_length, get_content_range, socket_read_iterator, SaveToBackendHandler, object_data_response, put_object_block, hashmap_md5, simple_list_response, api_method) -from pithos.api.settings import AUTHENTICATION_URL, AUTHENTICATION_USERS, COOKIE_NAME, UPDATE_MD5 +from pithos.api.settings import UPDATE_MD5 from pithos.backends.base import NotAllowedError, QuotaError from pithos.backends.filter import parse_filters @@ -66,17 +66,13 @@ logger = logging.getLogger(__name__) @csrf_exempt def top_demux(request): - get_user(request, AUTHENTICATION_URL, AUTHENTICATION_USERS) if request.method == 'GET': - if getattr(request, 'user', None) is not None: - return account_list(request) - return authenticate(request) + return account_list(request) else: return method_not_allowed(request) @csrf_exempt def account_demux(request, v_account): - get_user(request, AUTHENTICATION_URL, AUTHENTICATION_USERS) if request.method == 'HEAD': return account_meta(request, v_account) elif request.method == 'POST': @@ -88,7 +84,6 @@ def account_demux(request, v_account): @csrf_exempt def container_demux(request, v_account, v_container): - get_user(request, AUTHENTICATION_URL, AUTHENTICATION_USERS) if request.method == 'HEAD': return container_meta(request, v_account, v_container) elif request.method == 'PUT': @@ -105,12 +100,6 @@ def container_demux(request, v_account, v_container): @csrf_exempt def object_demux(request, v_account, v_container, v_object): # Helper to avoid placing the token in the URL when loading objects from a browser. - token = None - if request.method in ('HEAD', 'GET') and COOKIE_NAME in request.COOKIES: - cookie_value = unquote(request.COOKIES.get(COOKIE_NAME, '')) - if cookie_value and '|' in cookie_value: - token = cookie_value.split('|', 1)[1] - get_user(request, AUTHENTICATION_URL, AUTHENTICATION_USERS, token) if request.method == 'HEAD': return object_meta(request, v_account, v_container, v_object) elif request.method == 'GET': @@ -156,6 +145,8 @@ def account_list(request): # Normal Response Codes: 200, 204 # Error Response Codes: internalServerError (500), # badRequest (400) + if getattr(request, 'user', None) is None: + return authenticate(request) response = HttpResponse() diff --git a/snf-pithos-app/pithos/api/util.py b/snf-pithos-app/pithos/api/util.py index 7dbaf4c..28ebed9 100644 --- a/snf-pithos-app/pithos/api/util.py +++ b/snf-pithos-app/pithos/api/util.py @@ -49,6 +49,7 @@ from django.core.files.uploadhandler import FileUploadHandler from django.core.files.uploadedfile import UploadedFile from synnefo.lib.parsedate import parse_http_date_safe, parse_http_date +from synnefo.lib.astakos import get_user from pithos.api.faults import (Fault, NotModified, BadRequest, Unauthorized, Forbidden, ItemNotFound, Conflict, LengthRequired, PreconditionFailed, RequestEntityTooLarge, @@ -58,7 +59,10 @@ from pithos.api.settings import (BACKEND_DB_MODULE, BACKEND_DB_CONNECTION, BACKEND_BLOCK_MODULE, BACKEND_BLOCK_PATH, BACKEND_BLOCK_UMASK, BACKEND_QUEUE_MODULE, BACKEND_QUEUE_CONNECTION, - BACKEND_QUOTA, BACKEND_VERSIONING) + BACKEND_QUOTA, BACKEND_VERSIONING, + AUTHENTICATION_URL, AUTHENTICATION_USERS, + SERVICE_TOKEN, COOKIE_NAME) + from pithos.backends import connect_backend from pithos.backends.base import NotAllowedError, QuotaError @@ -875,8 +879,16 @@ def api_method(http_method=None, format_allowed=False, user_required=True): try: if http_method and request.method != http_method: raise BadRequest('Method not allowed.') - if user_required and getattr(request, 'user', None) is None: - raise Unauthorized('Access denied') + + if user_required: + token = None + if request.method in ('HEAD', 'GET') and COOKIE_NAME in request.COOKIES: + cookie_value = unquote(request.COOKIES.get(COOKIE_NAME, '')) + if cookie_value and '|' in cookie_value: + token = cookie_value.split('|', 1)[1] + get_user(request, IDENTITY_BASEURL, AUTHENTICATION_USERS, token) + if getattr(request, 'user', None) is None: + raise Unauthorized('Access denied') # The args variable may contain up to (account, container, object). if len(args) > 1 and len(args[1]) > 256: @@ -898,7 +910,7 @@ def api_method(http_method=None, format_allowed=False, user_required=True): return render_fault(request, fault) except BaseException, e: logger.exception('Unexpected error: %s' % e) - fault = InternalServerError('Unexpected error') + fault = InternalServerError('Unexpected error: %s' % e) return render_fault(request, fault) finally: if getattr(request, 'backend', None) is not None: -- 1.7.10.4