Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
kamaki
Commits
b44a5a37
Commit
b44a5a37
authored
Jun 27, 2013
by
Stavros Sachtouris
Browse files
Cache by uuid instead of token in astakos client
Refs: #3660
parent
fe4940bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
kamaki/clients/astakos/__init__.py
View file @
b44a5a37
...
...
@@ -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
:
...
...
kamaki/clients/astakos/test.py
View file @
b44a5a37
...
...
@@ -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
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment