Files
api/services/nginx/app/classes/edge_gateway_install_service.php
T
Jeppe Bundgaard 7d450e285e Remove outdated edge gateway object classes, add new agent implementation
Transitioned from obsolete gateway object classes (`edge_gateway_shell_action_jobs_o`, `edge_gateway_shell_events_o`, `edge_gateway_shell_sessions_o`, `edge_gateway_update_jobs_o`) to the new agent implementation (`edge-gateway-agent/agent.php`).
2026-04-21 14:13:17 +02:00

73 lines
1.8 KiB
PHP

<?php
namespace classes;
use Exception;
class edge_gateway_install_service
{
private const ARTIFACTS = [
'agent.php' => 'application/x-httpd-php; charset=utf-8',
'truckwash-edge-agent.service' => 'text/plain; charset=utf-8',
];
public function __construct(private readonly ?edge_gateway_manager $manager = null)
{
edge_gateway_schema_bootstrap::ensureTables();
}
public function buildInstallScript(string $plainToken): string
{
return $this->manager()->buildInstallScript($plainToken);
}
/**
* @throws Exception
*/
public function verifyInstallToken(string $plainToken): array
{
return $this->manager()->verifyInstallToken($plainToken);
}
/**
* @throws Exception
*/
public function readArtifact(string $fileName): string
{
$path = $this->artifactPath($fileName);
$contents = file_get_contents($path);
if ($contents === false) {
throw new Exception('Unable to read edge agent artifact');
}
return $contents;
}
public function contentType(string $fileName): string
{
return self::ARTIFACTS[$fileName] ?? 'application/octet-stream';
}
public function buildArtifactUrl(string $fileName): string
{
return rtrim($this->manager()->getApiBaseUrl(), '/') . '/edge-agent/artifacts/' . $fileName;
}
/**
* @throws Exception
*/
public function artifactPath(string $fileName): string
{
if (!array_key_exists($fileName, self::ARTIFACTS)) {
throw new Exception('Unknown edge agent artifact');
}
return edge_gateway_agent_artifact_locator::resolve($fileName);
}
private function manager(): edge_gateway_manager
{
return $this->manager ?? new edge_gateway_manager();
}
}