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
@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':
@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':
@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':
# Normal Response Codes: 200, 204
# Error Response Codes: internalServerError (500),
# badRequest (400)
+ if getattr(request, 'user', None) is None:
+ return authenticate(request)
response = HttpResponse()
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,
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
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:
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: