36 |
36 |
from django.views.decorators.csrf import csrf_exempt
|
37 |
37 |
|
38 |
38 |
from snf_django.lib.api import faults, utils, api_method
|
|
39 |
from django.core.cache import cache
|
39 |
40 |
|
|
41 |
from astakos.im import settings
|
40 |
42 |
from astakos.im.models import Service, AstakosUser
|
41 |
43 |
from .util import json_response, xml_response, validate_user,\
|
42 |
44 |
get_content_length
|
... | ... | |
45 |
47 |
logger = logging.getLogger(__name__)
|
46 |
48 |
|
47 |
49 |
|
|
50 |
def compute_endpoints():
|
|
51 |
l = []
|
|
52 |
for s in Service.objects.all().order_by("id").\
|
|
53 |
prefetch_related('endpoints__data').\
|
|
54 |
select_related('component'):
|
|
55 |
endpoints = []
|
|
56 |
for e in s.endpoints.all():
|
|
57 |
endpoint = dict((ed.key, ed.value) for ed in e.data.all())
|
|
58 |
endpoint["SNF:uiURL"] = s.component.url
|
|
59 |
endpoint["region"] = "default"
|
|
60 |
if s.name == 'astakos_weblogin':
|
|
61 |
endpoint["SNF:webloginURL"] = endpoint["publicURL"]
|
|
62 |
endpoints.append(endpoint)
|
|
63 |
l.append({"name": s.name,
|
|
64 |
"type": s.type,
|
|
65 |
"endpoints": endpoints,
|
|
66 |
"endpoints_links": []})
|
|
67 |
return l
|
|
68 |
|
|
69 |
|
|
70 |
def get_endpoints():
|
|
71 |
key = "endpoints"
|
|
72 |
result = cache.get(key)
|
|
73 |
if result is None:
|
|
74 |
cache.set(key, compute_endpoints(), settings.ENDPOINT_CACHE_TIMEOUT)
|
|
75 |
result = cache.get(key)
|
|
76 |
return result
|
|
77 |
|
|
78 |
|
48 |
79 |
@csrf_exempt
|
49 |
80 |
@api_method(http_method="POST", token_required=False, user_required=False,
|
50 |
81 |
logger=logger)
|
... | ... | |
100 |
131 |
"roles": list(user.groups.values("id", "name")),
|
101 |
132 |
"roles_links": []}
|
102 |
133 |
|
103 |
|
d["access"]["serviceCatalog"] = []
|
104 |
|
append = d["access"]["serviceCatalog"].append
|
105 |
|
for s in Service.objects.all().order_by("id").\
|
106 |
|
prefetch_related('endpoints__data').select_related('component'):
|
107 |
|
endpoints = []
|
108 |
|
for e in s.endpoints.all():
|
109 |
|
endpoint = dict((ed.key, ed.value) for ed in e.data.all())
|
110 |
|
endpoint["SNF:uiURL"] = s.component.url
|
111 |
|
endpoint["region"] = "default"
|
112 |
|
if s.name == 'astakos_weblogin':
|
113 |
|
endpoint["SNF:webloginURL"] = endpoint["publicURL"]
|
114 |
|
endpoints.append(endpoint)
|
115 |
|
append({"name": s.name,
|
116 |
|
"type": s.type,
|
117 |
|
"endpoints": endpoints,
|
118 |
|
"endpoints_links": []})
|
|
134 |
d["access"]["serviceCatalog"] = get_endpoints()
|
119 |
135 |
|
120 |
136 |
if request.serialization == 'xml':
|
121 |
137 |
return xml_response({'d': d}, 'api/access.xml')
|