update fix deadcode, security
This commit is contained in:
@@ -5,9 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Services;
|
||||
|
||||
use App\Http\Facade\SignRSA;
|
||||
use App\Http\Services\vCenter as VCenterService;
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Support\TlsHttpClientFactory;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
final class VmProvisionService
|
||||
@@ -21,48 +19,6 @@ final class VmProvisionService
|
||||
return config('vmware.template_password');
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// vCenter REST helpers (used by WaitVmReadyJob if still in flow)
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public function loginVCenter(\App\Models\vCenter $vcenter, VCenterService $service): void
|
||||
{
|
||||
if (!$service->loginServer($vcenter)) {
|
||||
throw new \RuntimeException("vCenter login failed for host={$vcenter->host}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{tools_running:bool,ip_address:string|null,os_family:string|null}
|
||||
*/
|
||||
public function getVmGuestInfo(VCenterService $service, string $vmId): array
|
||||
{
|
||||
try {
|
||||
$response = TlsHttpClientFactory::vCenter()
|
||||
->withHeaders(['vmware-api-session-id' => $service->token])
|
||||
->timeout(10)
|
||||
->get("https://{$service->apiUri}/rest/vcenter/vm/{$vmId}/guest/identity");
|
||||
|
||||
if (!$response->successful()) {
|
||||
return ['tools_running' => false, 'ip_address' => null, 'os_family' => null];
|
||||
}
|
||||
|
||||
$value = $response->json('value', []);
|
||||
$ip = trim((string) ($value['ip_address'] ?? ''));
|
||||
|
||||
return [
|
||||
'tools_running' => $ip !== '' && $ip !== '0.0.0.0',
|
||||
'ip_address' => $ip ?: null,
|
||||
'os_family' => isset($value['family']) ? strtoupper((string) $value['family']) : null,
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('VmProvisionService::getVmGuestInfo error', [
|
||||
'vm_id' => $vmId, 'error' => $e->getMessage(),
|
||||
]);
|
||||
return ['tools_running' => false, 'ip_address' => null, 'os_family' => null];
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Password
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -124,21 +80,4 @@ final class VmProvisionService
|
||||
'module_vmware_id' => $moduleVmwareId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update password + overwrite IP (used when real guest IP differs from pool IP).
|
||||
*/
|
||||
public function savePassword(int $moduleVmwareId, string $ip, string $plainPassword): void
|
||||
{
|
||||
ModuleVmware::findOrFail($moduleVmwareId)->update([
|
||||
'ip' => $ip,
|
||||
'password' => $this->encryptPassword($plainPassword),
|
||||
'plain_password' => $plainPassword,
|
||||
]);
|
||||
|
||||
Log::info('VmProvisionService::savePassword saved', [
|
||||
'module_vmware_id' => $moduleVmwareId,
|
||||
'ip' => $ip,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user