Revision f6c97079 pithos/api/functions.py
b/pithos/api/functions.py | ||
---|---|---|
59 | 59 |
|
60 | 60 |
def top_demux(request): |
61 | 61 |
if request.method == 'GET': |
62 |
if request.user: |
|
63 |
return account_list(request) |
|
62 | 64 |
return authenticate(request) |
63 | 65 |
else: |
64 | 66 |
return method_not_allowed(request) |
... | ... | |
125 | 127 |
x_auth_user) |
126 | 128 |
return response |
127 | 129 |
|
130 |
@api_method('GET', format_allowed=True) |
|
131 |
def account_list(request): |
|
132 |
# Normal Response Codes: 200, 204 |
|
133 |
# Error Response Codes: serviceUnavailable (503), |
|
134 |
# badRequest (400) |
|
135 |
|
|
136 |
response = HttpResponse() |
|
137 |
|
|
138 |
marker = request.GET.get('marker') |
|
139 |
limit = get_int_parameter(request.GET.get('limit')) |
|
140 |
if not limit: |
|
141 |
limit = 10000 |
|
142 |
|
|
143 |
accounts = backend.list_accounts(request.user, marker, limit) |
|
144 |
|
|
145 |
if request.serialization == 'text': |
|
146 |
if len(accounts) == 0: |
|
147 |
# The cloudfiles python bindings expect 200 if json/xml. |
|
148 |
response.status_code = 204 |
|
149 |
return response |
|
150 |
response.status_code = 200 |
|
151 |
response.content = '\n'.join(accounts) + '\n' |
|
152 |
return response |
|
153 |
|
|
154 |
account_meta = [] |
|
155 |
for x in accounts: |
|
156 |
try: |
|
157 |
meta = backend.get_account_meta(request.user, x) |
|
158 |
groups = backend.get_account_groups(request.user, x) |
|
159 |
except NotAllowedError: |
|
160 |
raise Unauthorized('Access denied') |
|
161 |
else: |
|
162 |
for k, v in groups.iteritems(): |
|
163 |
meta['X-Container-Group-' + k] = ','.join(v) |
|
164 |
account_meta.append(printable_header_dict(meta)) |
|
165 |
if request.serialization == 'xml': |
|
166 |
data = render_to_string('accounts.xml', {'accounts': account_meta}) |
|
167 |
elif request.serialization == 'json': |
|
168 |
data = json.dumps(account_meta) |
|
169 |
response.status_code = 200 |
|
170 |
response.content = data |
|
171 |
return response |
|
172 |
|
|
128 | 173 |
@api_method('HEAD') |
129 | 174 |
def account_meta(request, v_account): |
130 | 175 |
# Normal Response Codes: 204 |
... | ... | |
188 | 233 |
put_account_headers(response, meta, groups) |
189 | 234 |
|
190 | 235 |
marker = request.GET.get('marker') |
191 |
limit = request.GET.get('limit') |
|
192 |
if limit: |
|
193 |
try: |
|
194 |
limit = int(limit) |
|
195 |
if limit <= 0: |
|
196 |
raise ValueError |
|
197 |
except ValueError: |
|
198 |
limit = 10000 |
|
236 |
limit = get_int_parameter(request.GET.get('limit')) |
|
237 |
if not limit: |
|
238 |
limit = 10000 |
|
199 | 239 |
|
200 | 240 |
try: |
201 | 241 |
containers = backend.list_containers(request.user, v_account, marker, limit, until) |
... | ... | |
210 | 250 |
response.status_code = 204 |
211 | 251 |
return response |
212 | 252 |
response.status_code = 200 |
213 |
response.content = '\n'.join([x[0] for x in containers]) + '\n'
|
|
253 |
response.content = '\n'.join(containers) + '\n'
|
|
214 | 254 |
return response |
215 | 255 |
|
216 | 256 |
container_meta = [] |
217 | 257 |
for x in containers: |
218 |
if x[1] is not None: |
|
219 |
try: |
|
220 |
meta = backend.get_container_meta(request.user, v_account, x[0], until) |
|
221 |
policy = backend.get_container_policy(request.user, v_account, x[0]) |
|
222 |
except NotAllowedError: |
|
223 |
raise Unauthorized('Access denied') |
|
224 |
except NameError: |
|
225 |
pass |
|
226 |
else: |
|
227 |
for k, v in policy.iteritems(): |
|
228 |
meta['X-Container-Policy-' + k] = v |
|
229 |
container_meta.append(printable_header_dict(meta)) |
|
258 |
try: |
|
259 |
meta = backend.get_container_meta(request.user, v_account, x, until) |
|
260 |
policy = backend.get_container_policy(request.user, v_account, x) |
|
261 |
except NotAllowedError: |
|
262 |
raise Unauthorized('Access denied') |
|
263 |
except NameError: |
|
264 |
pass |
|
265 |
else: |
|
266 |
for k, v in policy.iteritems(): |
|
267 |
meta['X-Container-Policy-' + k] = v |
|
268 |
container_meta.append(printable_header_dict(meta)) |
|
230 | 269 |
if request.serialization == 'xml': |
231 | 270 |
data = render_to_string('containers.xml', {'account': v_account, 'containers': container_meta}) |
232 | 271 |
elif request.serialization == 'json': |
... | ... | |
376 | 415 |
prefix = prefix.lstrip('/') |
377 | 416 |
|
378 | 417 |
marker = request.GET.get('marker') |
379 |
limit = request.GET.get('limit') |
|
380 |
if limit: |
|
381 |
try: |
|
382 |
limit = int(limit) |
|
383 |
if limit <= 0: |
|
384 |
raise ValueError |
|
385 |
except ValueError: |
|
386 |
limit = 10000 |
|
418 |
limit = get_int_parameter(request.GET.get('limit')) |
|
419 |
if not limit: |
|
420 |
limit = 10000 |
|
387 | 421 |
|
388 | 422 |
keys = request.GET.get('meta') |
389 | 423 |
if keys: |
Also available in: Unified diff