Revision 8cb96389 snf-astakos-app/astakos/api/tokens.py

b/snf-astakos-app/astakos/api/tokens.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34
from urlparse import urlunsplit, urlsplit
35
from collections import defaultdict
35 36

  
36 37
from django.http import urlencode
37 38
from django.views.decorators.csrf import csrf_exempt
......
114 115
        if user.uuid != uuid:
115 116
            raise faults.Unauthorized('Invalid credentials')
116 117

  
117
    access = {}
118
    access['token'] = {'id': user.auth_token,
119
                       'expires': utils.isoformat(user.auth_token_expires),
120
                       'tenant': {'id': user.uuid, 'name': user.realname}}
121
    access['user'] = {'id': user.uuid, 'name': user.realname,
122
                      'roles': list(user.groups.values('id', 'name')),
123
                      'roles_links': []}
124
    access['serviceCatalog'] = []
125
    append = access['serviceCatalog'].append
126
    for s in Service.objects.all().order_by('id'):
127
        append({'name': s.name, 'type': s.type,
128
                'endpoints': [{'adminURL': s.api_url,
129
                               'publicURL': s.api_url,
130
                               'internalURL': s.api_url,
131
                               'SNF:uiURL': s.url,
132
                               'region': s.name}]})
118
    d = defaultdict(dict)
119
    d["access"]["token"] = {
120
        "id": user.auth_token,
121
        "expires": utils.isoformat(user.auth_token_expires),
122
        "tenant": {"id": user.uuid, "name": user.realname}}
123
    d["access"]["user"] = {
124
        "id": user.uuid, 'name': user.realname,
125
        "roles": list(user.groups.values("id", "name")),
126
        "roles_links": []}
127
    d["access"]["serviceCatalog"] = []
128
    append = d["access"]["serviceCatalog"].append
129
    for s in Service.objects.all().order_by("id"):
130
        endpoints = []
131
        for l in [e.data.values('key', 'value') for e in s.endpoints.all()]:
132
            endpoint = dict((d['key'], d['value']) for d in l)
133
            endpoints.append(endpoint)
134
        append({"name": s.name,
135
                "type": s.type,
136
                "SNF:uiURL": s.component.url,
137
                "endpoints": endpoints,
138
                "endpoints_links": []})
133 139

  
134 140
    if request.serialization == 'xml':
135
        return xml_response({'access': access}, 'api/access.xml')
141
        return xml_response({'d': d}, 'api/access.xml')
136 142
    else:
137
        return json_response(access)
143
        return json_response(d)

Also available in: Unified diff