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
dc897a7e
Commit
dc897a7e
authored
Jun 28, 2013
by
Stavros Sachtouris
Browse files
Allow multiple tokens per cloud configuration
Refs: #3632
parent
b5f436e8
Changes
2
Hide whitespace changes
Inline
Side-by-side
kamaki/cli/__init__.py
View file @
dc897a7e
...
...
@@ -41,6 +41,8 @@ from kamaki.cli.history import History
from
kamaki.cli.utils
import
print_dict
,
red
,
magenta
,
yellow
from
kamaki.cli.errors
import
CLIError
,
CLICmdSpecError
from
kamaki.cli
import
logger
from
kamaki.clients.astakos
import
AstakosClient
as
AuthCachedClient
from
kamaki.clients
import
ClientError
_help
=
False
_debug
=
False
...
...
@@ -285,7 +287,7 @@ def _init_session(arguments, is_non_API=False):
for
term
in
(
'url'
,
'token'
):
try
:
auth_args
[
term
]
=
_cnf
.
get_cloud
(
cloud
,
term
)
except
KeyError
:
except
KeyError
or
IndexError
:
auth_args
[
term
]
=
''
if
not
auth_args
[
term
]:
raise
CLIError
(
...
...
@@ -296,9 +298,23 @@ def _init_session(arguments, is_non_API=False):
' kamaki config set cloud.%s.%s <%s>'
%
(
cloud
,
term
,
term
.
upper
())])
from
kamaki.clients.astakos
import
AstakosClient
as
AuthCachedClient
try
:
return
AuthCachedClient
(
auth_args
[
'url'
],
auth_args
[
'token'
]),
cloud
auth_base
=
None
for
token
in
reversed
(
auth_args
[
'token'
].
split
()):
try
:
if
auth_base
:
auth_base
.
authenticate
(
token
)
else
:
auth_base
=
AuthCachedClient
(
auth_args
[
'url'
],
auth_args
[
'token'
])
auth_base
.
authenticate
(
token
)
except
ClientError
as
ce
:
if
ce
.
status
in
(
401
,
):
kloger
.
warning
(
'WARNING: Failed to authorize token %s'
%
token
)
else
:
raise
return
auth_base
,
cloud
except
AssertionError
as
ae
:
kloger
.
warning
(
'WARNING: Failed to load authenticator [%s]'
%
ae
)
return
None
,
cloud
...
...
kamaki/cli/commands/astakos.py
View file @
dc897a7e
...
...
@@ -45,6 +45,14 @@ _commands = [user_cmds]
class
_user_init
(
_command_init
):
def
_write_main_token
(
self
,
token
):
tokens
=
self
.
config
.
get_cloud
(
self
.
cloud
,
'token'
).
split
()
if
token
in
tokens
:
tokens
.
remove
(
token
)
tokens
.
insert
(
0
,
token
)
self
.
config
.
set_cloud
(
self
.
cloud
,
'token'
,
' '
.
join
(
tokens
))
self
.
config
.
write
()
@
errors
.
generic
.
all
@
errors
.
user
.
load
@
addLogSettings
...
...
@@ -54,6 +62,7 @@ class _user_init(_command_init):
if
base_url
:
token
=
self
.
_custom_token
(
'astakos'
)
\
or
self
.
config
.
get_cloud
(
self
.
cloud
,
'token'
)
token
=
token
.
split
()[
0
]
if
' '
in
token
else
token
self
.
client
=
AstakosClient
(
base_url
=
base_url
,
token
=
token
)
return
else
:
...
...
@@ -91,9 +100,7 @@ class user_authenticate(_user_init, _optional_json):
if
(
token_bu
!=
self
.
client
.
token
and
ask_user
(
'Permanently save token as cloud.%s.token ?'
%
(
self
.
cloud
))):
self
.
config
.
set_cloud
(
self
.
cloud
,
'token'
,
self
.
client
.
token
)
self
.
config
.
write
()
self
.
_write_main_token
(
self
.
client
.
token
)
except
Exception
:
#recover old token
self
.
client
.
token
=
token_bu
...
...
@@ -156,6 +163,9 @@ class user_set(_user_init, _optional_json):
print
(
'Session user set to %s (%s)'
%
(
self
.
client
.
user_term
(
'name'
),
self
.
client
.
user_term
(
'id'
)))
if
ask_user
(
'Permanently make %s the main user?'
%
(
self
.
client
.
user_term
(
'name'
))):
self
.
_write_main_token
(
self
.
client
.
token
)
return
raise
CLIError
(
'User with UUID %s not authenticated in current session'
%
uuid
,
...
...
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