diff --git a/app/Http/Livewire/PrivateKey/Change.php b/app/Http/Livewire/PrivateKey/Change.php new file mode 100644 index 000000000..bede7aca4 --- /dev/null +++ b/app/Http/Livewire/PrivateKey/Change.php @@ -0,0 +1,39 @@ +delete(); + session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get(); + redirect()->route('dashboard'); + } + public function changePrivateKey() + { + try { + $this->private_key_value = trim($this->private_key_value); + if (!str_ends_with($this->private_key_value, "\n")) { + $this->private_key_value .= "\n"; + } + PrivateKey::where('uuid', $this->private_key_uuid)->update([ + 'name' => $this->private_key_name, + 'description' => $this->private_key_description, + 'private_key' => $this->private_key_value, + ]); + session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get(); + } catch (\Exception $e) { + $this->addError('private_key_value', $e->getMessage()); + } + } +} diff --git a/app/Http/Livewire/PrivateKey/Create.php b/app/Http/Livewire/PrivateKey/Create.php new file mode 100644 index 000000000..e21f02309 --- /dev/null +++ b/app/Http/Livewire/PrivateKey/Create.php @@ -0,0 +1,27 @@ +private_key_value = trim($this->private_key_value); + if (!str_ends_with($this->private_key_value, "\n")) { + $this->private_key_value .= "\n"; + } + PrivateKey::create([ + 'name' => $this->private_key_name, + 'description' => $this->private_key_description, + 'private_key' => $this->private_key_value, + 'team_id' => session('currentTeam')->id + ]); + session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get(); + } +} diff --git a/app/Http/Livewire/Server/New/ByIp.php b/app/Http/Livewire/Server/New/ByIp.php index e5fdafa98..baf638a2f 100644 --- a/app/Http/Livewire/Server/New/ByIp.php +++ b/app/Http/Livewire/Server/New/ByIp.php @@ -15,7 +15,7 @@ class ByIp extends Component public $new_private_key_value; public string $name; - public string $description; + public string|null $description = null; public string $ip; public string $user = 'root'; public int $port = 22; @@ -29,20 +29,6 @@ public function setPrivateKey($private_key_id) { $this->private_key_id = $private_key_id; } - public function addPrivateKey() - { - $this->new_private_key_value = trim($this->new_private_key_value); - if (!str_ends_with($this->new_private_key_value, "\n")) { - $this->new_private_key_value .= "\n"; - } - PrivateKey::create([ - 'name' => $this->new_private_key_name, - 'description' => $this->new_private_key_description, - 'private_key' => $this->new_private_key_value, - 'team_id' => session('currentTeam')->id - ]); - session('currentTeam')->privateKeys = $this->private_keys = PrivateKey::where('team_id', session('currentTeam')->id)->get(); - } public function submit() { if (!$this->private_key_id) { diff --git a/app/Http/Livewire/Server/PrivateKey.php b/app/Http/Livewire/Server/PrivateKey.php new file mode 100644 index 000000000..6e57f4ad2 --- /dev/null +++ b/app/Http/Livewire/Server/PrivateKey.php @@ -0,0 +1,26 @@ +parameters['server_uuid'])->update([ + 'private_key_id' => $private_key_id + ]); + return redirect()->route('server.show', $this->parameters['server_uuid']); + } + public function mount() + { + $this->parameters = Route::current()->parameters(); + $this->private_keys = ModelsPrivateKey::where('team_id', session('currentTeam')->id)->get(); + } +} diff --git a/app/Models/Team.php b/app/Models/Team.php index 4c9938c5b..aaadcbb5a 100644 --- a/app/Models/Team.php +++ b/app/Models/Team.php @@ -24,4 +24,8 @@ public function applications() { return $this->hasManyThrough(Application::class, Project::class); } + public function privateKeys() + { + return $this->hasMany(PrivateKey::class); + } } diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 22a1b8310..c13cfd80a 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -14,6 +14,12 @@
No destinations found.
+ @endforelse +No servers found.
@endforelse diff --git a/resources/views/livewire/private-key/change.blade.php b/resources/views/livewire/private-key/change.blade.php new file mode 100644 index 000000000..9513c6c85 --- /dev/null +++ b/resources/views/livewire/private-key/change.blade.php @@ -0,0 +1,14 @@ +No private keys found
+ @endforelse +{{ $server->privateKey->name }}