*/ #[Endpoint('Rotate server database password', 'Rotates the password for a database assigned to a server.')] #[ResponseFromTransformer(ServerDatabaseTransformer::class, Database::class, description: 'Database password rotated.', resourceKey: 'server_database', include: ['password'])] public function __invoke(ServerDatabaseWriteRequest $request, RotatesDatabasePasswords $passwordService, Server $server, Database $database): array { if ($database->server_id !== $server->id) { throw (new ModelNotFoundException)->setModel(Database::class); } // The action commits its own transaction around the remote user change, so the // activity is logged afterwards instead of wrapping a change it cannot undo. $passwordService->rotate($database); Activity::event('admin:server-database.rotate-password') ->subject($database) ->property('name', $database->database) ->log(); return Fractal::item($database->refresh()) ->parseIncludes(['password']) ->transformWith($this->getTransformer(ServerDatabaseTransformer::class)) ->toResponseArray(); } }