Beispiel #1
0
    def list_users(self, limit=None, marker=None, include_marker=False):
        """List users that have access to the database"""
        LOG.debug(_("---Listing Users---"))
        users = []
        client = LocalSqlClient(get_engine())
        with client:
            mysql_user = models.MySQLUser()
            q = Query()
            q.columns = ['User']
            q.tables = ['mysql.user']
            q.where = ["host != 'localhost'"]
            q.order = ['User']
            if marker:
                q.where.append("User %s '%s'" %
                               (INCLUDE_MARKER_OPERATORS[include_marker],
                                marker))
            if limit:
                q.limit = limit + 1
            t = text(str(q))
            result = client.execute(t)
            next_marker = None
            LOG.debug("result = " + str(result))
            for count, row in enumerate(result):
                if count >= limit:
                    break
                LOG.debug("user = "******"^'(.+)'@", db['grantee'])
                    if (matches is not None and
                            matches.group(1) == mysql_user.name):
                        mysql_db = models.MySQLDatabase()
                        mysql_db.name = db['table_schema']
                        mysql_user.databases.append(mysql_db.serialize())
                users.append(mysql_user.serialize())
        if result.rowcount <= limit:
            next_marker = None
        LOG.debug("users = " + str(users))

        return users, next_marker
Beispiel #2
0
    def list_users(self, limit=None, marker=None, include_marker=False):
        """List users that have access to the database"""
        LOG.debug(_("---Listing Users---"))
        users = []
        client = LocalSqlClient(get_engine())
        with client:
            mysql_user = models.MySQLUser()
            q = Query()
            q.columns = ['User']
            q.tables = ['mysql.user']
            q.where = ["host != 'localhost'"]
            q.order = ['User']
            if marker:
                q.where.append(
                    "User %s '%s'" %
                    (INCLUDE_MARKER_OPERATORS[include_marker], marker))
            if limit:
                q.limit = limit + 1
            t = text(str(q))
            result = client.execute(t)
            next_marker = None
            LOG.debug("result = " + str(result))
            for count, row in enumerate(result):
                if count >= limit:
                    break
                LOG.debug("user = "******"^'(.+)'@", db['grantee'])
                    if (matches is not None
                            and matches.group(1) == mysql_user.name):
                        mysql_db = models.MySQLDatabase()
                        mysql_db.name = db['table_schema']
                        mysql_user.databases.append(mysql_db.serialize())
                users.append(mysql_user.serialize())
        if result.rowcount <= limit:
            next_marker = None
        LOG.debug("users = " + str(users))

        return users, next_marker
Beispiel #3
0
 def list_databases(self, limit=None, marker=None, include_marker=False):
     """List databases the user created on this mysql instance"""
     LOG.debug(_("---Listing Databases---"))
     databases = []
     client = LocalSqlClient(get_engine())
     with client:
         # If you have an external volume mounted at /var/lib/mysql
         # the lost+found directory will show up in mysql as a database
         # which will create errors if you try to do any database ops
         # on it.  So we remove it here if it exists.
         q = Query()
         q.columns = [
             'schema_name as name',
             'default_character_set_name as charset',
             'default_collation_name as collation',
         ]
         q.tables = ['information_schema.schemata']
         q.where = [
             '''schema_name not in (
                         'mysql', 'information_schema',
                         'lost+found', '#mysql50#lost+found'
                     )'''
         ]
         q.order = ['schema_name ASC']
         if limit:
             q.limit = limit + 1
         if marker:
             q.where.append(
                 "schema_name %s '%s'" %
                 (INCLUDE_MARKER_OPERATORS[include_marker], marker))
         t = text(str(q))
         database_names = client.execute(t)
         next_marker = None
         LOG.debug(_("database_names = %r") % database_names)
         for count, database in enumerate(database_names):
             if count >= limit:
                 break
             LOG.debug(_("database = %s ") % str(database))
             mysql_db = models.MySQLDatabase()
             mysql_db.name = database[0]
             next_marker = mysql_db.name
             mysql_db.character_set = database[1]
             mysql_db.collate = database[2]
             databases.append(mysql_db.serialize())
     LOG.debug(_("databases = ") + str(databases))
     if database_names.rowcount <= limit:
         next_marker = None
     return databases, next_marker
Beispiel #4
0
 def list_databases(self, limit=None, marker=None, include_marker=False):
     """List databases the user created on this mysql instance"""
     LOG.debug(_("---Listing Databases---"))
     databases = []
     client = LocalSqlClient(get_engine())
     with client:
         # If you have an external volume mounted at /var/lib/mysql
         # the lost+found directory will show up in mysql as a database
         # which will create errors if you try to do any database ops
         # on it.  So we remove it here if it exists.
         q = Query()
         q.columns = [
             'schema_name as name',
             'default_character_set_name as charset',
             'default_collation_name as collation',
         ]
         q.tables = ['information_schema.schemata']
         q.where = ['''schema_name not in (
                         'mysql', 'information_schema',
                         'lost+found', '#mysql50#lost+found'
                     )''']
         q.order = ['schema_name ASC']
         if limit:
             q.limit = limit + 1
         if marker:
             q.where.append("schema_name %s '%s'" %
                            (INCLUDE_MARKER_OPERATORS[include_marker],
                             marker))
         t = text(str(q))
         database_names = client.execute(t)
         next_marker = None
         LOG.debug(_("database_names = %r") % database_names)
         for count, database in enumerate(database_names):
             if count >= limit:
                 break
             LOG.debug(_("database = %s ") % str(database))
             mysql_db = models.MySQLDatabase()
             mysql_db.name = database[0]
             next_marker = mysql_db.name
             mysql_db.character_set = database[1]
             mysql_db.collate = database[2]
             databases.append(mysql_db.serialize())
     LOG.debug(_("databases = ") + str(databases))
     if database_names.rowcount <= limit:
         next_marker = None
     return databases, next_marker