refactor: Update PrivateKey model to improve code readability and maintainability

This commit is contained in:
Andras Bacsai
2024-09-20 12:27:55 +02:00
parent b81f9114d9
commit 5b00b66f24
3 changed files with 36 additions and 16 deletions

View File

@@ -2,9 +2,10 @@
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;
use App\Models\PrivateKey;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Process;
use Illuminate\Support\Facades\Storage;
class PopulateSshKeysDirectorySeeder extends Seeder
{
@@ -12,11 +13,17 @@ class PopulateSshKeysDirectorySeeder extends Seeder
{
Storage::disk('ssh-keys')->deleteDirectory('');
Storage::disk('ssh-keys')->makeDirectory('');
Storage::disk('ssh-mux')->deleteDirectory('');
Storage::disk('ssh-mux')->makeDirectory('');
PrivateKey::chunk(100, function ($keys) {
foreach ($keys as $key) {
echo 'Storing key: '.$key->name."\n";
$key->storeInFileSystem();
}
});
Process::run('chown -R 9999:9999 '.storage_path('app/ssh/keys'));
Process::run('chown -R 9999:9999 '.storage_path('app/ssh/mux'));
}
}

View File

@@ -123,6 +123,7 @@ class ProductionSeeder extends Seeder
]);
$server->update(['user' => $user]);
echo "SSH key found for the Coolify host machine (localhost).\n";
} else {
PrivateKey::create(
[