Exemplo n.º 1
0
    def update_attributes(self, username, hostname, user_attrs):
        """Change the attributes of an existing user."""
        LOG.debug("Changing user attributes for user %s.", username)
        user = self._get_user(username, hostname)

        new_name = user_attrs.get('name')
        new_host = user_attrs.get('host')
        new_password = user_attrs.get('password')

        if new_name or new_host or new_password:

            with self.local_sql_client(self.mysql_app.get_engine()) as client:

                if new_password is not None:
                    uu = sql_query.SetPassword(user.name,
                                               host=user.host,
                                               new_password=new_password)

                    t = text(str(uu))
                    client.execute(t)

                if new_name or new_host:
                    uu = sql_query.RenameUser(user.name,
                                              host=user.host,
                                              new_user=new_name,
                                              new_host=new_host)
                    t = text(str(uu))
                    client.execute(t)
Exemplo n.º 2
0
    def update_attributes(self, username, hostname, user_attrs):
        """Change the attributes of an existing user."""
        LOG.debug("Changing user attributes for user %s.", username)
        user = self._get_user(username, hostname)

        new_name = user_attrs.get('name')
        new_host = user_attrs.get('host')
        new_password = user_attrs.get('password')

        if new_name or new_host or new_password:
            with mysql_util.SqlClient(self.mysql_app.get_engine(),
                                      use_flush=True) as client:
                if new_password is not None:
                    uu = sql_query.SetPassword(
                        user.name,
                        host=user.host,
                        new_password=new_password,
                        ds=CONF.datastore_manager,
                        ds_version=CONF.datastore_version)
                    t = text(str(uu))
                    client.execute(t)

                if new_name or new_host:
                    uu = sql_query.RenameUser(user.name,
                                              host=user.host,
                                              new_user=new_name,
                                              new_host=new_host)
                    t = text(str(uu))
                    client.execute(t)
Exemplo n.º 3
0
 def test_change_host(self):
     username = '******'
     hostname = 'localhost'
     new_host = '%'
     uu = sql_query.RenameUser(user=username,
                               host=hostname,
                               new_host=new_host)
     self.assertEqual("RENAME USER 'root'@'localhost' "
                      "TO 'root'@'%';", str(uu))
Exemplo n.º 4
0
 def test_rename_user(self):
     username = '******'
     hostname = 'localhost'
     new_user = '******'
     uu = sql_query.RenameUser(user=username,
                               host=hostname,
                               new_user=new_user)
     self.assertEqual(
         "RENAME USER 'root'@'localhost' "
         "TO 'root123'@'localhost';", str(uu))