coolify/app/Http/Livewire/Server/ShowPrivateKey.php

45 lines
1.2 KiB
PHP
Raw Normal View History

2023-05-03 12:38:57 +02:00
<?php
namespace App\Http\Livewire\Server;
use App\Models\Server;
use Livewire\Component;
2023-06-16 13:13:09 +02:00
use Masmerise\Toaster\Toaster;
2023-05-03 12:38:57 +02:00
2023-08-30 11:06:44 +02:00
class ShowPrivateKey extends Component
2023-05-03 12:38:57 +02:00
{
2023-06-15 14:18:49 +02:00
public Server $server;
public $privateKeys;
2023-05-03 12:38:57 +02:00
public $parameters;
2023-06-16 13:13:09 +02:00
public function setPrivateKey($private_key_id)
{
$this->server->update([
'private_key_id' => $private_key_id
]);
2023-08-16 17:18:50 +02:00
refresh_server_connection($this->server->privateKey);
$this->server->refresh();
$this->checkConnection();
}
2023-06-16 13:13:09 +02:00
public function checkConnection()
{
try {
['uptime' => $uptime, 'dockerVersion' => $dockerVersion] = validateServer($this->server);
2023-06-16 13:13:09 +02:00
if ($uptime) {
Toaster::success('Server is reachable with this private key.');
}
if ($dockerVersion) {
Toaster::success('Server is usable for Coolify.');
2023-06-16 13:13:09 +02:00
}
} catch (\Exception $e) {
2023-06-22 21:02:32 +02:00
return general_error_handler(customErrorMessage: "Server is not reachable. Reason: {$e->getMessage()}", that: $this);
2023-06-16 13:13:09 +02:00
}
}
2023-05-03 12:38:57 +02:00
public function mount()
{
$this->parameters = get_route_parameters();
2023-05-03 12:38:57 +02:00
}
}