From 95070ab48d371c75effac2636b13e1a21bb220fc Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:57:06 +0200 Subject: [PATCH] Feat: SSH Key cleanup job --- app/Console/Kernel.php | 5 +++++ app/Jobs/CleanupSshKeysJob.php | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 app/Jobs/CleanupSshKeysJob.php diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index b960a4a8b..d28a399b9 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -7,6 +7,7 @@ use App\Jobs\CleanupInstanceStuffsJob; use App\Jobs\CleanupStaleMultiplexedConnections; use App\Jobs\DatabaseBackupJob; use App\Jobs\DockerCleanupJob; +use App\Jobs\CleanupSshKeysJob; use App\Jobs\PullHelperImageJob; use App\Jobs\PullSentinelImageJob; use App\Jobs\PullTemplatesFromCDN; @@ -43,6 +44,8 @@ class Kernel extends ConsoleKernel $schedule->command('uploads:clear')->everyTwoMinutes(); $schedule->command('telescope:prune')->daily(); + + $schedule->job(new CleanupSshKeysJob)->weekly()->onOneServer(); } else { // Instance Jobs $schedule->command('horizon:snapshot')->everyFiveMinutes(); @@ -59,6 +62,8 @@ class Kernel extends ConsoleKernel $schedule->command('cleanup:database --yes')->daily(); $schedule->command('uploads:clear')->everyTwoMinutes(); + + $schedule->job(new CleanupSshKeysJob)->weekly()->onOneServer(); } } diff --git a/app/Jobs/CleanupSshKeysJob.php b/app/Jobs/CleanupSshKeysJob.php new file mode 100644 index 000000000..05e3a8837 --- /dev/null +++ b/app/Jobs/CleanupSshKeysJob.php @@ -0,0 +1,26 @@ +subWeek(); + + PrivateKey::where('created_at', '<', $oneWeekAgo) + ->whereDoesntHave('gitSources') + ->whereDoesntHave('servers') + ->delete(); + } +} \ No newline at end of file