From 1271532df81df6edd9221612a02dc26a678a35fe Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 5 Nov 2025 06:55:38 -0500 Subject: [PATCH] refactor function --- .../Admin/Resources/Nodes/Pages/EditNode.php | 21 ++++++++----------- app/Models/Node.php | 4 ++-- app/Providers/AppServiceProvider.php | 13 ------------ app/Repositories/Daemon/DaemonRepository.php | 19 ----------------- ...ository.php => DaemonSystemRepository.php} | 19 ++++++++++++++++- .../Daemon/HttpDaemonRepository.php | 8 ------- app/Services/Nodes/NodeUpdateService.php | 4 ++-- 7 files changed, 31 insertions(+), 57 deletions(-) rename app/Repositories/Daemon/{DaemonConfigurationRepository.php => DaemonSystemRepository.php} (69%) delete mode 100644 app/Repositories/Daemon/HttpDaemonRepository.php diff --git a/app/Filament/Admin/Resources/Nodes/Pages/EditNode.php b/app/Filament/Admin/Resources/Nodes/Pages/EditNode.php index d3bc64cf4..2bcbddbf3 100644 --- a/app/Filament/Admin/Resources/Nodes/Pages/EditNode.php +++ b/app/Filament/Admin/Resources/Nodes/Pages/EditNode.php @@ -4,8 +4,7 @@ namespace App\Filament\Admin\Resources\Nodes\Pages; use App\Filament\Admin\Resources\Nodes\NodeResource; use App\Models\Node; -use App\Repositories\Daemon\DaemonConfigurationRepository; -use App\Repositories\Daemon\DaemonRepository; +use App\Repositories\Daemon\DaemonSystemRepository; use App\Services\Helpers\SoftwareVersionService; use App\Services\Nodes\NodeAutoDeployService; use App\Services\Nodes\NodeUpdateService; @@ -51,17 +50,14 @@ class EditNode extends EditRecord protected static string $resource = NodeResource::class; - private DaemonConfigurationRepository $daemonConfigurationRepository; - - private DaemonRepository $daemonRepository; + private DaemonSystemRepository $daemonSystemRepository; private NodeUpdateService $nodeUpdateService; - public function boot(DaemonConfigurationRepository $daemonConfigurationRepository, NodeUpdateService $nodeUpdateService, DaemonRepository $daemonRepository): void + public function boot(DaemonSystemRepository $daemonSystemRepository, NodeUpdateService $nodeUpdateService): void { - $this->daemonConfigurationRepository = $daemonConfigurationRepository; + $this->daemonSystemRepository = $daemonSystemRepository; $this->nodeUpdateService = $nodeUpdateService; - $this->daemonRepository = $daemonRepository; } /** @@ -653,7 +649,7 @@ class EditNode extends EditRecord $logLines = $get('log_lines') ?? 200; try { - $response = $this->daemonRepository->setNode($node)->getDiagnostics($logLines, $includeEndpoints, $includeLogs); + $response = $this->daemonSystemRepository->setNode($node)->getDiagnostics($logLines, $includeEndpoints, $includeLogs); $set('pulled', true); $set('log', $response->body()); @@ -691,7 +687,7 @@ class EditNode extends EditRecord if ($response->failed()) { Notification::make() ->title(trans('admin/node.diagnostics.upload_failed')) - ->body($response->status()) + ->body(fn () => $response->status() . ' - ' . $response->body()) ->danger() ->send(); @@ -752,7 +748,8 @@ class EditNode extends EditRecord ->hiddenLabel() ->columnSpanFull() ->rows(35) - ->visible(fn (Get $get) => ($get('pulled') ?? false) || ($get('uploaded') ?? false)), ]), + ->visible(fn (Get $get) => ($get('pulled') ?? false) || ($get('uploaded') ?? false)), + ]), ]), ]); } @@ -810,7 +807,7 @@ class EditNode extends EditRecord try { if ($changed) { - $this->daemonConfigurationRepository->setNode($node)->update($node); + $this->daemonSystemRepository->setNode($node)->update($node); } parent::getSavedNotification()?->send(); } catch (ConnectionException) { diff --git a/app/Models/Node.php b/app/Models/Node.php index 52b02ac11..e4f127d84 100644 --- a/app/Models/Node.php +++ b/app/Models/Node.php @@ -4,7 +4,7 @@ namespace App\Models; use App\Contracts\Validatable; use App\Exceptions\Service\HasActiveServersException; -use App\Repositories\Daemon\DaemonConfigurationRepository; +use App\Repositories\Daemon\DaemonSystemRepository; use App\Traits\HasValidation; use Carbon\Carbon; use Exception; @@ -316,7 +316,7 @@ class Node extends Model implements Validatable { return once(function () { try { - return (new DaemonConfigurationRepository()) + return (new DaemonSystemRepository()) ->setNode($this) ->getSystemInformation(); } catch (Exception $exception) { diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 74d5f664c..bdab4e90a 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -22,8 +22,6 @@ use App\Models\Server; use App\Models\Task; use App\Models\User; use App\Models\UserSSHKey; -use App\Repositories\Daemon\DaemonRepository; -use App\Repositories\Daemon\HttpDaemonRepository; use App\Services\Helpers\SoftwareVersionService; use Dedoc\Scramble\Scramble; use Dedoc\Scramble\Support\Generator\OpenApi; @@ -122,15 +120,4 @@ class AppServiceProvider extends ServiceProvider AboutCommand::add('Environment', 'Installation Directory', base_path()); } - - /** - * Register application service providers. - */ - public function register(): void - { - Scramble::ignoreDefaultRoutes(); - - // Bind the daemon repository abstract to a concrete implementation so it is instantiable. - $this->app->bind(DaemonRepository::class, HttpDaemonRepository::class); - } } diff --git a/app/Repositories/Daemon/DaemonRepository.php b/app/Repositories/Daemon/DaemonRepository.php index 102a01e38..f8b85e0d1 100644 --- a/app/Repositories/Daemon/DaemonRepository.php +++ b/app/Repositories/Daemon/DaemonRepository.php @@ -72,23 +72,4 @@ abstract class DaemonRepository return true; } - - /** - * Retrieve diagnostics from the daemon for the current node. - * - * - * @throws ConnectionException - */ - public function getDiagnostics(int $lines, bool $includeEndpoints, bool $includeLogs): Response - { - Assert::isInstanceOf($this->node, Node::class); - - return $this->getHttpClient() - ->timeout(5) - ->get('/api/diagnostics', [ - 'log_lines' => $lines, - 'include_endpoints' => $includeEndpoints ? 'true' : 'false', - 'include_logs' => $includeLogs ? 'true' : 'false', - ]); - } } diff --git a/app/Repositories/Daemon/DaemonConfigurationRepository.php b/app/Repositories/Daemon/DaemonSystemRepository.php similarity index 69% rename from app/Repositories/Daemon/DaemonConfigurationRepository.php rename to app/Repositories/Daemon/DaemonSystemRepository.php index 916e7d459..71d88a138 100644 --- a/app/Repositories/Daemon/DaemonConfigurationRepository.php +++ b/app/Repositories/Daemon/DaemonSystemRepository.php @@ -6,7 +6,7 @@ use App\Models\Node; use Illuminate\Http\Client\ConnectionException; use Illuminate\Http\Client\Response; -class DaemonConfigurationRepository extends DaemonRepository +class DaemonSystemRepository extends DaemonRepository { /** * Returns system information from the daemon instance. @@ -30,6 +30,23 @@ class DaemonConfigurationRepository extends DaemonRepository })->json(); } + /** + * 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', + ]); + } + /** * 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 diff --git a/app/Repositories/Daemon/HttpDaemonRepository.php b/app/Repositories/Daemon/HttpDaemonRepository.php deleted file mode 100644 index ac758a737..000000000 --- a/app/Repositories/Daemon/HttpDaemonRepository.php +++ /dev/null @@ -1,8 +0,0 @@ -