Commit 2a882371 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

astakos: Fix bug in Astakos stats view

'ASTAKOS_AUTH_URL' setting is not present in Astakos node.
parent b9144a81
......@@ -36,12 +36,19 @@ from django import http
from django.utils import simplejson as json
from snf_django.lib import api
from astakos.im import settings
from synnefo.lib.services import get_path
from astakos.admin import stats
logger = logging.getLogger(__name__)
PERMITTED_GROUPS = settings.ADMIN_STATS_PERMITTED_GROUPS
try:
AUTH_URL = get_path(settings.astakos_services,
"astakos_identity.endpoints")[0]["publicURL"]
except (IndexError, KeyError) as e:
logger.error("Failed to load Astakos Auth URL: %s", e)
AUTH_URL = None
@api.api_method(http_method='GET', user_required=False, token_required=False,
......@@ -54,6 +61,7 @@ def get_public_stats(request):
@api.api_method(http_method='GET', user_required=True, token_required=True,
astakos_auth_url=AUTH_URL,
logger=logger, serializations=['json'])
@api.user_in_groups(permitted_groups=PERMITTED_GROUPS,
logger=logger)
......
......@@ -106,8 +106,15 @@ 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_auth_url or settings.ASTAKOS_AUTH_URL
astakos = AstakosClient(token, astakos,
astakos_url = astakos_auth_url
if astakos_url is None:
try:
astakos_url = settings.ASTAKOS_AUTH_URL
except AttributeError:
logger.error("Cannot authenticate without having"
" an Astakos Authentication URL")
raise
astakos = AstakosClient(token, astakos_url,
use_pool=True,
retry=2,
logger=logger)
......
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