diff --git a/releasenotes/notes/add-user-update-attributes-to-osc-5adfffe826a62f3b.yaml b/releasenotes/notes/add-user-update-attributes-to-osc-5adfffe826a62f3b.yaml new file mode 100644 index 00000000..69fb5dd5 --- /dev/null +++ b/releasenotes/notes/add-user-update-attributes-to-osc-5adfffe826a62f3b.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The command ``trove user-update-attributes`` is now available to use in + the python-openstackclient CLI as + ``openstack database user update attributes`` diff --git a/setup.cfg b/setup.cfg index d4343936..6512cc2b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -66,6 +66,7 @@ openstack.database.v1 = database_user_revoke_access = troveclient.osc.v1.database_users:RevokeDatabaseUserAccess database_user_show = troveclient.osc.v1.database_users:ShowDatabaseUser database_user_show_access = troveclient.osc.v1.database_users:ShowDatabaseUserAccess + database_user_update_attributes = troveclient.osc.v1.database_users:UpdateDatabaseUserAttributes datastore_list = troveclient.osc.v1.datastores:ListDatastores datastore_show = troveclient.osc.v1.datastores:ShowDatastore datastore_version_list = troveclient.osc.v1.datastores:ListDatastoreVersions diff --git a/troveclient/osc/v1/database_users.py b/troveclient/osc/v1/database_users.py index e3df4e8f..edfc275d 100644 --- a/troveclient/osc/v1/database_users.py +++ b/troveclient/osc/v1/database_users.py @@ -280,3 +280,64 @@ class ShowDatabaseUserAccess(command.Lister): hostname=parsed_args.host) access = [utils.get_item_properties(n, self.columns) for n in names] return self.columns, access + + +class UpdateDatabaseUserAttributes(command.Command): + + _description = _("Updates a user's attributes on an instance." + "At least one optional argument must be provided.") + + def get_parser(self, prog_name): + parser = super(UpdateDatabaseUserAttributes, + self).get_parser(prog_name) + parser.add_argument( + 'instance', + metavar='', + help=_('ID or name of the instance.') + ) + parser.add_argument( + 'name', + metavar='', + help=_('Name of user.') + ) + parser.add_argument( + '--host', + metavar='', + default=None, + help=_('Optional host of user.') + ) + parser.add_argument( + '--new_name', + metavar='', + default=None, + help=_('Optional new name of user.') + ) + parser.add_argument( + '--new_password', + metavar='', + default=None, + help=_('Optional new password of user.') + ) + parser.add_argument( + '--new_host', + metavar='', + default=None, + help=_('Optional new host of user.') + ) + return parser + + def take_action(self, parsed_args): + manager = self.app.client_manager.database + users = manager.users + instance = utils.find_resource(manager.instances, + parsed_args.instance) + new_attrs = {} + if parsed_args.new_name: + new_attrs['name'] = parsed_args.new_name + if parsed_args.new_password: + new_attrs['password'] = parsed_args.new_password + if parsed_args.new_host: + new_attrs['host'] = parsed_args.new_host + users.update_attributes(instance, parsed_args.name, + newuserattr=new_attrs, + hostname=parsed_args.host) diff --git a/troveclient/tests/osc/v1/test_database_users.py b/troveclient/tests/osc/v1/test_database_users.py index 75fee14a..a33c9344 100644 --- a/troveclient/tests/osc/v1/test_database_users.py +++ b/troveclient/tests/osc/v1/test_database_users.py @@ -207,3 +207,31 @@ class TestDatabaseUserShowAccess(TestUsers): columns, data = self.cmd.take_action(parsed_args) self.assertEqual(self.columns, columns) self.assertEqual(self.values, data) + + +class TestDatabaseUserUpdateAttributes(TestUsers): + + def setUp(self): + super(TestDatabaseUserUpdateAttributes, self).setUp() + self.cmd = database_users.UpdateDatabaseUserAttributes(self.app, None) + + @mock.patch.object(utils, 'find_resource') + def test_user__update_attributes(self, mock_find): + args = ['userinstance', + 'user1', + '--host', '1.1.1.1', + '--new_name', 'user2', + '--new_password', '111111', + '--new_host', '1.1.1.2'] + verifylist = [ + ('instance', 'userinstance'), + ('name', 'user1'), + ('host', '1.1.1.1'), + ('new_name', 'user2'), + ('new_password', '111111'), + ('new_host', '1.1.1.2'), + ] + mock_find.return_value = args[0] + parsed_args = self.check_parser(self.cmd, args, verifylist) + result = self.cmd.take_action(parsed_args) + self.assertIsNone(result)