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 ;
2025-01-07 22:58:04 +01:00
use Illuminate\Http\Client\ConnectionException ;
2024-10-19 21:00:11 -04:00
use Illuminate\Http\Client\Response ;
2019-12-09 21:05:39 -08:00
2025-11-08 15:47:40 -05:00
class DaemonSystemRepository extends DaemonRepository
2019-09-05 20:33:27 -07:00
{
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
*
2025-03-03 14:41:19 -05:00
* @ return array < mixed >
*
2025-01-07 22:58:04 +01:00
* @ throws ConnectionException
2019-12-09 21:05:39 -08:00
*/
2025-01-07 22:58:04 +01:00
public function getSystemInformation () : array
2019-12-09 21:05:39 -08:00
{
2025-01-07 22:58:04 +01:00
return $this -> getHttpClient ()
-> connectTimeout ( 3 )
2025-02-22 21:44:49 +01:00
-> get ( '/api/system' )
-> throwIf ( function ( $result ) {
2025-05-01 15:49:35 +02:00
$this -> enforceValidNodeToken ( $result );
2026-07-09 09:55:11 -04:00
throw_unless ( $result -> collect () -> has ([ 'architecture' , 'cpu_count' , 'kernel_version' , 'os' , 'version' ]), new ConnectionException ( $result -> effectiveUri () -> __toString () . ' is not Pelican Wings !' ));
2025-02-22 21:44:49 +01:00
return true ;
}) -> json ();
2019-12-09 21:05:39 -08:00
}
2020-04-10 15:15:38 -07:00
2025-11-08 15:47:40 -05:00
/**
* Retrieve diagnostics from the daemon for the current node .
*
*
* @ throws ConnectionException
*/
public function getDiagnostics ( int $lines , bool $includeEndpoints , bool $includeLogs ) : Response
{
return $this -> getHttpClient ()
-> timeout ( 5 )
-> get ( '/api/diagnostics' , [
'log_lines' => $lines ,
'include_endpoints' => $includeEndpoints ? 'true' : 'false' ,
'include_logs' => $includeLogs ? 'true' : 'false' ,
]);
}
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
*
2025-01-07 22:58:04 +01:00
* @ throws ConnectionException
2020-04-10 15:15:38 -07:00
*/
2024-10-19 21:00:11 -04:00
public function update ( Node $node ) : Response
2020-04-10 15:15:38 -07:00
{
2025-01-07 22:58:04 +01:00
return $this -> getHttpClient () -> post ( '/api/update' , $node -> getConfiguration ());
2020-04-10 15:15:38 -07:00
}
2019-09-05 20:33:27 -07:00
}