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
c3e01785
Commit
c3e01785
authored
Jun 27, 2013
by
Stavros Sachtouris
Browse files
Merge branch 'feature-user-commands' into develop
parents
9d0a8ecf
fe4940bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
kamaki/cli/commands/astakos.py
View file @
c3e01785
...
...
@@ -36,8 +36,8 @@ from kamaki.clients.astakos import AstakosClient
from
kamaki.cli.commands
import
(
_command_init
,
errors
,
_optional_json
,
addLogSettings
)
from
kamaki.cli.command_tree
import
CommandTree
from
kamaki.cli.errors
import
CLIBaseUrlError
from
kamaki.cli.utils
import
print_dict
from
kamaki.cli.errors
import
CLIBaseUrlError
,
CLIError
from
kamaki.cli.utils
import
print_dict
,
ask_user
user_cmds
=
CommandTree
(
'user'
,
'Astakos API commands'
)
_commands
=
[
user_cmds
]
...
...
@@ -85,10 +85,15 @@ class user_authenticate(_user_init, _optional_json):
@
errors
.
generic
.
all
@
errors
.
user
.
authenticate
def
_run
(
self
,
custom_token
=
None
):
super
(
self
.
__class__
,
self
).
_run
()
token_bu
=
self
.
client
.
token
try
:
r
=
self
.
client
.
authenticate
(
custom_token
)
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
()
except
Exception
:
#recover old token
self
.
client
.
token
=
token_bu
...
...
@@ -96,4 +101,67 @@ class user_authenticate(_user_init, _optional_json):
self
.
_print
(
r
,
self
.
_print_access
)
def
main
(
self
,
custom_token
=
None
):
super
(
self
.
__class__
,
self
).
_run
()
self
.
_run
(
custom_token
)
@
command
(
user_cmds
)
class
user_list
(
_user_init
,
_optional_json
):
"""Get service endpoints"""
@
errors
.
generic
.
all
def
_run
(
self
,
custom_token
=
None
):
self
.
_print
(
self
.
client
.
list_users
())
def
main
(
self
):
super
(
self
.
__class__
,
self
).
_run
()
self
.
_run
()
@
command
(
user_cmds
)
class
user_get
(
_user_init
,
_optional_json
):
"""Get session user"""
@
errors
.
generic
.
all
def
_run
(
self
):
self
.
_print
(
self
.
client
.
user_info
(),
print_dict
)
def
main
(
self
):
super
(
self
.
__class__
,
self
).
_run
()
self
.
_run
()
@
command
(
user_cmds
)
class
user_set
(
_user_init
,
_optional_json
):
"""Set session user by id
To enrich your options, authenticate more users:
/user authenticate <other user token>
To list authenticated users
/user list
To get the current session user
/user get
"""
@
errors
.
generic
.
all
def
_run
(
self
,
uuid
):
for
user
in
self
.
client
.
list_users
():
if
user
.
get
(
'id'
,
None
)
in
(
uuid
,):
ntoken
=
user
[
'auth_token'
]
if
ntoken
==
self
.
client
.
token
:
print
(
'%s (%s) is already the session user'
%
(
self
.
client
.
user_term
(
'name'
),
self
.
client
.
user_term
(
'id'
)))
return
self
.
client
.
token
=
user
[
'auth_token'
]
print
(
'Session user set to %s (%s)'
%
(
self
.
client
.
user_term
(
'name'
),
self
.
client
.
user_term
(
'id'
)))
return
raise
CLIError
(
'User with UUID %s not authenticated in current session'
%
uuid
,
details
=
[
'To authenticate a user'
,
' /user authenticate <t0k3n>'
])
def
main
(
self
,
uuid
):
super
(
self
.
__class__
,
self
).
_run
()
self
.
_run
(
uuid
)
kamaki/clients/astakos/__init__.py
View file @
c3e01785
...
...
@@ -117,6 +117,8 @@ class AstakosClient(Client):
def
list_users
(
self
):
"""list cached users information"""
if
not
self
.
_cache
:
self
.
authenticate
()
r
=
[]
for
k
,
v
in
self
.
_cache
.
items
():
r
.
append
(
dict
(
v
[
'access'
][
'user'
]))
...
...
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