use shared functions when possible
This commit is contained in:
		@@ -43,7 +43,7 @@ class PrivateKey extends BaseModel
 | 
				
			|||||||
    protected static function booted()
 | 
					    protected static function booted()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        static::saving(function ($key) {
 | 
					        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)) {
 | 
					            if (!self::validatePrivateKey($key->private_key)) {
 | 
				
			||||||
                throw ValidationException::withMessages([
 | 
					                throw ValidationException::withMessages([
 | 
				
			||||||
@@ -101,13 +101,13 @@ class PrivateKey extends BaseModel
 | 
				
			|||||||
            $instance->rateLimit(10);
 | 
					            $instance->rateLimit(10);
 | 
				
			||||||
            $name = generate_random_name();
 | 
					            $name = generate_random_name();
 | 
				
			||||||
            $description = 'Created by Coolify';
 | 
					            $description = 'Created by Coolify';
 | 
				
			||||||
            ['private' => $privateKey, 'public' => $publicKey] = generateSSHKey($type === 'ed25519' ? 'ed25519' : 'rsa');
 | 
					            $keyPair = generateSSHKey($type === 'ed25519' ? 'ed25519' : 'rsa');
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            return [
 | 
					            return [
 | 
				
			||||||
                'name' => $name,
 | 
					                'name' => $name,
 | 
				
			||||||
                'description' => $description,
 | 
					                'description' => $description,
 | 
				
			||||||
                'private_key' => $privateKey,
 | 
					                'private_key' => $keyPair['private'],
 | 
				
			||||||
                'public_key' => $publicKey,
 | 
					                'public_key' => $keyPair['public'],
 | 
				
			||||||
            ];
 | 
					            ];
 | 
				
			||||||
        } catch (\Throwable $e) {
 | 
					        } catch (\Throwable $e) {
 | 
				
			||||||
            throw new \Exception("Failed to generate new {$type} key: " . $e->getMessage());
 | 
					            throw new \Exception("Failed to generate new {$type} key: " . $e->getMessage());
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user