You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Services/Cloud/CloudAgentGatewayEndpoint.php

39 lines
1.4 KiB
PHP

<?php
namespace App\Services\Cloud;
/** Strict loopback endpoint for PHP-to-Go Agent gateway dispatch. */
final class CloudAgentGatewayEndpoint
{
public const PATH = '/internal/agent/request';
public const URL = 'http://127.0.0.1:8001' . self::PATH;
public static function normalize($value): string
{
if (!is_string($value)) {
throw new \InvalidArgumentException('Agent gateway URL is invalid');
}
$value = trim($value);
if ($value === '' || strlen($value) > 2048
|| preg_match('/[\x00-\x20\x7f\\\\]/', $value) === 1) {
throw new \InvalidArgumentException('Agent gateway URL is invalid');
}
$parts = parse_url($value);
if (!is_array($parts)) {
throw new \InvalidArgumentException('Agent gateway URL is invalid');
}
$scheme = strtolower((string) ($parts['scheme'] ?? ''));
$host = (string) ($parts['host'] ?? '');
if ($scheme !== 'http' || $host !== '127.0.0.1'
|| ($parts['path'] ?? '') !== self::PATH
|| isset($parts['user']) || isset($parts['pass'])
|| isset($parts['query']) || isset($parts['fragment'])
|| ($parts['port'] ?? null) !== 8001) {
throw new \InvalidArgumentException(
'Agent gateway URL must be the fixed 127.0.0.1:8001 dispatch endpoint'
);
}
return self::URL;
}
}