2019-09-05 20:33:27 -07:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
namespace App\Repositories\Daemon;
|
2019-09-05 20:33:27 -07:00
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
use App\Models\Node;
|
2019-12-09 21:05:39 -08:00
|
|
|
use GuzzleHttp\Exception\TransferException;
|
2024-03-12 22:39:16 -04:00
|
|
|
use App\Exceptions\Http\Connection\DaemonConnectionException;
|
2019-12-09 21:05:39 -08:00
|
|
|
|
2019-09-05 20:33:27 -07:00
|
|
|
class DaemonConfigurationRepository extends DaemonRepository
|
|
|
|
|
{
|
2019-12-09 21:05:39 -08:00
|
|
|
/**
|
2024-03-12 22:39:16 -04:00
|
|
|
* Returns system information from the daemon instance.
|
2019-12-09 21:05:39 -08:00
|
|
|
*
|
2024-03-12 22:39:16 -04:00
|
|
|
* @throws \App\Exceptions\Http\Connection\DaemonConnectionException
|
2019-12-09 21:05:39 -08:00
|
|
|
*/
|
2024-03-24 14:42:54 -04:00
|
|
|
public function getSystemInformation(?int $version = null, $connectTimeout = 5): array
|
2019-12-09 21:05:39 -08:00
|
|
|
{
|
|
|
|
|
try {
|
2024-03-24 14:42:54 -04:00
|
|
|
$response = $this
|
|
|
|
|
->getHttpClient()
|
|
|
|
|
->connectTimeout($connectTimeout)
|
|
|
|
|
->get('/api/system' . (!is_null($version) ? '?v=' . $version : ''));
|
2019-12-09 21:05:39 -08:00
|
|
|
} catch (TransferException $exception) {
|
|
|
|
|
throw new DaemonConnectionException($exception);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-25 19:15:45 -04:00
|
|
|
return $response->json() ?? [];
|
2019-12-09 21:05:39 -08:00
|
|
|
}
|
2020-04-10 15:15:38 -07:00
|
|
|
|
|
|
|
|
/**
|
2020-04-11 16:33:15 -07:00
|
|
|
* 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.
|
2020-04-10 15:15:38 -07:00
|
|
|
*
|
2024-03-12 22:39:16 -04:00
|
|
|
* @throws \App\Exceptions\Http\Connection\DaemonConnectionException
|
2020-04-10 15:15:38 -07:00
|
|
|
*/
|
2024-03-23 16:10:47 -04:00
|
|
|
public function update(Node $node)
|
2020-04-10 15:15:38 -07:00
|
|
|
{
|
|
|
|
|
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(),
|
2020-04-10 15:15:38 -07:00
|
|
|
);
|
|
|
|
|
} catch (TransferException $exception) {
|
|
|
|
|
throw new DaemonConnectionException($exception);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-05 20:33:27 -07:00
|
|
|
}
|