Revision a421e0b9
b/snf-pithos-app/pithos/api/settings.py | ||
---|---|---|
1 | 1 |
#coding=utf8 |
2 | 2 |
from django.conf import settings |
3 | 3 |
from synnefo.lib import parse_base_url, join_urls |
4 |
from synnefo.lib.services import fill_endpoints |
|
4 |
from synnefo.lib.services import fill_endpoints, get_public_endpoint
|
|
5 | 5 |
from synnefo.util.keypath import get_path, set_path |
6 | 6 |
from pithos.api.services import pithos_services as vanilla_pithos_services |
7 | 7 |
from astakosclient import astakos_services as vanilla_astakos_services |
... | ... | |
103 | 103 |
PUBLIC_URL_ALPHABET = getattr( |
104 | 104 |
settings, |
105 | 105 |
'PITHOS_PUBLIC_URL_ALPHABET', |
106 |
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
107 |
) |
|
106 |
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
|
107 |
|
|
108 |
ASTAKOS_UI_URL = get_public_endpoint(astakos_services, 'astakos_ui', '').rstrip('/') |
|
109 |
|
|
110 |
# Astakos login URL to redirect if the user information is missing |
|
111 |
LOGIN_URL = join_urls(ASTAKOS_UI_URL, 'login') |
b/snf-pithos-app/pithos/api/util.py | ||
---|---|---|
35 | 35 |
from datetime import datetime |
36 | 36 |
from urllib import quote, unquote |
37 | 37 |
|
38 |
from django.http import HttpResponse, Http404, HttpResponseForbidden |
|
38 |
from django.http import (HttpResponse, HttpResponseRedirect, Http404, |
|
39 |
HttpResponseForbidden) |
|
39 | 40 |
from django.template.loader import render_to_string |
40 | 41 |
from django.utils import simplejson as json |
41 | 42 |
from django.utils.http import http_date, parse_etags |
... | ... | |
63 | 64 |
RADOS_POOL_MAPS, TRANSLATE_UUIDS, |
64 | 65 |
PUBLIC_URL_SECURITY, |
65 | 66 |
PUBLIC_URL_ALPHABET, |
66 |
COOKIE_NAME, BASE_HOST) |
|
67 |
COOKIE_NAME, BASE_HOST, LOGIN_URL)
|
|
67 | 68 |
from pithos.api.resources import resources |
68 | 69 |
from pithos.backends.base import (NotAllowedError, QuotaError, ItemNotExists, |
69 | 70 |
VersionNotExists) |
... | ... | |
1113 | 1114 |
def decorator(func): |
1114 | 1115 |
@wraps(func) |
1115 | 1116 |
def wrapper(request, *args, **kwargs): |
1116 |
request.META['HTTP_X_AUTH_TOKEN'] = get_token_from_cookie(request) |
|
1117 |
token = get_token_from_cookie(request) |
|
1118 |
if token is None: |
|
1119 |
return HttpResponseRedirect('%s?next=%s' % (LOGIN_URL, |
|
1120 |
request.path)) |
|
1121 |
request.META['HTTP_X_AUTH_TOKEN'] = token |
|
1117 | 1122 |
# Get the response object |
1118 | 1123 |
response = func(request, *args, **kwargs) |
1119 |
if response.status_code == 200:
|
|
1124 |
if response.status_code in [200, 206, 304, 412, 416]:
|
|
1120 | 1125 |
return response |
1121 | 1126 |
elif response.status_code == 404: |
1122 | 1127 |
raise Http404() |
1123 | 1128 |
elif response.status_code in [401, 403]: |
1124 | 1129 |
return HttpResponseForbidden() |
1125 | 1130 |
else: |
1126 |
raise Exception(response) |
|
1131 |
# unexpected response status |
|
1132 |
raise Exception(response.status_code) |
|
1127 | 1133 |
return wrapper |
1128 | 1134 |
return decorator |
Also available in: Unified diff