Revision 2715ade4 snf-pithos-app/pithos/api/public.py
b/snf-pithos-app/pithos/api/public.py | ||
---|---|---|
1 | 1 |
# Copyright 2011-2012 GRNET S.A. All rights reserved. |
2 |
#
|
|
2 |
# |
|
3 | 3 |
# Redistribution and use in source and binary forms, with or |
4 | 4 |
# without modification, are permitted provided that the following |
5 | 5 |
# conditions are met: |
6 |
#
|
|
6 |
# |
|
7 | 7 |
# 1. Redistributions of source code must retain the above |
8 | 8 |
# copyright notice, this list of conditions and the following |
9 | 9 |
# disclaimer. |
10 |
#
|
|
10 |
# |
|
11 | 11 |
# 2. Redistributions in binary form must reproduce the above |
12 | 12 |
# copyright notice, this list of conditions and the following |
13 | 13 |
# disclaimer in the documentation and/or other materials |
14 | 14 |
# provided with the distribution. |
15 |
#
|
|
15 |
# |
|
16 | 16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
17 | 17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | 18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
... | ... | |
25 | 25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
26 | 26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 | 27 |
# POSSIBILITY OF SUCH DAMAGE. |
28 |
#
|
|
28 |
# |
|
29 | 29 |
# The views and conclusions contained in the software and |
30 | 30 |
# documentation are those of the authors and should not be |
31 | 31 |
# interpreted as representing official policies, either expressed |
... | ... | |
40 | 40 |
|
41 | 41 |
from pithos.api.faults import (Fault, BadRequest, ItemNotFound) |
42 | 42 |
from pithos.api.util import (put_object_headers, update_manifest_meta, |
43 |
validate_modification_preconditions, validate_matching_preconditions, |
|
44 |
object_data_response, api_method) |
|
43 |
validate_modification_preconditions, validate_matching_preconditions,
|
|
44 |
object_data_response, api_method)
|
|
45 | 45 |
from pithos.api.short_url import decode_url |
46 | 46 |
from pithos.api.settings import AUTHENTICATION_URL, AUTHENTICATION_USERS |
47 | 47 |
|
... | ... | |
59 | 59 |
else: |
60 | 60 |
return method_not_allowed(request) |
61 | 61 |
|
62 |
|
|
62 | 63 |
@api_method('HEAD', user_required=False) |
63 | 64 |
def public_meta(request, v_public): |
64 | 65 |
# Normal Response Codes: 204 |
65 | 66 |
# Error Response Codes: internalServerError (500), |
66 | 67 |
# itemNotFound (404), |
67 | 68 |
# badRequest (400) |
68 |
|
|
69 |
|
|
69 | 70 |
try: |
70 |
v_account, v_container, v_object = request.backend.get_public(request.user_uniq, |
|
71 |
decode_url(v_public)) |
|
71 |
v_account, v_container, v_object = request.backend.get_public( |
|
72 |
request.user_uniq, |
|
73 |
decode_url(v_public)) |
|
72 | 74 |
meta = request.backend.get_object_meta(request.user_uniq, v_account, |
73 |
v_container, v_object, 'pithos') |
|
74 |
public = request.backend.get_object_public(request.user_uniq, v_account, |
|
75 |
v_container, v_object) |
|
75 |
v_container, v_object, 'pithos') |
|
76 |
public = request.backend.get_object_public( |
|
77 |
request.user_uniq, v_account, |
|
78 |
v_container, v_object) |
|
76 | 79 |
except: |
77 | 80 |
raise ItemNotFound('Object does not exist') |
78 |
|
|
81 |
|
|
79 | 82 |
if not public: |
80 | 83 |
raise ItemNotFound('Object does not exist') |
81 | 84 |
update_manifest_meta(request, v_account, meta) |
82 |
|
|
85 |
|
|
83 | 86 |
response = HttpResponse(status=200) |
84 | 87 |
put_object_headers(response, meta, True) |
85 | 88 |
return response |
86 | 89 |
|
90 |
|
|
87 | 91 |
@api_method('GET', user_required=False) |
88 | 92 |
def public_read(request, v_public): |
89 | 93 |
# Normal Response Codes: 200, 206 |
... | ... | |
93 | 97 |
# itemNotFound (404), |
94 | 98 |
# badRequest (400), |
95 | 99 |
# notModified (304) |
96 |
|
|
97 | 100 |
try: |
98 |
v_account, v_container, v_object = request.backend.get_public(request.user_uniq, |
|
99 |
decode_url(v_public)) |
|
101 |
v_account, v_container, v_object = request.backend.get_public( |
|
102 |
request.user_uniq, |
|
103 |
decode_url(v_public)) |
|
100 | 104 |
meta = request.backend.get_object_meta(request.user_uniq, v_account, |
101 |
v_container, v_object, 'pithos') |
|
102 |
public = request.backend.get_object_public(request.user_uniq, v_account, |
|
103 |
v_container, v_object) |
|
105 |
v_container, v_object, 'pithos') |
|
106 |
public = request.backend.get_object_public( |
|
107 |
request.user_uniq, v_account, |
|
108 |
v_container, v_object) |
|
104 | 109 |
except: |
105 | 110 |
raise ItemNotFound('Object does not exist') |
106 |
|
|
111 |
|
|
107 | 112 |
if not public: |
108 | 113 |
raise ItemNotFound('Object does not exist') |
109 | 114 |
update_manifest_meta(request, v_account, meta) |
110 |
|
|
115 |
|
|
111 | 116 |
# Evaluate conditions. |
112 | 117 |
validate_modification_preconditions(request, meta) |
113 | 118 |
try: |
... | ... | |
116 | 121 |
response = HttpResponse(status=304) |
117 | 122 |
response['ETag'] = meta['ETag'] |
118 | 123 |
return response |
119 |
|
|
124 |
|
|
120 | 125 |
sizes = [] |
121 | 126 |
hashmaps = [] |
122 | 127 |
if 'X-Object-Manifest' in meta: |
123 | 128 |
try: |
124 |
src_container, src_name = split_container_object_string('/' + meta['X-Object-Manifest']) |
|
125 |
objects = request.backend.list_objects(request.user_uniq, v_account, |
|
126 |
src_container, prefix=src_name, virtual=False) |
|
129 |
src_container, src_name = split_container_object_string( |
|
130 |
'/' + meta['X-Object-Manifest']) |
|
131 |
objects = request.backend.list_objects( |
|
132 |
request.user_uniq, v_account, |
|
133 |
src_container, prefix=src_name, virtual=False) |
|
127 | 134 |
except: |
128 | 135 |
raise ItemNotFound('Object does not exist') |
129 |
|
|
136 |
|
|
130 | 137 |
try: |
131 | 138 |
for x in objects: |
132 | 139 |
s, h = request.backend.get_object_hashmap(request.user_uniq, |
133 |
v_account, src_container, x[0], x[1]) |
|
140 |
v_account, src_container, x[0], x[1])
|
|
134 | 141 |
sizes.append(s) |
135 | 142 |
hashmaps.append(h) |
136 | 143 |
except: |
137 | 144 |
raise ItemNotFound('Object does not exist') |
138 | 145 |
else: |
139 | 146 |
try: |
140 |
s, h = request.backend.get_object_hashmap(request.user_uniq, v_account, |
|
141 |
v_container, v_object) |
|
147 |
s, h = request.backend.get_object_hashmap( |
|
148 |
request.user_uniq, v_account, |
|
149 |
v_container, v_object) |
|
142 | 150 |
sizes.append(s) |
143 | 151 |
hashmaps.append(h) |
144 | 152 |
except: |
145 | 153 |
raise ItemNotFound('Object does not exist') |
146 |
|
|
154 |
|
|
147 | 155 |
if 'Content-Disposition' not in meta: |
148 | 156 |
name = v_object.rstrip('/').split('/')[-1] |
149 | 157 |
if not name: |
150 | 158 |
name = v_public |
151 | 159 |
meta['Content-Disposition'] = 'attachment; filename=%s' % (name,) |
152 |
|
|
160 |
|
|
153 | 161 |
return object_data_response(request, sizes, hashmaps, meta, True) |
154 | 162 |
|
163 |
|
|
155 | 164 |
@api_method(user_required=False) |
156 | 165 |
def method_not_allowed(request, **v_args): |
157 | 166 |
raise ItemNotFound('Object does not exist') |
Also available in: Unified diff