change/modify/delete/add private keys

This commit is contained in:
Andras Bacsai
2023-05-03 12:38:57 +02:00
parent 906b4ce158
commit 612460ca16
16 changed files with 169 additions and 24 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Http\Livewire\PrivateKey;
use App\Models\PrivateKey;
use Livewire\Component;
class Change extends Component
{
public $private_keys;
public $private_key_uuid;
public $private_key_value;
public $private_key_name;
public $private_key_description;
public function delete($private_key_uuid)
{
PrivateKey::where('uuid', $private_key_uuid)->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());
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Livewire\PrivateKey;
use App\Models\PrivateKey;
use Livewire\Component;
class Create extends Component
{
public $private_key_value;
public $private_key_name;
public $private_key_description;
public function createPrivateKey()
{
$this->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();
}
}

View File

@@ -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 @@ class ByIp extends Component
{
$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) {

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Livewire\Server;
use App\Models\PrivateKey as ModelsPrivateKey;
use App\Models\Server;
use Illuminate\Support\Facades\Route;
use Livewire\Component;
class PrivateKey extends Component
{
public $private_keys;
public $parameters;
public function setPrivateKey($private_key_id)
{
Server::where('uuid', $this->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();
}
}

View File

@@ -24,4 +24,8 @@ class Team extends BaseModel
{
return $this->hasManyThrough(Application::class, Project::class);
}
public function privateKeys()
{
return $this->hasMany(PrivateKey::class);
}
}