def delete(self, req, tenant_id, instance_id, user_id, id): """Revoke access for a user.""" LOG.info( _("Revoking user access for instance '%(id)s'\n" "req : '%(req)s'\n\n") % { "id": instance_id, "req": req }) context = req.environ[wsgi.CONTEXT_KEY] self.authorize_target_action(context, 'user_access:delete', instance_id) context.notification = notification.DBaaSUserRevoke(context, request=req) user_id = correct_id_with_req(user_id, req) user = self._get_user(context, instance_id, user_id) if not user: LOG.error(_("No such user: %(user)s ") % {'user': user}) raise exception.UserNotFound(uuid=user) username, hostname = unquote_user_host(user_id) access = models.User.access(context, instance_id, username, hostname) databases = [db.name for db in access.databases] with StartNotification(context, instance_id=instance_id, username=username, database=databases): if id not in databases: raise exception.DatabaseNotFound(uuid=id) models.User.revoke(context, instance_id, username, hostname, id) return wsgi.Result(None, 202)
def revoke_access(self, username, hostname, database): """Remove a database from a users's grant list.""" if (username, hostname) not in self.users: raise rd_exception.UserNotFound( "User %s cannot be found on the instance." % username) if database not in self.grants.get((username, hostname), set()): raise rd_exception.DatabaseNotFound( "Database %s cannot be found on the instance." % database) current_grants = self.grants.get((username, hostname), set()) if database in current_grants: current_grants.remove(database) self.grants[(username, hostname)] = current_grants
def delete(self, req, tenant_id, instance_id, user_id, id): """Revoke access for a user.""" LOG.info(_("Revoking user access for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] user = self._get_user(context, instance_id, user_id) username, hostname = unquote_user_host(user_id) access = models.User.access(context, instance_id, username, hostname) databases = [db.name for db in access.databases] if id not in databases: raise exception.DatabaseNotFound(uuid=id) models.User.revoke(context, instance_id, username, hostname, id) return wsgi.Result(None, 202)
def delete(self, req, tenant_id, instance_id, id): LOG.info("Deleting schema for instance '%(id)s'\n" "req : '%(req)s'\n\n", {"id": instance_id, "req": req}) context = req.environ[wsgi.CONTEXT_KEY] self.authorize_target_action( context, 'database:delete', instance_id) context.notification = notification.DBaaSDatabaseDelete( context, request=req) with StartNotification(context, instance_id=instance_id, dbname=id): try: schema = guest_models.MySQLSchema(name=id) schema.check_delete() if not models.Schemas.find(context, instance_id, id): raise exception.DatabaseNotFound(uuid=id) models.Schema.delete(context, instance_id, schema.serialize()) except (ValueError, AttributeError) as e: raise exception.BadRequest(_("Database delete error: %(e)s") % {'e': e}) return wsgi.Result(None, 202)