def update(self, req, body, tenant_id, instance_id, id): LOG.info(_LI("Updating user attributes for instance '%(id)s'\n" "req : '%(req)s'\n\n") % {"id": instance_id, "req": strutils.mask_password(req)}) context = req.environ[wsgi.CONTEXT_KEY] self.authorize_target_action(context, 'user:update', instance_id) user_id = correct_id_with_req(id, req) updates = body['user'] context.notification = notification.DBaaSUserUpdateAttributes( context, request=req) client = self.create_guest_client(context, instance_id) with StartNotification(context, instance_id=instance_id, username=user_id): try: if self.is_reserved_id(user_id): raise exception.ReservedUserId(name=user_id) model = self.find_user(client, user_id) if not model: raise exception.UserNotFound(uuid=user_id) new_user_id = self.apply_user_updates(model, updates) if (new_user_id is not None and self.find_user(client, new_user_id)): raise exception.UserAlreadyExists(name=new_user_id) self.update_user(client, user_id, updates) except (ValueError, AttributeError) as e: raise exception.BadRequest(str(e)) return wsgi.Result(None, 202)
def update(self, req, body, tenant_id, instance_id, id): """Change attributes for one user.""" LOG.info(_("Updating user attributes for instance '%(id)s'\n" "req : '%(req)s'\n\n") % {"id": instance_id, "req": strutils.mask_password(req)}) context = req.environ[wsgi.CONTEXT_KEY] id = correct_id_with_req(id, req) username, hostname = unquote_user_host(id) user = None user_attrs = body['user'] context.notification = notification.DBaaSUserUpdateAttributes( context, request=req) with StartNotification(context, instance_id=instance_id, username=username): try: user = models.User.load(context, instance_id, username, hostname) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) if not user: raise exception.UserNotFound(uuid=id) try: models.User.update_attributes(context, instance_id, username, hostname, user_attrs) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) return wsgi.Result(None, 202)
def delete(self, req, tenant_id, instance_id, id): LOG.info(_LI("Delete 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:delete', instance_id) database_id = correct_id_with_req(id, req) context.notification = notification.DBaaSDatabaseDelete(context, request=req) client = self.create_guest_client(context, instance_id) with StartNotification(context, instance_id=instance_id, dbname=database_id): try: if self.is_reserved_id(database_id): raise exception.ReservedDatabaseId(name=database_id) model = self.find_database(client, database_id) if not model: raise exception.DatabaseNotFound(uuid=database_id) self.delete_database(client, model) except (ValueError, AttributeError) as e: raise exception.BadRequest(str(e)) return wsgi.Result(None, 202)
def delete(self, req, tenant_id, instance_id, id): LOG.info(_("Delete instance '%(id)s'\n" "req : '%(req)s'\n\n") % {"id": instance_id, "req": req}) context = req.environ[wsgi.CONTEXT_KEY] id = correct_id_with_req(id, req) username, host = unquote_user_host(id) context.notification = notification.DBaaSUserDelete(context, request=req) with StartNotification(context, instance_id=instance_id, username=username): user = None try: user = guest_models.MySQLUser() user.name = username user.host = host found_user = models.User.load(context, instance_id, username, host) if not found_user: user = None except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) if not user: raise exception.UserNotFound(uuid=id) models.User.delete(context, instance_id, user.serialize()) return wsgi.Result(None, 202)
def update(self, req, body, tenant_id, instance_id, user_id): """Grant access for a user to one or more databases.""" LOG.info(_("Granting user access for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] 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) databases = [db['name'] for db in body['databases']] models.User.grant(context, instance_id, username, hostname, databases) return wsgi.Result(None, 202)
def index(self, req, tenant_id, instance_id, user_id): """Show permissions for the given user.""" LOG.info(_("Showing user access for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] # Make sure this user exists. 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) view = views.UserAccessView(access.databases) return wsgi.Result(view.data(), 200)
def index(self, req, tenant_id, instance_id, user_id): LOG.info(_("Showing 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:index', instance_id) user_id = correct_id_with_req(user_id, req) self.assert_user_show(req, tenant_id, instance_id, user_id) client = self.create_guest_client(context, instance_id) databases = self.list_access(client, user_id) view = self.build_model_collection_view(databases) return wsgi.Result(view.data(), 200)
def show(self, req, tenant_id, instance_id, id): """Return a single user.""" LOG.info(_("Showing a user for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] id = correct_id_with_req(id, req) username, host = unquote_user_host(id) user = None try: user = models.User.load(context, instance_id, username, host) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) if not user: raise exception.UserNotFound(uuid=id) view = views.UserView(user) return wsgi.Result(view.data(), 200)
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_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] 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 user for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] id = correct_id_with_req(id, req) username, host = unquote_user_host(id) user = None try: user = guest_models.MySQLUser() user.name = username user.host = host found_user = models.User.load(context, instance_id, username, host) if not found_user: user = None except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) if not user: raise exception.UserNotFound(uuid=id) models.User.delete(context, instance_id, user.serialize()) return wsgi.Result(None, 202)
def update(self, req, body, tenant_id, instance_id, id): """Change attributes for one user.""" LOG.info(_("Updating user attributes for instance '%s'") % instance_id) LOG.info(logging.mask_password(_("req : '%s'\n\n") % req)) context = req.environ[wsgi.CONTEXT_KEY] id = correct_id_with_req(id, req) username, hostname = unquote_user_host(id) user = None user_attrs = body["user"] try: user = models.User.load(context, instance_id, username, hostname) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) if not user: raise exception.UserNotFound(uuid=id) try: models.User.update_attributes(context, instance_id, username, hostname, user_attrs) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) return wsgi.Result(None, 202)
def index(self, req, tenant_id, instance_id, user_id): """Show permissions for the given user.""" LOG.info( _("Showing 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:index', instance_id) # Make sure this user exists. 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) view = views.UserAccessView(access.databases) return wsgi.Result(view.data(), 200)
def show(self, req, tenant_id, instance_id, id): """Return a single user.""" LOG.info( _("Showing a user 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:show', instance_id) id = correct_id_with_req(id, req) username, host = unquote_user_host(id) user = None try: user = models.User.load(context, instance_id, username, host) except (ValueError, AttributeError) as e: raise exception.BadRequest(_("User show error: %(e)s") % {'e': e}) if not user: raise exception.UserNotFound(uuid=id) view = views.UserView(user) return wsgi.Result(view.data(), 200)
def update(self, req, body, tenant_id, instance_id, user_id): """Grant access for a user to one or more databases.""" LOG.info(_("Granting user access for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] context.notification = notification.DBaaSUserGrant(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) databases = [db['name'] for db in body['databases']] with StartNotification(context, instance_id=instance_id, username=username, database=databases): models.User.grant(context, instance_id, username, hostname, databases) return wsgi.Result(None, 202)
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] 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] 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 update(self, req, body, tenant_id, instance_id, id): """Change attributes for one user.""" LOG.info(_("Updating user attributes for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] id = correct_id_with_req(id, req) username, hostname = unquote_user_host(id) user = None user_attrs = body['user'] try: user = models.User.load(context, instance_id, username, hostname) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) if not user: raise exception.UserNotFound(uuid=id) try: models.User.update_attributes(context, instance_id, username, hostname, user_attrs) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) return wsgi.Result(None, 202)
def show(self, req, tenant_id, instance_id, id): LOG.info(_LI("Showing a database 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:show', instance_id) database_id = correct_id_with_req(id, req) client = self.create_guest_client(context, instance_id) try: if self.is_reserved_id(database_id): raise exception.ReservedDatabaseId(name=database_id) model = self.find_database(client, database_id) if not model: raise exception.DatabaseNotFound(uuid=database_id) view = self.build_model_view(model) return wsgi.Result(view.data(), 200) except (ValueError, AttributeError) as e: raise exception.BadRequest(str(e))
def delete(self, req, tenant_id, instance_id, user_id, id): 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) with StartNotification(context, instance_id=instance_id, username=user_id, database=id): self.assert_user_show(req, tenant_id, instance_id, user_id) client = self.create_guest_client(context, instance_id) if not self.has_access(client, user_id, id): raise exception.DatabaseNotInAccessList( database_name=id, user_name=user_id) self.revoke_access(client, user_id, id) return wsgi.Result(None, 202)
def update(self, req, body, tenant_id, instance_id, user_id): LOG.info(_("Granting 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:update', instance_id) user_id = correct_id_with_req(user_id, req) context.notification = notification.DBaaSUserGrant( context, request=req) database_ids = self.parse_database_ids_from_request(body['databases']) with StartNotification(context, instance_id=instance_id, username=user_id, database=",".join(database_ids)): self.assert_user_show(req, tenant_id, instance_id, user_id) for database_id in database_ids: self.assert_database_show( req, tenant_id, instance_id, database_id) client = self.create_guest_client(context, instance_id) self.grant_access(client, user_id, database_ids) return wsgi.Result(None, 202)