Revision dfdf4802 snf-pithos-app/pithos/api/functions.py

b/snf-pithos-app/pithos/api/functions.py
52 52
    validate_modification_preconditions, validate_matching_preconditions, split_container_object_string,
53 53
    copy_or_move_object, get_int_parameter, get_content_length, get_content_range, socket_read_iterator,
54 54
    SaveToBackendHandler, object_data_response, put_object_block, hashmap_md5, simple_list_response, api_method)
55
from pithos.api.settings import AUTHENTICATION_URL, AUTHENTICATION_USERS, COOKIE_NAME, UPDATE_MD5
55
from pithos.api.settings import UPDATE_MD5
56 56

  
57 57
from pithos.backends.base import NotAllowedError, QuotaError
58 58
from pithos.backends.filter import parse_filters
......
66 66

  
67 67
@csrf_exempt
68 68
def top_demux(request):
69
    get_user(request, AUTHENTICATION_URL, AUTHENTICATION_USERS)
70 69
    if request.method == 'GET':
71
        if getattr(request, 'user', None) is not None:
72
            return account_list(request)
73
        return authenticate(request)
70
        return account_list(request)
74 71
    else:
75 72
        return method_not_allowed(request)
76 73

  
77 74
@csrf_exempt
78 75
def account_demux(request, v_account):
79
    get_user(request, AUTHENTICATION_URL, AUTHENTICATION_USERS)
80 76
    if request.method == 'HEAD':
81 77
        return account_meta(request, v_account)
82 78
    elif request.method == 'POST':
......
88 84

  
89 85
@csrf_exempt
90 86
def container_demux(request, v_account, v_container):
91
    get_user(request, AUTHENTICATION_URL, AUTHENTICATION_USERS)
92 87
    if request.method == 'HEAD':
93 88
        return container_meta(request, v_account, v_container)
94 89
    elif request.method == 'PUT':
......
105 100
@csrf_exempt
106 101
def object_demux(request, v_account, v_container, v_object):
107 102
    # Helper to avoid placing the token in the URL when loading objects from a browser.
108
    token = None
109
    if request.method in ('HEAD', 'GET') and COOKIE_NAME in request.COOKIES:
110
        cookie_value = unquote(request.COOKIES.get(COOKIE_NAME, ''))
111
        if cookie_value and '|' in cookie_value:
112
            token = cookie_value.split('|', 1)[1]
113
    get_user(request, AUTHENTICATION_URL, AUTHENTICATION_USERS, token)
114 103
    if request.method == 'HEAD':
115 104
        return object_meta(request, v_account, v_container, v_object)
116 105
    elif request.method == 'GET':
......
156 145
    # Normal Response Codes: 200, 204
157 146
    # Error Response Codes: internalServerError (500),
158 147
    #                       badRequest (400)
148
    if getattr(request, 'user', None) is None:
149
        return authenticate(request)
159 150
    
160 151
    response = HttpResponse()
161 152
    

Also available in: Unified diff