operationRun = $operationRun; } /** * @return array */ public function middleware(): array { return [new TrackOperationRun]; } public function handle( RbacHealthService $rbacHealthService, OperationRunService $runs, ): void { $tenant = Tenant::query()->find($this->tenantId); if (! $tenant instanceof Tenant) { throw new RuntimeException('Tenant not found.'); } $user = User::query()->find($this->userId); if (! $user instanceof User) { throw new RuntimeException('User not found.'); } $result = $rbacHealthService->check($tenant); if (! $this->operationRun instanceof OperationRun) { return; } $status = $result['status'] ?? 'error'; $isHealthy = in_array($status, ['ok', 'configured', 'manual_assignment_required'], true); if ($isHealthy) { $runs->updateRun( $this->operationRun, status: OperationRunStatus::Completed->value, outcome: OperationRunOutcome::Succeeded->value, ); return; } $runs->updateRun( $this->operationRun, status: OperationRunStatus::Completed->value, outcome: OperationRunOutcome::Failed->value, failures: [[ 'code' => 'rbac.health_check.failed', 'reason_code' => $result['reason'] ?? 'unknown', 'message' => sprintf('RBAC health check completed with status: %s', $status), ]], ); } }