Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

Feat: SSH Key cleanup job

peaklabs-dev95070ab48d37
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index b960a4a8bd..d28a399b9b 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 0000000000..05e3a8837e
--- /dev/null
+++ b/app/Jobs/CleanupSshKeysJob.php
@@ -0,0 +1,26 @@
+<?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)
+ ->whereDoesntHave('gitSources')
+ ->whereDoesntHave('servers')
+ ->delete();
+ }
+}
\ No newline at end of file