Commit b44a5a37 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Cache by uuid instead of token in astakos client

Refs: #3660
parent fe4940bc
......@@ -41,6 +41,7 @@ class AstakosClient(Client):
def __init__(self, base_url, token=None):
super(AstakosClient, self).__init__(base_url, token)
self._cache = {}
self._uuids = {}
self.log = getLogger('__name__')
def authenticate(self, token=None):
......@@ -54,8 +55,14 @@ class AstakosClient(Client):
"""
self.token = token or self.token
body = dict(auth=dict(token=dict(id=self.token)))
self._cache[self.token] = self.post('/tokens', json=body).json
return self._cache[self.token]
r = self.post('/tokens', json=body).json
uuid = r['access']['user']['id']
self._uuids[self.token] = uuid
self._cache[uuid] = r
return self._cache[uuid]
def get_token(self, uuid):
return self._cache[uuid]['access']['token']['id']
def get_services(self, token=None):
"""
......@@ -64,7 +71,7 @@ class AstakosClient(Client):
token_bu = self.token or token
token = token or self.token
try:
r = self._cache[token]
r = self._cache[self._uuids[token]]
except KeyError:
r = self.authenticate(token)
finally:
......@@ -122,7 +129,7 @@ class AstakosClient(Client):
r = []
for k, v in self._cache.items():
r.append(dict(v['access']['user']))
r[-1].update(dict(auth_token=k))
r[-1].update(dict(auth_token=self.get_token(k)))
return r
def user_info(self, token=None):
......@@ -130,7 +137,7 @@ class AstakosClient(Client):
token_bu = self.token or token
token = token or self.token
try:
r = self._cache[token]
r = self._cache[self._uuids[token]]
except KeyError:
r = self.authenticate(token)
finally:
......
......@@ -60,6 +60,13 @@ example = dict(
example0 = dict(
access=dict(
token=dict(
expires="2013-07-14T10:07:42.481134+00:00",
id="ast@k0sT0k3n==",
tenant=dict(
id="42",
name="Simple Name 0")
),
serviceCatalog=[
dict(name='service name 1', type='compute', endpoints=[
dict(versionId='v1', publicUrl='http://1.1.1.1/v1'),
......@@ -168,7 +175,7 @@ class AstakosClient(TestCase):
def test_list_users(self):
if not self.cached:
self._authenticate
self._authenticate()
FR.json = example0
self._authenticate()
r = self.client.list_users()
......
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