Revision 6476ceb7
b/astakosclient/astakosclient/__init__.py | ||
---|---|---|
128 | 128 |
self.auth_prefix = parsed_auth_url.path |
129 | 129 |
self.api_tokens = join_urls(self.auth_prefix, "tokens") |
130 | 130 |
|
131 |
def _fill_endpoints(self, endpoints): |
|
131 |
def _fill_endpoints(self, endpoints, extra=False): |
|
132 |
"""Fill the endpoints for our AstakosClient |
|
133 |
|
|
134 |
This will be done once (lazily) and the endpoints will be there |
|
135 |
to be used afterwards. |
|
136 |
The `extra' parameter is there for compatibility reasons. We are going |
|
137 |
to fill the oauth2 endpoint only if we need it. This way we are keeping |
|
138 |
astakosclient compatible with older Astakos version. |
|
139 |
|
|
140 |
""" |
|
132 | 141 |
astakos_service_catalog = parse_endpoints( |
133 | 142 |
endpoints, ep_name="astakos_account", ep_version_id="v1.0") |
134 | 143 |
self._account_url = \ |
... | ... | |
145 | 154 |
self._ui_prefix = parsed_ui_url.path |
146 | 155 |
self.logger.debug("Got ui_prefix \"%s\"" % self._ui_prefix) |
147 | 156 |
|
148 |
oauth2_service_catalog = parse_endpoints(endpoints, |
|
149 |
ep_name="astakos_oauth2") |
|
150 |
self._oauth2_url = \ |
|
151 |
oauth2_service_catalog[0]['endpoints'][0]['publicURL'] |
|
152 |
parsed_oauth2_url = urlparse.urlparse(self._oauth2_url) |
|
153 |
self._oauth2_prefix = parsed_oauth2_url.path |
|
157 |
if extra: |
|
158 |
oauth2_service_catalog = \ |
|
159 |
parse_endpoints(endpoints, ep_name="astakos_oauth2") |
|
160 |
self._oauth2_url = \ |
|
161 |
oauth2_service_catalog[0]['endpoints'][0]['publicURL'] |
|
162 |
parsed_oauth2_url = urlparse.urlparse(self._oauth2_url) |
|
163 |
self._oauth2_prefix = parsed_oauth2_url.path |
|
154 | 164 |
|
155 |
def _get_value(self, s): |
|
165 |
def _get_value(self, s, extra=False):
|
|
156 | 166 |
assert s in ['_account_url', '_account_prefix', |
157 | 167 |
'_ui_url', '_ui_prefix', |
158 | 168 |
'_oauth2_url', '_oauth2_prefix'] |
159 | 169 |
try: |
160 | 170 |
return getattr(self, s) |
161 | 171 |
except AttributeError: |
162 |
self.get_endpoints() |
|
172 |
self.get_endpoints(extra=extra)
|
|
163 | 173 |
return getattr(self, s) |
164 | 174 |
|
165 | 175 |
@property |
... | ... | |
180 | 190 |
|
181 | 191 |
@property |
182 | 192 |
def oauth2_url(self): |
183 |
return self._get_value('_oauth2_url') |
|
193 |
return self._get_value('_oauth2_url', extra=True)
|
|
184 | 194 |
|
185 | 195 |
@property |
186 | 196 |
def oauth2_prefix(self): |
187 |
return self._get_value('_oauth2_prefix') |
|
197 |
return self._get_value('_oauth2_prefix', extra=True)
|
|
188 | 198 |
|
189 | 199 |
@property |
190 | 200 |
def api_usercatalogs(self): |
... | ... | |
456 | 466 |
|
457 | 467 |
# ----------------------------------------- |
458 | 468 |
# do a POST to ``API_TOKENS`` with no token |
459 |
def get_endpoints(self): |
|
469 |
def get_endpoints(self, extra=False):
|
|
460 | 470 |
""" Get services' endpoints |
461 | 471 |
|
472 |
The extra parameter is to be used by _fill_endpoints. |
|
462 | 473 |
In case of error raise an AstakosClientException. |
463 | 474 |
|
464 | 475 |
""" |
... | ... | |
467 | 478 |
r = self._call_astakos(self.api_tokens, headers=req_headers, |
468 | 479 |
body=req_body, method="POST", |
469 | 480 |
log_body=False) |
470 |
self._fill_endpoints(r) |
|
481 |
self._fill_endpoints(r, extra=extra)
|
|
471 | 482 |
return r |
472 | 483 |
|
473 | 484 |
# -------------------------------------- |
Also available in: Unified diff