4
0
mirror of https://github.com/AzuraCast/AzuraCast.git synced 2024-06-14 13:16:37 +00:00
AzuraCast/src/Service/WebUpdater.php
2023-01-05 13:48:55 -06:00

41 lines
968 B
PHP

<?php
namespace App\Service;
use App\Environment;
final class WebUpdater
{
// Don't worry that this is insecure; it's only ever used for internal communications.
public const WATCHTOWER_TOKEN = 'azur4c457';
public function __construct(
private readonly Environment $environment,
private readonly GuzzleFactory $guzzleFactory
) {
}
public function isSupported(): bool
{
return $this->environment->enableWebUpdater();
}
public function triggerUpdate(): void
{
if (!$this->isSupported()) {
throw new \RuntimeException('Web updates are not supported on this installation.');
}
$client = $this->guzzleFactory->buildClient();
$client->post(
'http://updater:8080/v1/update',
[
'headers' => [
'Authorization' => 'Bearer ' . self::WATCHTOWER_TOKEN,
],
]
);
}
}