コード例 #1
0
    def enable_root(self, root_password=None):
        """Enable the root user global access and/or
           reset the root password.
        """
        user = models.MySQLUser.root(password=root_password)
        with self.local_sql_client(self.mysql_app.get_engine()) as client:
            try:
                cu = sql_query.CreateUser(user.name, host=user.host)
                t = text(str(cu))
                client.execute(t, **cu.keyArgs)
            except (exc.OperationalError, exc.InternalError) as err:
                # Ignore, user is already created, just reset the password
                # TODO(rnirmal): More fine grained error checking later on
                LOG.debug(err)
        with self.local_sql_client(self.mysql_app.get_engine()) as client:
            uu = sql_query.SetPassword(user.name, host=user.host,
                                       new_password=user.password)
            t = text(str(uu))
            client.execute(t)

            LOG.debug("CONF.root_grant: %s CONF.root_grant_option: %s." %
                      (CONF.root_grant, CONF.root_grant_option))

            g = sql_query.Grant(permissions=CONF.root_grant,
                                user=user.name,
                                host=user.host,
                                grant_option=CONF.root_grant_option,
                                clear=user.password)

            t = text(str(g))
            client.execute(t)
            return user.serialize()
コード例 #2
0
ファイル: service.py プロジェクト: crowdy/trove
    def _create_admin_user(self, client, password):
        """
        Create a os_admin user with a random password
        with all privileges similar to the root user.
        """
        LOG.info("Creating Trove admin user '%s'.", ADMIN_USER_NAME)
        host = "localhost"
        try:
            cu = sql_query.CreateUser(ADMIN_USER_NAME,
                                      host=host,
                                      clear=password)
            t = text(str(cu))
            client.execute(t, **cu.keyArgs)
        except (exc.OperationalError, exc.InternalError) as err:
            # Ignore, user is already created, just reset the password
            # (user will already exist in a restore from backup)
            LOG.debug(err)
            uu = sql_query.SetPassword(ADMIN_USER_NAME,
                                       host=host,
                                       new_password=password,
                                       ds=CONF.datastore_manager,
                                       ds_version=CONF.datastore_version)
            t = text(str(uu))
            client.execute(t)

        g = sql_query.Grant(permissions='ALL',
                            user=ADMIN_USER_NAME,
                            host=host,
                            grant_option=True)
        t = text(str(g))
        client.execute(t)
        LOG.info("Trove admin user '%s' created.", ADMIN_USER_NAME)
コード例 #3
0
ファイル: service.py プロジェクト: crowdy/trove
    def create_users(self, users):
        """Create users and grant them privileges for the
           specified databases.
        """
        with mysql_util.SqlClient(self.mysql_app.get_engine(),
                                  use_flush=True) as client:
            for item in users:
                user = models.MySQLUser.deserialize(item)
                user.check_create()

                cu = sql_query.CreateUser(user.name,
                                          host=user.host,
                                          clear=user.password)
                t = text(str(cu))
                client.execute(t, **cu.keyArgs)

                for database in user.databases:
                    mydb = models.MySQLSchema.deserialize(database)
                    g = sql_query.Grant(permissions='ALL',
                                        database=mydb.name,
                                        user=user.name,
                                        host=user.host)
                    t = text(str(g))
                    LOG.debug('Creating user, command: %s', str(g))
                    client.execute(t)
コード例 #4
0
    def enable_root(cls, root_password=None):
        """Enable the root user global access and/or reset the root password"""
        user = models.RootUser()
        user.name = "root"
        user.host = "%"
        user.password = root_password or generate_random_password()
        with LocalSqlClient(get_engine()) as client:
            print(client)
            try:
                cu = sql_query.CreateUser(user.name, host=user.host)
                t = text(str(cu))
                client.execute(t, **cu.keyArgs)
            except exc.OperationalError as err:
                # Ignore, user is already created, just reset the password
                # TODO(rnirmal): More fine grained error checking later on
                LOG.debug(err)
        with LocalSqlClient(get_engine()) as client:
            print(client)
            uu = sql_query.UpdateUser(user.name, host=user.host,
                                      clear=user.password)
            t = text(str(uu))
            client.execute(t)

            LOG.debug("CONF.root_grant: %s CONF.root_grant_option: %s" %
                      (CONF.root_grant, CONF.root_grant_option))

            g = sql_query.Grant(permissions=CONF.root_grant,
                                user=user.name,
                                host=user.host,
                                grant_option=CONF.root_grant_option,
                                clear=user.password)

            t = text(str(g))
            client.execute(t)
            return user.serialize()
コード例 #5
0
 def test_defaults(self):
     username = '******'
     hostname = 'localhost'
     password = '******'
     cu = sql_query.CreateUser(user=username, host=hostname, clear=password)
     self.assertEqual(
         "CREATE USER :user@:host "
         "IDENTIFIED BY 'password123';", str(cu))
コード例 #6
0
ファイル: service.py プロジェクト: crowdy/trove
    def enable_root(self, root_password=None):
        """Enable the root user global access and/or
           reset the root password.
        """
        user = models.MySQLUser.root(password=root_password)
        with mysql_util.SqlClient(self.mysql_app.get_engine(),
                                  use_flush=True) as client:
            try:
                cu = sql_query.CreateUser(user.name, host=user.host)
                t = text(str(cu))
                client.execute(t, **cu.keyArgs)
            except (exc.OperationalError, exc.InternalError) as err:
                # Ignore, user is already created, just reset the password
                # TODO(rnirmal): More fine grained error checking later on
                LOG.debug(err)

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

            LOG.debug(
                "CONF.root_grant: %(grant)s CONF.root_grant_option: "
                "%(grant_option)s.", {
                    'grant': CONF.root_grant,
                    'grant_option': CONF.root_grant_option
                })

            g = sql_query.Grant(permissions=CONF.root_grant,
                                user=user.name,
                                host=user.host,
                                grant_option=CONF.root_grant_option)

            t = text(str(g))
            client.execute(t)
            return user.serialize()