From 175f4b9ae1dbbc4af2aa58e2c4fe8334af4b6354 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:47:02 +0200 Subject: [PATCH] use shared functions when possible --- app/Models/PrivateKey.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Models/PrivateKey.php b/app/Models/PrivateKey.php index 05310e413..1ad12cf36 100644 --- a/app/Models/PrivateKey.php +++ b/app/Models/PrivateKey.php @@ -43,7 +43,7 @@ class PrivateKey extends BaseModel protected static function booted() { static::saving(function ($key) { - $key->private_key = rtrim($key->private_key) . "\n"; + $key->private_key = formatPrivateKey($key->private_key); if (!self::validatePrivateKey($key->private_key)) { throw ValidationException::withMessages([ @@ -101,13 +101,13 @@ class PrivateKey extends BaseModel $instance->rateLimit(10); $name = generate_random_name(); $description = 'Created by Coolify'; - ['private' => $privateKey, 'public' => $publicKey] = generateSSHKey($type === 'ed25519' ? 'ed25519' : 'rsa'); + $keyPair = generateSSHKey($type === 'ed25519' ? 'ed25519' : 'rsa'); return [ 'name' => $name, 'description' => $description, - 'private_key' => $privateKey, - 'public_key' => $publicKey, + 'private_key' => $keyPair['private'], + 'public_key' => $keyPair['public'], ]; } catch (\Throwable $e) { throw new \Exception("Failed to generate new {$type} key: " . $e->getMessage());