Ejemplo n.º 1
0
 def delete_database(self, database):
     """Delete the specified database"""
     with LocalSqlClient(get_engine()) as client:
         mydb = models.ValidatedMySQLDatabase()
         mydb.deserialize(database)
         dd = query.DropDatabase(mydb.name)
         t = text(str(dd))
         client.execute(t)
Ejemplo n.º 2
0
 def create_database(self, databases):
     """Create the list of specified databases"""
     with LocalSqlClient(get_engine()) as client:
         for item in databases:
             mydb = models.ValidatedMySQLDatabase()
             mydb.deserialize(item)
             cd = query.CreateDatabase(mydb.name, mydb.character_set,
                                       mydb.collate)
             t = text(str(cd))
             client.execute(t)
Ejemplo n.º 3
0
 def delete(self, req, tenant_id, instance_id, id):
     LOG.info(_("Deleting schema for instance '%s'") % instance_id)
     LOG.info(_("req : '%s'\n\n") % req)
     context = req.environ[wsgi.CONTEXT_KEY]
     try:
         schema = guest_models.ValidatedMySQLDatabase()
         schema.name = id
         models.Schema.delete(context, instance_id, schema.serialize())
     except (ValueError, AttributeError) as e:
         raise exception.BadRequest(msg=str(e))
     return wsgi.Result(None, 202)
Ejemplo n.º 4
0
def populate_validated_databases(dbs):
    """
    Create a serializable request with user provided data
    for creating new databases.
    """
    try:
        databases = []
        for database in dbs:
            mydb = guest_models.ValidatedMySQLDatabase()
            mydb.name = database.get('name', '')
            mydb.character_set = database.get('character_set', '')
            mydb.collate = database.get('collate', '')
            databases.append(mydb.serialize())
        return databases
    except ValueError as ve:
        # str(ve) contains user input and may include '%' which can cause a
        # format str vulnerability. Escape the '%' to avoid this. This is
        # okay to do since we're not using dict args here in any case.
        safe_string = str(ve).replace('%', '%%')
        raise exception.BadRequest(safe_string)
Ejemplo n.º 5
0
 def create_user(self, users):
     """Create users and grant them privileges for the
        specified databases"""
     with LocalSqlClient(get_engine()) as client:
         for item in users:
             user = models.MySQLUser()
             user.deserialize(item)
             # TODO(cp16net):Should users be allowed to create users
             # 'os_admin' or 'debian-sys-maint'
             g = query.Grant(user=user.name,
                             host=user.host,
                             clear=user.password)
             t = text(str(g))
             client.execute(t)
             for database in user.databases:
                 mydb = models.ValidatedMySQLDatabase()
                 mydb.deserialize(database)
                 g = query.Grant(permissions='ALL',
                                 database=mydb.name,
                                 user=user.name,
                                 host=user.host,
                                 clear=user.password)
                 t = text(str(g))
                 client.execute(t)
Ejemplo n.º 6
0
    def setUp(self):
        super(MySQLDatabaseTest, self).setUp()

        self.mysqlDb = dbmodels.ValidatedMySQLDatabase()
        self.origin_ignore_db = self.mysqlDb._ignore_dbs
        self.mysqlDb._ignore_dbs = ['mysql']