Merge pull request #3509 from coollabsio/delete-unused-ssh-keys

Feat: Delete unused ssh keys button
This commit is contained in:
Andras Bacsai
2024-09-20 13:00:54 +02:00
committed by GitHub
5 changed files with 49 additions and 35 deletions

View File

@@ -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();
});
}
}

View 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.');
}
}

View File

@@ -226,4 +226,11 @@ class PrivateKey extends BaseModel
return $query->exists();
}
public static function cleanupUnusedKeys()
{
self::all()->each(function ($privateKey) {
$privateKey->safeDelete();
});
}
}