chore: Refactor code to improve SSH key handling and storage
This commit is contained in:
@@ -1236,8 +1236,6 @@ function parseLineForSudo(string $command, Server $server): string
|
||||
function get_public_ips()
|
||||
{
|
||||
try {
|
||||
echo "Refreshing public ips!\n";
|
||||
$settings = \App\Models\InstanceSettings::get();
|
||||
[$first, $second] = Process::concurrently(function (Pool $pool) {
|
||||
$pool->path(__DIR__)->command('curl -4s https://ifconfig.io');
|
||||
$pool->path(__DIR__)->command('curl -6s https://ifconfig.io');
|
||||
@@ -1251,7 +1249,7 @@ function get_public_ips()
|
||||
|
||||
return;
|
||||
}
|
||||
$settings->update(['public_ipv4' => $ipv4]);
|
||||
InstanceSettings::get()->update(['public_ipv4' => $ipv4]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo "Error: {$e->getMessage()}\n";
|
||||
@@ -1266,7 +1264,7 @@ function get_public_ips()
|
||||
|
||||
return;
|
||||
}
|
||||
$settings->update(['public_ipv6' => $ipv6]);
|
||||
InstanceSettings::get()->update(['public_ipv6' => $ipv6]);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
echo "Error: {$e->getMessage()}\n";
|
||||
|
@@ -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();
|
||||
}
|
||||
});
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user