43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support;
|
|
|
|
use Illuminate\Http\Client\PendingRequest;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
final class TlsHttpClientFactory
|
|
{
|
|
public static function vCenter(): PendingRequest
|
|
{
|
|
return Http::withOptions(['verify' => self::verifyOption('vmware')]);
|
|
}
|
|
|
|
public static function plesk(): PendingRequest
|
|
{
|
|
return Http::withOptions(['verify' => self::verifyOption('services.plesk')]);
|
|
}
|
|
|
|
/** @return array<int, mixed> */
|
|
public static function vCenterCurlOptions(): array
|
|
{
|
|
$verify = self::verifyOption('vmware');
|
|
|
|
return array_filter([
|
|
CURLOPT_SSL_VERIFYPEER => $verify !== false,
|
|
CURLOPT_SSL_VERIFYHOST => $verify === false ? 0 : 2,
|
|
CURLOPT_CAINFO => is_string($verify) ? $verify : null,
|
|
], fn ($value) => $value !== null);
|
|
}
|
|
|
|
private static function verifyOption(string $configKey): bool|string
|
|
{
|
|
if (!config("{$configKey}.tls_verify", true)) {
|
|
return false;
|
|
}
|
|
|
|
return config("{$configKey}.ca_bundle") ?: true;
|
|
}
|
|
}
|