Revision 63de12cf

b/snf-pithos-app/pithos/api/functions.py
816 816

  
817 817
@api_method('GET', format_allowed=True, user_required=True, logger=logger)
818 818
def object_read(request, v_account, v_container, v_object):
819
    return _object_read(request, v_account, v_container, v_object)
820

  
821

  
822
def _object_read(request, v_account, v_container, v_object):
819 823
    # Normal Response Codes: 200, 206
820 824
    # Error Response Codes: internalServerError (500),
821 825
    #                       rangeNotSatisfiable (416),
b/snf-pithos-app/pithos/api/urls.py
40 40
    BASE_PATH, ASTAKOS_BASE_URL, BASE_ASTAKOS_PROXY_PATH,
41 41
    ASTAKOS_ACCOUNTS_PREFIX, PROXY_USER_SERVICES,
42 42
    PITHOS_PREFIX, PUBLIC_PREFIX, UI_PREFIX)
43
from urlparse import urlparse
44 43

  
45 44

  
46 45
# TODO: This only works when in this order.
......
53 52
    'container_demux'),
54 53
    (r'^(?P<v_account>.+?)/?$', 'account_demux'))
55 54

  
55
pithos_view_patterns = patterns(
56
    'pithos.api.views',
57
    (r'^(?P<v_account>.+?)/(?P<v_container>.+?)/(?P<v_object>.+?)$',
58
    'object_read'))
59

  
56 60
pithos_patterns = patterns(
57 61
    '',
58 62
    (r'{0}v1/'.format(prefix_pattern(PITHOS_PREFIX)),
59 63
        include(pithos_api_patterns)),
60 64
    (r'{0}(?P<v_public>.+?)/?$'.format(prefix_pattern(PUBLIC_PREFIX)),
61
        'pithos.api.public.public_demux'))
65
        'pithos.api.public.public_demux'),
66
    (r'{0}v1/'.format(prefix_pattern(UI_PREFIX)),
67
        include(pithos_view_patterns)))
62 68

  
63 69
urlpatterns = patterns(
64 70
    '',
b/snf-pithos-app/pithos/api/util.py
1091 1091
                    request.backend.close()
1092 1092
        return wrapper
1093 1093
    return decorator
1094

  
1095

  
1096
def get_token_from_cookie(request):
1097
    assert(request.method == 'GET'),\
1098
        "Cookie based authentication is only allowed to GET requests"
1099
    token = None
1100
    if COOKIE_NAME in request.COOKIES:
1101
        cookie_value = unquote(request.COOKIES.get(COOKIE_NAME, ''))
1102
        account, sep, token = cookie_value.partition('|')
1103
    return token
1104

  
1105

  
1106
def view_method():
1107
    """Decorator function for views."""
1108

  
1109
    def decorator(func):
1110
        @wraps(func)
1111
        def wrapper(request, *args, **kwargs):
1112
            request.META['HTTP_X_AUTH_TOKEN'] = get_token_from_cookie(request)
1113
            # Get the response object
1114
            response = func(request, *args, **kwargs)
1115
            # TODO: support additional success codes
1116
            if response.status_code == 200:
1117
                return response
1118
            else:
1119
                # TODO: raise more specific exceptions
1120
                raise Exception()
1121
        return wrapper
1122
    return decorator
b/snf-pithos-app/pithos/api/views.py
1
# Create your views here.
1
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34
from pithos.api.functions import _object_read
35
from pithos.api.util import api_method, view_method
36

  
37
import logging
38
logger = logging.getLogger(__name__)
39

  
40

  
41
@view_method()
42
@api_method('GET', format_allowed=True, user_required=True, logger=logger)
43
def object_read(request, v_account, v_container, v_object):
44
    return _object_read(request, v_account, v_container, v_object)

Also available in: Unified diff