Files
panel-pelican-dev/app/Repositories/Daemon/DaemonConfigurationRepository.php

46 lines
1.4 KiB
PHP
Raw Permalink Normal View History

<?php
2024-03-12 22:39:16 -04:00
namespace App\Repositories\Daemon;
2024-03-12 22:39:16 -04:00
use App\Models\Node;
use GuzzleHttp\Exception\TransferException;
2024-03-12 22:39:16 -04:00
use App\Exceptions\Http\Connection\DaemonConnectionException;
class DaemonConfigurationRepository extends DaemonRepository
{
/**
2024-03-12 22:39:16 -04:00
* Returns system information from the daemon instance.
*
2024-03-12 22:39:16 -04:00
* @throws \App\Exceptions\Http\Connection\DaemonConnectionException
*/
2022-11-22 13:39:43 -07:00
public function getSystemInformation(?int $version = null): array
{
try {
2022-11-22 13:39:43 -07:00
$response = $this->getHttpClient()->get('/api/system' . (!is_null($version) ? '?v=' . $version : ''));
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
2024-03-23 16:10:47 -04:00
return $response->json();
}
/**
* Updates the configuration information for a daemon. Updates the information for
* this instance using a passed-in model. This allows us to change plenty of information
* in the model, and still use the old, pre-update model to actually make the HTTP request.
*
2024-03-12 22:39:16 -04:00
* @throws \App\Exceptions\Http\Connection\DaemonConnectionException
*/
2024-03-23 16:10:47 -04:00
public function update(Node $node)
{
try {
return $this->getHttpClient()->post(
2021-01-23 12:33:34 -08:00
'/api/update',
['json' => $node->getConfiguration()]
);
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
}
}