diff --git a/app/Jobs/CleanupSshKeysJob.php b/app/Jobs/CleanupSshKeysJob.php deleted file mode 100644 index 485bf99eb..000000000 --- a/app/Jobs/CleanupSshKeysJob.php +++ /dev/null @@ -1,27 +0,0 @@ -subWeek(); - - PrivateKey::where('created_at', '<', $oneWeekAgo) - ->get() - ->each(function ($privateKey) { - $privateKey->safeDelete(); - }); - } -} diff --git a/app/Livewire/Security/PrivateKey/Index.php b/app/Livewire/Security/PrivateKey/Index.php new file mode 100644 index 000000000..0b50ba1d8 --- /dev/null +++ b/app/Livewire/Security/PrivateKey/Index.php @@ -0,0 +1,24 @@ +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.'); + } +} diff --git a/app/Models/PrivateKey.php b/app/Models/PrivateKey.php index 46ca06f5c..48273a9f8 100644 --- a/app/Models/PrivateKey.php +++ b/app/Models/PrivateKey.php @@ -226,4 +226,11 @@ class PrivateKey extends BaseModel return $query->exists(); } + + public static function cleanupUnusedKeys() + { + self::all()->each(function ($privateKey) { + $privateKey->safeDelete(); + }); + } } diff --git a/resources/views/security/private-key/index.blade.php b/resources/views/livewire/security/private-key/index.blade.php similarity index 58% rename from resources/views/security/private-key/index.blade.php rename to resources/views/livewire/security/private-key/index.blade.php index cb1ddf2dc..104bace2b 100644 --- a/resources/views/security/private-key/index.blade.php +++ b/resources/views/livewire/security/private-key/index.blade.php @@ -1,13 +1,20 @@ - - - Private Keys | Coolify - +
+

Private Keys

+
@forelse ($privateKeys as $key) @@ -19,11 +26,15 @@
{{ $key->description }} + @if (!$key->isInUse()) + Unused + @endif
+
@empty
No private keys found.
@endforelse -
+ \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 8c3fd805d..bd5edc075 100644 --- a/routes/web.php +++ b/routes/web.php @@ -32,6 +32,7 @@ use App\Livewire\Project\Shared\Logs; use App\Livewire\Project\Shared\ScheduledTask\Show as ScheduledTaskShow; use App\Livewire\Project\Show as ProjectShow; use App\Livewire\Security\ApiTokens; +use App\Livewire\Security\PrivateKey\Index as SecurityPrivateKeyIndex; use App\Livewire\Security\PrivateKey\Show as SecurityPrivateKeyShow; use App\Livewire\Server\Destination\Show as DestinationShow; 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/private-key', fn () => view('security.private-key.index', [ - 'privateKeys' => PrivateKey::ownedByCurrentTeam(['name', 'uuid', 'is_git_related', 'description'])->get(), - ]))->name('security.private-key.index'); + Route::get('/security/private-key', SecurityPrivateKeyIndex::class)->name('security.private-key.index'); // 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');