pelican-panel-mirror/app/Repositories/Daemon/DaemonPowerRepository.php
2024-03-23 16:10:47 -04:00

31 lines
840 B
PHP

<?php
namespace App\Repositories\Daemon;
use Webmozart\Assert\Assert;
use App\Models\Server;
use GuzzleHttp\Exception\TransferException;
use App\Exceptions\Http\Connection\DaemonConnectionException;
class DaemonPowerRepository extends DaemonRepository
{
/**
* Sends a power action to the server instance.
*
* @throws \App\Exceptions\Http\Connection\DaemonConnectionException
*/
public function send(string $action)
{
Assert::isInstanceOf($this->server, Server::class);
try {
return $this->getHttpClient()->post(
sprintf('/api/servers/%s/power', $this->server->uuid),
['json' => ['action' => $action]]
);
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
}
}