Revision 409371de kamaki/clients/astakos.py
b/kamaki/clients/astakos.py | ||
---|---|---|
43 | 43 |
super(AstakosClient, self).__init__(base_url, token) |
44 | 44 |
|
45 | 45 |
def authenticate(self, token=None): |
46 |
""" |
|
46 |
"""Get authentication information and store it in this client |
|
47 |
As long as the AstakosClient instance is alive, the latest |
|
48 |
authentication information for this token will be available |
|
49 |
|
|
47 | 50 |
:param token: (str) custom token to authenticate |
48 | 51 |
|
49 | 52 |
:returns: (dict) authentication information |
50 | 53 |
""" |
51 | 54 |
self.token = token or self.token |
52 |
self._cache[token] = self.get('/im/authenticate').json |
|
53 |
return self._cache[token] |
|
55 |
self._cache[self.token] = self.get('/im/authenticate').json
|
|
56 |
return self._cache[self.token]
|
|
54 | 57 |
|
55 | 58 |
def list(self): |
56 | 59 |
"""list cached user information""" |
57 | 60 |
return self._cache.values() |
58 | 61 |
|
59 | 62 |
def _user_info(self, token=None): |
63 |
token_bu = self.token |
|
60 | 64 |
token = token or self.token |
61 | 65 |
try: |
62 |
return self._cache[token]
|
|
66 |
r = self._cache[token]
|
|
63 | 67 |
except KeyError: |
64 |
return self.authenticate(token) |
|
68 |
r = self.authenticate(token) |
|
69 |
self.token = token_bu |
|
70 |
return r |
|
65 | 71 |
|
66 | 72 |
def term(self, key, token=None): |
67 | 73 |
"""Get (cached) term, from user credentials""" |
Also available in: Unified diff