Require authorization for LAN worker relay endpoints
This commit is contained in:
@@ -61,7 +61,7 @@ final class OperationAbortException extends RuntimeException
|
||||
|
||||
final class HttpJsonClient
|
||||
{
|
||||
public function __construct(private readonly string $baseUrl)
|
||||
public function __construct(private readonly string $baseUrl, private readonly array $defaultHeaders = [])
|
||||
{
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ final class HttpJsonClient
|
||||
|
||||
private function requestJson(string $method, string $url, ?array $payload, int $timeoutSeconds): array
|
||||
{
|
||||
$headers = ['Accept: application/json'];
|
||||
$headers = array_values(array_merge(['Accept: application/json'], $this->defaultHeaders));
|
||||
if ($payload !== null) {
|
||||
$headers[] = 'Content-Type: application/json';
|
||||
}
|
||||
@@ -1031,7 +1031,10 @@ final class TruckwashEdgeAgent
|
||||
}
|
||||
|
||||
$this->http = new HttpJsonClient((string)$this->config->get('apiUrl'));
|
||||
$this->workerHttp = new HttpJsonClient((string)$this->config->get('workerBaseUrl', self::DEFAULT_WORKER_BASE_URL));
|
||||
$this->workerHttp = new HttpJsonClient(
|
||||
(string)$this->config->get('workerBaseUrl', self::DEFAULT_WORKER_BASE_URL),
|
||||
$this->workerAuthorizationHeaders()
|
||||
);
|
||||
$this->logger = new Logger($this->runtimeDir . DIRECTORY_SEPARATOR . 'agent.log');
|
||||
$this->stateStore = new LocalStateStore((string)$this->config->get('stateDatabasePath', self::DEFAULT_STATE_DATABASE));
|
||||
$this->statePath = $this->runtimeDir . DIRECTORY_SEPARATOR . 'current-operation.json';
|
||||
@@ -2615,6 +2618,12 @@ final class TruckwashEdgeAgent
|
||||
}
|
||||
}
|
||||
|
||||
private function workerAuthorizationHeaders(): array
|
||||
{
|
||||
$agentToken = trim((string)$this->config->get('agentToken', ''));
|
||||
return $agentToken !== '' ? ['X-Truckwash-Worker-Token: ' . $agentToken] : [];
|
||||
}
|
||||
|
||||
private function ensureAgentInstanceId(): string
|
||||
{
|
||||
$configured = trim((string)$this->config->get('agentInstanceId', ''));
|
||||
|
||||
Reference in New Issue
Block a user