registries()->firstOrNew([ 'type' => RegistryType::MANAGED->value, ]); $registry->fill([ 'name' => 'Managed Registry', 'url' => $this->registryHost($url), 'storage_path' => $storagePath ?: (string) config('keystone.managed_registry.storage_path'), 'retention_successful_artifacts' => $retention ?: (int) config('keystone.managed_registry.retention.successful_artifacts_per_environment', 3), 'control_server_id' => $controlServer?->id, 'credentials' => $this->credentials($registry->credentials ?? []), ]); if ($registry->health_status === null) { $registry->health_status = 'pending'; } $registry->save(); if ($controlServer instanceof Server) { $controlServer->forceFill([ 'is_control_node' => true, 'build_enabled' => true, ])->save(); } return $registry->refresh(); } /** * @param array $existing * @return array */ private function credentials(array $existing): array { return [ 'build_username' => (string) ($existing['build_username'] ?? 'keystone-build'), 'build_password' => (string) ($existing['build_password'] ?? Str::password(40)), 'runtime_username' => (string) ($existing['runtime_username'] ?? 'keystone-runtime'), 'runtime_password' => (string) ($existing['runtime_password'] ?? Str::password(40)), ]; } private function registryHost(string $url): string { $host = preg_replace('#^https?://#', '', trim($url)); return rtrim($host === null ? trim($url) : $host, '/'); } }