diff --git a/app/Models/PrivateKey.php b/app/Models/PrivateKey.php index f2fa9c9cf..fef464823 100644 --- a/app/Models/PrivateKey.php +++ b/app/Models/PrivateKey.php @@ -144,6 +144,10 @@ class PrivateKey extends BaseModel public static function deleteFromStorage(self $privateKey) { + if ($privateKey->isInUse()) { + throw new \Exception('Cannot delete a private key that is in use.'); + } + $filename = "ssh@{$privateKey->uuid}"; Storage::disk('ssh-keys')->delete($filename); }