From 984a7748110db4a7a5e629b7178b19fe318505fb Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Tue, 23 Mar 2021 16:08:17 -0600 Subject: [PATCH] api(app): add NodeInformationController --- .../Api/Application/Nodes/NodeController.php | 2 +- .../Nodes/NodeInformationController.php | 52 +++++++++++++++++++ routes/api-application.php | 1 + 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Api/Application/Nodes/NodeInformationController.php diff --git a/app/Http/Controllers/Api/Application/Nodes/NodeController.php b/app/Http/Controllers/Api/Application/Nodes/NodeController.php index 549ccbf56..54534edaf 100644 --- a/app/Http/Controllers/Api/Application/Nodes/NodeController.php +++ b/app/Http/Controllers/Api/Application/Nodes/NodeController.php @@ -108,7 +108,7 @@ class NodeController extends ApplicationApiController $node = $this->updateService->handle( $node, $request->validated(), - $request->input('reset_secret') === true + $request->input('reset_secret') ); return $this->fractal->item($node) diff --git a/app/Http/Controllers/Api/Application/Nodes/NodeInformationController.php b/app/Http/Controllers/Api/Application/Nodes/NodeInformationController.php new file mode 100644 index 000000000..6b87578c7 --- /dev/null +++ b/app/Http/Controllers/Api/Application/Nodes/NodeInformationController.php @@ -0,0 +1,52 @@ +cache = $cache; + $this->repository = $repository; + } + + /** + * Returns system information from the node. + * + * @return \Illuminate\Http\JsonResponse + * + * @throws \Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException + */ + public function __invoke(Request $request, Node $node) + { + $data = $this->cache + ->tags(['nodes']) + ->remember($node->uuid, Carbon::now()->addSeconds(30), function () use ($node) { + return $this->repository->setNode($node)->getSystemInformation(); + }); + + return new JsonResponse([ + 'version' => $data['version'] ?? null, + 'system' => [ + 'type' => Str::title($data['os'] ?? 'Unknown'), + 'arch' => $data['architecture'] ?? null, + 'release' => $data['kernel_version'] ?? null, + 'cpus' => $data['cpu_count'] ?? null, + ], + ]); + } +} diff --git a/routes/api-application.php b/routes/api-application.php index ee7711400..98f0f0a20 100644 --- a/routes/api-application.php +++ b/routes/api-application.php @@ -117,6 +117,7 @@ Route::group(['prefix' => '/nodes'], function () { Route::get('/deployable', 'Nodes\NodeDeploymentController'); Route::get('/{node}', 'Nodes\NodeController@view')->name('api.application.nodes.view'); Route::get('/{node}/configuration', 'Nodes\NodeConfigurationController'); + Route::get('/{node}/information', 'Nodes\NodeInformationController'); Route::post('/', 'Nodes\NodeController@store');