Interactive prompt for create user
Execution of the shell will now prompt the user for a password if argument '--pass' is specified without a following parameter. In that way, a user does not need to pass passwords on the command line. Usage example: $ keystone user-create --name bob --tenant admin --pass --enabled true New Password: Repeat New Password: Closes-Bug: #1100116 Change-Id: I1f6d6322830972dfad19ebe2fe63e91f82ed8033
This commit is contained in:
		| @@ -13,6 +13,7 @@ | ||||
| import os | ||||
| import sys | ||||
|  | ||||
| import mock | ||||
| from mox3 import stubout | ||||
| import six | ||||
| from testtools import matchers | ||||
| @@ -102,6 +103,20 @@ class ShellTests(utils.TestCase): | ||||
|                  'name': 'new-user', | ||||
|                  'tenantId': None}}) | ||||
|  | ||||
|     @mock.patch('sys.stdin', autospec=True) | ||||
|     def test_user_create_password_prompt(self, mock_stdin): | ||||
|         with mock.patch('getpass.getpass') as mock_getpass: | ||||
|             mock_getpass.return_value = 'newpass' | ||||
|             self.run_command('user-create --name new-user --pass') | ||||
|             self.fake_client.assert_called_anytime( | ||||
|                 'POST', '/users', | ||||
|                 {'user': | ||||
|                     {'email': None, | ||||
|                      'password': 'newpass', | ||||
|                      'enabled': True, | ||||
|                      'name': 'new-user', | ||||
|                      'tenantId': None}}) | ||||
|  | ||||
|     def test_user_get(self): | ||||
|         self.run_command('user-get 1') | ||||
|         self.fake_client.assert_called_anytime('GET', '/users/1') | ||||
|   | ||||
							
								
								
									
										10
									
								
								keystoneclient/v2_0/shell.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										10
									
								
								keystoneclient/v2_0/shell.py
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @@ -27,6 +27,7 @@ from keystoneclient.v2_0 import client | ||||
|  | ||||
|  | ||||
| CLIENT_CLASS = client.Client | ||||
| ASK_FOR_PASSWORD = object() | ||||
|  | ||||
|  | ||||
| def require_service_catalog(f): | ||||
| @@ -71,8 +72,8 @@ def do_user_get(kc, args): | ||||
| @utils.arg('--tenant', '--tenant-id', metavar='<tenant>', | ||||
|            help='New user default tenant') | ||||
| @utils.arg('--tenant_id', help=argparse.SUPPRESS) | ||||
| @utils.arg('--pass', metavar='<pass>', dest='passwd', | ||||
|            help='New user password') | ||||
| @utils.arg('--pass', metavar='<pass>', dest='passwd', nargs='?', | ||||
|            const=ASK_FOR_PASSWORD, help='New user password') | ||||
| @utils.arg('--email', metavar='<email>', | ||||
|            help='New user email address') | ||||
| @utils.arg('--enabled', metavar='<true|false>', default=True, | ||||
| @@ -85,7 +86,10 @@ def do_user_create(kc, args): | ||||
|         tenant_id = args.tenant_id | ||||
|     else: | ||||
|         tenant_id = None | ||||
|     user = kc.users.create(args.name, args.passwd, args.email, | ||||
|     new_passwd = args.passwd | ||||
|     if args.passwd is ASK_FOR_PASSWORD: | ||||
|         new_passwd = utils.prompt_for_password() | ||||
|     user = kc.users.create(args.name, new_passwd, args.email, | ||||
|                            tenant_id=tenant_id, | ||||
|                            enabled=strutils.bool_from_string(args.enabled)) | ||||
|     utils.print_dict(user._info) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Eric Brown
					Eric Brown