Commit e264d084 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Make 'api_method' to take astakos_url as argument

parent 3e941c3a
......@@ -60,7 +60,7 @@ def get_token(request):
def api_method(http_method=None, token_required=True, user_required=True,
logger=None, format_allowed=True):
logger=None, format_allowed=True, astakos_url=None):
"""Decorator function for views that implement an API method."""
if not logger:
logger = log
......@@ -89,8 +89,9 @@ def api_method(http_method=None, token_required=True, user_required=True,
# Authenticate
if user_required:
assert(token_required), "Can not get user without token"
astakos = astakos_url or settings.ASTAKOS_URL
try:
astakos = AstakosClient(settings.ASTAKOS_URL,
astakos = AstakosClient(astakos,
use_pool=True,
logger=logger)
user_info = astakos.get_user_info(token)
......@@ -166,7 +167,7 @@ def update_response_headers(request, response):
raise ValueError("Unknown serialization format '%s'" %
serialization)
if settings.DEBUG or settings.TEST:
if settings.DEBUG or getattr(settings, "TEST", False):
response["Date"] = format_date_time(time())
if not response.has_header("Content-Length"):
......@@ -182,7 +183,7 @@ def update_response_headers(request, response):
def render_fault(request, fault):
"""Render an API fault to an HTTP response."""
# If running in debug mode add exception information to fault details
if settings.DEBUG or settings.TEST:
if settings.DEBUG or getattr(settings, "TEST", False):
fault.details = format_exc()
try:
......
......@@ -1015,7 +1015,8 @@ def api_method(http_method=None, user_required=True, logger=None,
format_allowed=False):
def decorator(func):
@api.api_method(http_method=http_method, user_required=user_required,
logger=logger, format_allowed=format_allowed)
logger=logger, format_allowed=format_allowed,
astakos_url=ASTAKOS_URL)
@wraps(func)
def wrapper(request, *args, **kwargs):
# The args variable may contain up to (account, container, object).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment