Skip to content

Commit

Permalink
Merge pull request #3509 from coollabsio/delete-unused-ssh-keys
Browse files Browse the repository at this point in the history
Feat: Delete unused ssh keys button
  • Loading branch information
andrasbacsai authored Sep 20, 2024
2 parents c0898f0 + dbc7230 commit f9238ce
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 35 deletions.
27 changes: 0 additions & 27 deletions app/Jobs/CleanupSshKeysJob.php

This file was deleted.

24 changes: 24 additions & 0 deletions app/Livewire/Security/PrivateKey/Index.php
Original file line number Diff line number Diff line change
@@ -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.');
}
}
7 changes: 7 additions & 0 deletions app/Models/PrivateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,11 @@ private static function fingerprintExists($fingerprint, $excludeId = null)

return $query->exists();
}

public static function cleanupUnusedKeys()
{
self::all()->each(function ($privateKey) {
$privateKey->safeDelete();
});
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<x-layout>
<x-slot:title>
Private Keys | Coolify
</x-slot>
<div>
<x-security.navbar />

<div class="flex gap-2">
<h2 class="pb-4">Private Keys</h2>
<x-modal-input buttonTitle="+ Add" title="New Private Key">
<livewire:security.private-key.create />
</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 class="grid gap-2 lg:grid-cols-2">
@forelse ($privateKeys as $key)
Expand All @@ -19,11 +26,15 @@
</div>
<div class="box-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>
</a>
@empty
<div>No private keys found.</div>
@endforelse
</div>
</x-layout>
</div>
5 changes: 2 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
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;
Expand Down Expand Up @@ -215,9 +216,7 @@
});

// 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');

Expand Down

0 comments on commit f9238ce

Please sign in to comment.