Commit fb7b3c0a authored by Sofia Papagiannaki's avatar Sofia Papagiannaki

astakosclient: Provide call for requesting oa2 token

parent 6040de52
...@@ -39,6 +39,7 @@ import logging ...@@ -39,6 +39,7 @@ import logging
import urlparse import urlparse
import urllib import urllib
import hashlib import hashlib
from base64 import b64encode
from copy import copy from copy import copy
import simplejson import simplejson
...@@ -144,9 +145,16 @@ class AstakosClient(object): ...@@ -144,9 +145,16 @@ class AstakosClient(object):
self._ui_prefix = parsed_ui_url.path self._ui_prefix = parsed_ui_url.path
self.logger.debug("Got ui_prefix \"%s\"" % self._ui_prefix) self.logger.debug("Got ui_prefix \"%s\"" % self._ui_prefix)
oa2_service_catalog = parse_endpoints(endpoints, ep_name="astakos_oa2")
self._oa2_url = \
oa2_service_catalog[0]['endpoints'][0]['publicURL']
parsed_oa2_url = urlparse.urlparse(self._oa2_url)
self._oa2_prefix = parsed_oa2_url.path
def _get_value(self, s): def _get_value(self, s):
assert s in ['_account_url', '_account_prefix', assert s in ['_account_url', '_account_prefix',
'_ui_url', '_ui_prefix'] '_ui_url', '_ui_prefix',
'_oa2_url', '_oa2_prefix']
try: try:
return getattr(self, s) return getattr(self, s)
except AttributeError: except AttributeError:
...@@ -169,6 +177,14 @@ class AstakosClient(object): ...@@ -169,6 +177,14 @@ class AstakosClient(object):
def ui_prefix(self): def ui_prefix(self):
return self._get_value('_ui_prefix') return self._get_value('_ui_prefix')
@property
def oa2_url(self):
return self._get_value('_oa2_url')
@property
def oa2_prefix(self):
return self._get_value('_oa2_prefix')
@property @property
def api_usercatalogs(self): def api_usercatalogs(self):
return join_urls(self.account_prefix, "user_catalogs") return join_urls(self.account_prefix, "user_catalogs")
...@@ -217,6 +233,14 @@ class AstakosClient(object): ...@@ -217,6 +233,14 @@ class AstakosClient(object):
def api_getservices(self): def api_getservices(self):
return join_urls(self.ui_prefix, "get_services") return join_urls(self.ui_prefix, "get_services")
@property
def api_oa2_auth(self):
return join_urls(self.oa2_prefix, "auth")
@property
def api_oa2_token(self):
return join_urls(self.oa2_prefix, "token")
# ---------------------------------- # ----------------------------------
@retry_dec @retry_dec
def _call_astakos(self, request_path, headers=None, def _call_astakos(self, request_path, headers=None,
...@@ -877,6 +901,18 @@ class AstakosClient(object): ...@@ -877,6 +901,18 @@ class AstakosClient(object):
return self._call_astakos(self.api_memberships, headers=req_headers, return self._call_astakos(self.api_memberships, headers=req_headers,
body=req_body, method="POST") body=req_body, method="POST")
# --------------------------------
# do a POST to ``API_OA2_TOKEN``
def get_token(self, grant_type, client_id, client_secret, **body_params):
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic %s' % b64encode('%s:%s' %
(client_id,
client_secret))}
body_params['grant_type'] = grant_type
body = urllib.urlencode(body_params)
return self._call_astakos(self.api_oa2_token, headers=headers,
body=body, method="POST")
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# parse endpoints # parse endpoints
......
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