summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xkeystoneclient/v2_0/shell.py30
-rw-r--r--tests/test_shell.py23
2 files changed, 47 insertions, 6 deletions
diff --git a/keystoneclient/v2_0/shell.py b/keystoneclient/v2_0/shell.py
index 1d2d6dc..6825b16 100755
--- a/keystoneclient/v2_0/shell.py
+++ b/keystoneclient/v2_0/shell.py
@@ -234,20 +234,38 @@ def do_ec2_credentials_create(kc, args):
utils.print_dict(credentials._info)
-@utils.arg('--user', metavar='<user-id>', help='User ID to list')
+@utils.arg('--user', metavar='<user-id>', required=True, help='User ID')
+@utils.arg('--access', metavar='<access-key>', required=True,
+ help='Access Key')
+def do_ec2_credentials_get(kc, args):
+ """Display EC2-compatibile credentials"""
+ cred = kc.ec2.get(args.user, args.access)
+ if cred:
+ utils.print_dict(cred._info)
+
+
+@utils.arg('--user', metavar='<user-id>', required=True, help='User ID')
def do_ec2_credentials_list(kc, args):
"""List EC2-compatibile credentials for a user"""
credentials = kc.ec2.list(args.user)
for cred in credentials:
- cred.tenant = kc.tenants.get(cred.tenant_id).name
- utils.print_list(credentials, ['tenant', 'key', 'secret'])
+ try:
+ cred.tenant = getattr(kc.tenants.get(cred.tenant_id), 'name')
+ except:
+ pass
+ utils.print_list(credentials, ['tenant', 'access', 'secret'])
-@utils.arg('--user', metavar='<user-id>', help='User ID')
-@utils.arg('--key', metavar='<access-key>', help='Access Key')
+@utils.arg('--user', metavar='<user-id>', required=True, help='User ID')
+@utils.arg('--access', metavar='<access-key>', required=True,
+ help='Access Key')
def do_ec2_credentials_delete(kc, args):
"""Delete EC2-compatibile credentials"""
- kc.ec2.delete(args.user, args.key)
+ try:
+ kc.ec2.delete(args.user, args.access)
+ print 'Credential has been deleted.'
+ except Exception, e:
+ print 'Unable to delete credential: %s' % e
@utils.arg('--service', metavar='<service-type>', default=None,
diff --git a/tests/test_shell.py b/tests/test_shell.py
index 1126702..9b4c30d 100644
--- a/tests/test_shell.py
+++ b/tests/test_shell.py
@@ -152,3 +152,26 @@ class ShellTest(utils.TestCase):
(DEFAULT_AUTH_URL, DEFAULT_PASSWORD, 'os-tenant',
DEFAULT_TENANT_NAME, DEFAULT_USERNAME, '')
assert (b.tenant_id, b.user) == ('ec2-tenant', 'ec2-user')
+
+ def test_do_ec2_get(self):
+ do_shell_mock = mock.MagicMock()
+
+ with mock.patch('keystoneclient.v2_0.shell.do_ec2_credentials_create',
+ do_shell_mock):
+ shell('ec2-credentials-create')
+ assert do_shell_mock.called
+
+ with mock.patch('keystoneclient.v2_0.shell.do_ec2_credentials_get',
+ do_shell_mock):
+ shell('ec2-credentials-get')
+ assert do_shell_mock.called
+
+ with mock.patch('keystoneclient.v2_0.shell.do_ec2_credentials_list',
+ do_shell_mock):
+ shell('ec2-credentials-list')
+ assert do_shell_mock.called
+
+ with mock.patch('keystoneclient.v2_0.shell.do_ec2_credentials_delete',
+ do_shell_mock):
+ shell('ec2-credentials-delete')
+ assert do_shell_mock.called