change/modify/delete/add private keys
This commit is contained in:
parent
906b4ce158
commit
612460ca16
39
app/Http/Livewire/PrivateKey/Change.php
Normal file
39
app/Http/Livewire/PrivateKey/Change.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
app/Http/Livewire/PrivateKey/Create.php
Normal file
27
app/Http/Livewire/PrivateKey/Create.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -15,7 +15,7 @@ class ByIp extends Component
|
|||||||
public $new_private_key_value;
|
public $new_private_key_value;
|
||||||
|
|
||||||
public string $name;
|
public string $name;
|
||||||
public string $description;
|
public string|null $description = null;
|
||||||
public string $ip;
|
public string $ip;
|
||||||
public string $user = 'root';
|
public string $user = 'root';
|
||||||
public int $port = 22;
|
public int $port = 22;
|
||||||
@ -29,20 +29,6 @@ public function setPrivateKey($private_key_id)
|
|||||||
{
|
{
|
||||||
$this->private_key_id = $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()
|
public function submit()
|
||||||
{
|
{
|
||||||
if (!$this->private_key_id) {
|
if (!$this->private_key_id) {
|
||||||
|
26
app/Http/Livewire/Server/PrivateKey.php
Normal file
26
app/Http/Livewire/Server/PrivateKey.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -24,4 +24,8 @@ public function applications()
|
|||||||
{
|
{
|
||||||
return $this->hasManyThrough(Application::class, Project::class);
|
return $this->hasManyThrough(Application::class, Project::class);
|
||||||
}
|
}
|
||||||
|
public function privateKeys()
|
||||||
|
{
|
||||||
|
return $this->hasMany(PrivateKey::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,12 @@
|
|||||||
<h1>Destinations <a href="{{ route('destination.new') }}"><button>New</button></a></h1>
|
<h1>Destinations <a href="{{ route('destination.new') }}"><button>New</button></a></h1>
|
||||||
@forelse ($destinations as $destination)
|
@forelse ($destinations as $destination)
|
||||||
<a href="{{ route('destination.show', [$destination->uuid]) }}">{{ data_get($destination, 'name') }}</a>
|
<a href="{{ route('destination.show', [$destination->uuid]) }}">{{ data_get($destination, 'name') }}</a>
|
||||||
|
@empty
|
||||||
|
<p>No destinations found.</p>
|
||||||
|
@endforelse
|
||||||
|
<h1>Private Keys <a href="{{ route('private-key.new') }}"><button>New</button></a></h1>
|
||||||
|
@forelse ($private_keys as $private_key)
|
||||||
|
<a href="{{ route('private-key.show', [$private_key->uuid]) }}">{{ data_get($private_key, 'name') }}</a>
|
||||||
@empty
|
@empty
|
||||||
<p>No servers found.</p>
|
<p>No servers found.</p>
|
||||||
@endforelse
|
@endforelse
|
||||||
|
14
resources/views/livewire/private-key/change.blade.php
Normal file
14
resources/views/livewire/private-key/change.blade.php
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<div>
|
||||||
|
<form class="flex flex-col gap-2 w-96" wire:submit.prevent='changePrivateKey'>
|
||||||
|
<x-form-input id="private_key_name" label="Name" required />
|
||||||
|
<x-form-input id="private_key_description" label="Longer Description" />
|
||||||
|
<x-form-input type="textarea" id="private_key_value" label="Private Key" required />
|
||||||
|
<button type="submit">
|
||||||
|
Submit
|
||||||
|
</button>
|
||||||
|
<button class="bg-red-500" @confirm.window="$wire.delete('{{ $private_key_uuid }}')"
|
||||||
|
x-on:click="toggleConfirmModal('Are you sure you would like to delete this application?')">
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
10
resources/views/livewire/private-key/create.blade.php
Normal file
10
resources/views/livewire/private-key/create.blade.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<div>
|
||||||
|
<form class="flex flex-col gap-2 w-96" wire:submit.prevent='createPrivateKey'>
|
||||||
|
<x-form-input id="private_key_name" label="Name" required />
|
||||||
|
<x-form-input id="private_key_description" label="Longer Description" />
|
||||||
|
<x-form-input type="textarea" id="private_key_value" label="Private Key" required />
|
||||||
|
<button type="submit">
|
||||||
|
Submit
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
@ -21,7 +21,8 @@
|
|||||||
<button class="w-16 mt-4" type="submit">
|
<button class="w-16 mt-4" type="submit">
|
||||||
Submit
|
Submit
|
||||||
</button>
|
</button>
|
||||||
<button wire:click.prevent='checkServer'>Check Server</button>
|
<button wire:loading.class="text-black bg-green-500" wire:loading.attr="disabled"
|
||||||
|
wire:click.prevent='checkServer'>Check Server</button>
|
||||||
<button class="bg-red-500" @confirm.window="$wire.delete()"
|
<button class="bg-red-500" @confirm.window="$wire.delete()"
|
||||||
x-on:click="toggleConfirmModal('Are you sure you would like to delete this application?')">
|
x-on:click="toggleConfirmModal('Are you sure you would like to delete this application?')">
|
||||||
Delete</button>
|
Delete</button>
|
||||||
|
@ -20,14 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h2>Add a new One</h2>
|
<h2>Add a new One</h2>
|
||||||
<form class="flex flex-col gap-2" wire:submit.prevent='addPrivateKey'>
|
<livewire:private-key.create />
|
||||||
<x-form-input id="new_private_key_name" label="Name" required />
|
|
||||||
<x-form-input id="new_private_key_description" label="Longer Description" />
|
|
||||||
<x-form-input type="textarea" id="new_private_key_value" label="Private Key" required />
|
|
||||||
<button type="submit">
|
|
||||||
Submit
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
7
resources/views/livewire/server/private-key.blade.php
Normal file
7
resources/views/livewire/server/private-key.blade.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<div>
|
||||||
|
@forelse ($private_keys as $private_key)
|
||||||
|
<button wire:click='setPrivateKey({{ $private_key->id }})'>{{ $private_key->name }}</button>
|
||||||
|
@empty
|
||||||
|
<p>No private keys found</p>
|
||||||
|
@endforelse
|
||||||
|
</div>
|
4
resources/views/private-key/new.blade.php
Normal file
4
resources/views/private-key/new.blade.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<x-layout>
|
||||||
|
<h1>New Private Key</h1>
|
||||||
|
<livewire:private-key.new.key />
|
||||||
|
</x-layout>
|
4
resources/views/private-key/show.blade.php
Normal file
4
resources/views/private-key/show.blade.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<x-layout>
|
||||||
|
<h1>Private Key</h1>
|
||||||
|
<livewire:private-key.change :private_key_value="$private_key->private_key" :private_key_description="$private_key->description" :private_key_name="$private_key->name" :private_key_uuid="$private_key->uuid" />
|
||||||
|
</x-layout>
|
4
resources/views/server/private-key.blade.php
Normal file
4
resources/views/server/private-key.blade.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<x-layout>
|
||||||
|
<h1>Select a private Key</h1>
|
||||||
|
<livewire:server.private-key />
|
||||||
|
</x-layout>
|
@ -1,6 +1,10 @@
|
|||||||
<x-layout>
|
<x-layout>
|
||||||
<h1>Server</h1>
|
<h1>Server</h1>
|
||||||
<livewire:server.form :server_id="$server->id" />
|
<livewire:server.form :server_id="$server->id" />
|
||||||
|
<h2>Private Key <a
|
||||||
|
href="{{ route('server.private-key', ['server_uuid' => $server->uuid]) }}"><button>Change</button></a>
|
||||||
|
</h2>
|
||||||
|
<p>{{ $server->privateKey->name }}</p>
|
||||||
<h2>Destinations <a href="{{ route('destination.new', ['server_id' => $server->id]) }}"><button>New</button></a></h2>
|
<h2>Destinations <a href="{{ route('destination.new', ['server_id' => $server->id]) }}"><button>New</button></a></h2>
|
||||||
@if ($server->standaloneDockers)
|
@if ($server->standaloneDockers)
|
||||||
@foreach ($server->standaloneDockers as $docker)
|
@foreach ($server->standaloneDockers as $docker)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
use App\Http\Controllers\HomeController;
|
use App\Http\Controllers\HomeController;
|
||||||
use App\Http\Controllers\ProjectController;
|
use App\Http\Controllers\ProjectController;
|
||||||
use App\Models\InstanceSettings;
|
use App\Models\InstanceSettings;
|
||||||
|
use App\Models\PrivateKey;
|
||||||
use App\Models\StandaloneDocker;
|
use App\Models\StandaloneDocker;
|
||||||
use App\Models\SwarmDocker;
|
use App\Models\SwarmDocker;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
@ -28,10 +29,13 @@
|
|||||||
$destinations = $servers->map(function ($server) {
|
$destinations = $servers->map(function ($server) {
|
||||||
return $server->standaloneDockers->merge($server->swarmDockers);
|
return $server->standaloneDockers->merge($server->swarmDockers);
|
||||||
})->flatten();
|
})->flatten();
|
||||||
|
$private_keys = session('currentTeam')->load(['privateKeys'])->privateKeys;
|
||||||
|
|
||||||
return view('dashboard', [
|
return view('dashboard', [
|
||||||
'servers' => $servers->sortBy('name'),
|
'servers' => $servers->sortBy('name'),
|
||||||
'projects' => $projects->sortBy('name'),
|
'projects' => $projects->sortBy('name'),
|
||||||
'destinations' => $destinations->sortBy('name'),
|
'destinations' => $destinations->sortBy('name'),
|
||||||
|
'private_keys' => $private_keys->sortBy('name'),
|
||||||
]);
|
]);
|
||||||
})->name('dashboard');
|
})->name('dashboard');
|
||||||
|
|
||||||
@ -60,6 +64,15 @@
|
|||||||
})->name('demo');
|
})->name('demo');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::middleware(['auth'])->group(function () {
|
||||||
|
Route::get('/private-key/new', fn () => view('private-key.new'))->name('private-key.new');
|
||||||
|
Route::get('/private-key/{private_key_uuid}', function () {
|
||||||
|
$private_key = PrivateKey::where('uuid', request()->private_key_uuid)->first();
|
||||||
|
return view('private-key.show', [
|
||||||
|
'private_key' => $private_key,
|
||||||
|
]);
|
||||||
|
})->name('private-key.show');
|
||||||
|
});
|
||||||
Route::middleware(['auth'])->group(function () {
|
Route::middleware(['auth'])->group(function () {
|
||||||
Route::get('/server/new', fn () => view('server.new'))->name('server.new');
|
Route::get('/server/new', fn () => view('server.new'))->name('server.new');
|
||||||
Route::get('/server/{server_uuid}', function () {
|
Route::get('/server/{server_uuid}', function () {
|
||||||
@ -71,6 +84,9 @@
|
|||||||
'server' => $server,
|
'server' => $server,
|
||||||
]);
|
]);
|
||||||
})->name('server.show');
|
})->name('server.show');
|
||||||
|
Route::get('/server/{server_uuid}/private-key', function () {
|
||||||
|
return view('server.private-key');
|
||||||
|
})->name('server.private-key');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::middleware(['auth'])->group(function () {
|
Route::middleware(['auth'])->group(function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user