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();
|
||||
}
|
||||
|
||||
public static function cleanupUnusedKeys()
|
||||
{
|
||||
self::all()->each(function ($privateKey) {
|
||||
$privateKey->safeDelete();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user