chore: Refactor code to improve SSH key handling and storage

This commit is contained in:
Andras Bacsai
2024-09-29 20:12:30 +02:00
parent 795af8de52
commit cccd05f322
3 changed files with 3 additions and 12 deletions

View File

@@ -19,7 +19,6 @@ class PopulateSshKeysDirectorySeeder extends Seeder
PrivateKey::chunk(100, function ($keys) {
foreach ($keys as $key) {
echo 'Storing key: '.$key->name."\n";
$key->storeInFileSystem();
}
});

View File

@@ -101,19 +101,13 @@ class ProductionSeeder extends Seeder
}
if (! isCloud() && config('coolify.is_windows_docker_desktop') == false) {
echo "Checking localhost key.\n";
$coolify_key_name = '@host.docker.internal';
$ssh_keys_directory = Storage::disk('ssh-keys')->files();
$coolify_key = collect($ssh_keys_directory)->firstWhere(fn ($item) => str($item)->contains($coolify_key_name));
$server = Server::find(0);
$found = $server->privateKey;
if ($found) {
echo 'Private Key found in database.\n';
if ($coolify_key) {
echo "SSH key found for the Coolify host machine (localhost).\n";
}
} else {
if (! $found) {
if ($coolify_key) {
$user = str($coolify_key)->before('@')->after('id.');
$coolify_key = Storage::disk('ssh-keys')->get($coolify_key);