coolify/app/Livewire/Security/PrivateKey/Show.php

59 lines
2.0 KiB
PHP
Raw Normal View History

2023-05-03 12:38:57 +02:00
<?php
2024-01-07 16:23:41 +01:00
namespace App\Livewire\Security\PrivateKey;
2023-05-03 12:38:57 +02:00
use App\Models\PrivateKey;
use Livewire\Component;
2024-01-07 16:23:41 +01:00
class Show extends Component
2023-05-03 12:38:57 +02:00
{
2023-05-03 14:24:18 +02:00
public PrivateKey $private_key;
public $public_key;
2023-05-03 14:24:18 +02:00
protected $rules = [
'private_key.name' => 'required|string',
'private_key.description' => 'nullable|string',
2023-06-19 10:58:00 +02:00
'private_key.private_key' => 'required|string',
'private_key.is_git_related' => 'nullable|boolean'
2023-05-03 14:24:18 +02:00
];
2023-06-16 12:35:40 +02:00
protected $validationAttributes = [
'private_key.name' => 'name',
'private_key.description' => 'description',
'private_key.private_key' => 'private key'
];
public function mount()
{
try {
2024-01-07 16:23:41 +01:00
$this->private_key = PrivateKey::ownedByCurrentTeam(['name', 'description', 'private_key', 'is_git_related'])->whereUuid(request()->private_key_uuid)->firstOrFail();
$this->public_key = $this->private_key->publicKey();
}catch(\Throwable $e) {
return handleError($e, $this);
}
}
2023-05-04 15:45:53 +02:00
public function delete()
2023-05-03 12:38:57 +02:00
{
2023-06-16 13:13:09 +02:00
try {
2023-06-19 09:44:39 +02:00
if ($this->private_key->isEmpty()) {
$this->private_key->delete();
2023-08-22 17:44:49 +02:00
currentTeam()->privateKeys = PrivateKey::where('team_id', currentTeam()->id)->get();
2023-12-27 16:45:01 +01:00
return redirect()->route('security.private-key.index');
2023-06-19 09:44:39 +02:00
}
2023-12-07 19:06:32 +01:00
$this->dispatch('error', 'This private key is in use and cannot be deleted. Please delete all servers, applications, and GitHub/GitLab apps that use this private key before deleting it.');
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-06-16 13:13:09 +02:00
}
2023-05-03 12:38:57 +02:00
}
2023-05-03 12:38:57 +02:00
public function changePrivateKey()
{
try {
2023-08-22 17:44:49 +02:00
$this->private_key->private_key = formatPrivateKey($this->private_key->private_key);
2023-05-03 14:24:18 +02:00
$this->private_key->save();
2023-08-16 17:18:50 +02:00
refresh_server_connection($this->private_key);
2024-03-21 12:44:32 +01:00
$this->dispatch('success', 'Private key updated.');
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-05-03 12:38:57 +02:00
}
}
}