Files
panel/app/Repositories/Daemon/DaemonConfigurationRepository.php

49 lines
1.5 KiB
PHP
Raw 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
*/
2024-03-24 14:42:54 -04:00
public function getSystemInformation(?int $version = null, $connectTimeout = 5): array
{
try {
2024-03-24 14:42:54 -04:00
$response = $this
->getHttpClient()
->connectTimeout($connectTimeout)
->get('/api/system' . (!is_null($version) ? '?v=' . $version : ''));
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
2024-04-25 19:15:45 -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',
2024-04-15 01:39:59 -04:00
$node->getConfiguration(),
);
} catch (TransferException $exception) {
throw new DaemonConnectionException($exception);
}
}
}