Merge pull request #3509 from coollabsio/delete-unused-ssh-keys
Feat: Delete unused ssh keys button
This commit is contained in:
@@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use App\Models\PrivateKey;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
class CleanupSshKeysJob implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
public function handle()
|
|
||||||
{
|
|
||||||
$oneWeekAgo = Carbon::now()->subWeek();
|
|
||||||
|
|
||||||
PrivateKey::where('created_at', '<', $oneWeekAgo)
|
|
||||||
->get()
|
|
||||||
->each(function ($privateKey) {
|
|
||||||
$privateKey->safeDelete();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
24
app/Livewire/Security/PrivateKey/Index.php
Normal file
24
app/Livewire/Security/PrivateKey/Index.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Livewire\Security\PrivateKey;
|
||||||
|
|
||||||
|
use Livewire\Component;
|
||||||
|
use App\Models\PrivateKey;
|
||||||
|
|
||||||
|
class Index extends Component
|
||||||
|
{
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
$privateKeys = PrivateKey::ownedByCurrentTeam(['name', 'uuid', 'is_git_related', 'description'])->get();
|
||||||
|
|
||||||
|
return view('livewire.security.private-key.index', [
|
||||||
|
'privateKeys' => $privateKeys,
|
||||||
|
])->layout('components.layout');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cleanupUnusedKeys()
|
||||||
|
{
|
||||||
|
PrivateKey::cleanupUnusedKeys();
|
||||||
|
$this->dispatch('success', 'Unused keys have been cleaned up.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -226,4 +226,11 @@ class PrivateKey extends BaseModel
|
|||||||
|
|
||||||
return $query->exists();
|
return $query->exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function cleanupUnusedKeys()
|
||||||
|
{
|
||||||
|
self::all()->each(function ($privateKey) {
|
||||||
|
$privateKey->safeDelete();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
<x-layout>
|
<div>
|
||||||
<x-slot:title>
|
|
||||||
Private Keys | Coolify
|
|
||||||
</x-slot>
|
|
||||||
<x-security.navbar />
|
<x-security.navbar />
|
||||||
|
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<h2 class="pb-4">Private Keys</h2>
|
<h2 class="pb-4">Private Keys</h2>
|
||||||
<x-modal-input buttonTitle="+ Add" title="New Private Key">
|
<x-modal-input buttonTitle="+ Add" title="New Private Key">
|
||||||
<livewire:security.private-key.create />
|
<livewire:security.private-key.create />
|
||||||
</x-modal-input>
|
</x-modal-input>
|
||||||
|
<x-modal-confirmation
|
||||||
|
title="Confirm unused SSH Key Deletion?"
|
||||||
|
buttonTitle="Delete unused SSH Keys"
|
||||||
|
isErrorButton
|
||||||
|
submitAction="cleanupUnusedKeys"
|
||||||
|
:actions="['All unused SSH keys (marked with unused) are permanently deleted.']"
|
||||||
|
:confirmWithText="false"
|
||||||
|
:confirmWithPassword="false"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid gap-2 lg:grid-cols-2">
|
<div class="grid gap-2 lg:grid-cols-2">
|
||||||
@forelse ($privateKeys as $key)
|
@forelse ($privateKeys as $key)
|
||||||
@@ -19,11 +26,15 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="box-description">
|
<div class="box-description">
|
||||||
{{ $key->description }}
|
{{ $key->description }}
|
||||||
|
@if (!$key->isInUse())
|
||||||
|
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-yellow-400 text-black">Unused</span>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
@empty
|
@empty
|
||||||
<div>No private keys found.</div>
|
<div>No private keys found.</div>
|
||||||
@endforelse
|
@endforelse
|
||||||
</div>
|
</div>
|
||||||
</x-layout>
|
</div>
|
||||||
@@ -32,6 +32,7 @@ use App\Livewire\Project\Shared\Logs;
|
|||||||
use App\Livewire\Project\Shared\ScheduledTask\Show as ScheduledTaskShow;
|
use App\Livewire\Project\Shared\ScheduledTask\Show as ScheduledTaskShow;
|
||||||
use App\Livewire\Project\Show as ProjectShow;
|
use App\Livewire\Project\Show as ProjectShow;
|
||||||
use App\Livewire\Security\ApiTokens;
|
use App\Livewire\Security\ApiTokens;
|
||||||
|
use App\Livewire\Security\PrivateKey\Index as SecurityPrivateKeyIndex;
|
||||||
use App\Livewire\Security\PrivateKey\Show as SecurityPrivateKeyShow;
|
use App\Livewire\Security\PrivateKey\Show as SecurityPrivateKeyShow;
|
||||||
use App\Livewire\Server\Destination\Show as DestinationShow;
|
use App\Livewire\Server\Destination\Show as DestinationShow;
|
||||||
use App\Livewire\Server\Index as ServerIndex;
|
use App\Livewire\Server\Index as ServerIndex;
|
||||||
@@ -215,9 +216,7 @@ Route::middleware(['auth', 'verified'])->group(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Route::get('/security', fn () => view('security.index'))->name('security.index');
|
// Route::get('/security', fn () => view('security.index'))->name('security.index');
|
||||||
Route::get('/security/private-key', fn () => view('security.private-key.index', [
|
Route::get('/security/private-key', SecurityPrivateKeyIndex::class)->name('security.private-key.index');
|
||||||
'privateKeys' => PrivateKey::ownedByCurrentTeam(['name', 'uuid', 'is_git_related', 'description'])->get(),
|
|
||||||
]))->name('security.private-key.index');
|
|
||||||
// Route::get('/security/private-key/new', SecurityPrivateKeyCreate::class)->name('security.private-key.create');
|
// Route::get('/security/private-key/new', SecurityPrivateKeyCreate::class)->name('security.private-key.create');
|
||||||
Route::get('/security/private-key/{private_key_uuid}', SecurityPrivateKeyShow::class)->name('security.private-key.show');
|
Route::get('/security/private-key/{private_key_uuid}', SecurityPrivateKeyShow::class)->name('security.private-key.show');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user