chore: Refactor code to improve SSH key handling and storage
This commit is contained in:
parent
795af8de52
commit
cccd05f322
3 changed files with 3 additions and 12 deletions
|
|
@ -1236,8 +1236,6 @@ function parseLineForSudo(string $command, Server $server): string
|
||||||
function get_public_ips()
|
function get_public_ips()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
echo "Refreshing public ips!\n";
|
|
||||||
$settings = \App\Models\InstanceSettings::get();
|
|
||||||
[$first, $second] = Process::concurrently(function (Pool $pool) {
|
[$first, $second] = Process::concurrently(function (Pool $pool) {
|
||||||
$pool->path(__DIR__)->command('curl -4s https://ifconfig.io');
|
$pool->path(__DIR__)->command('curl -4s https://ifconfig.io');
|
||||||
$pool->path(__DIR__)->command('curl -6s https://ifconfig.io');
|
$pool->path(__DIR__)->command('curl -6s https://ifconfig.io');
|
||||||
|
|
@ -1251,7 +1249,7 @@ function get_public_ips()
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$settings->update(['public_ipv4' => $ipv4]);
|
InstanceSettings::get()->update(['public_ipv4' => $ipv4]);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
echo "Error: {$e->getMessage()}\n";
|
echo "Error: {$e->getMessage()}\n";
|
||||||
|
|
@ -1266,7 +1264,7 @@ function get_public_ips()
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$settings->update(['public_ipv6' => $ipv6]);
|
InstanceSettings::get()->update(['public_ipv6' => $ipv6]);
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
echo "Error: {$e->getMessage()}\n";
|
echo "Error: {$e->getMessage()}\n";
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ public function run()
|
||||||
|
|
||||||
PrivateKey::chunk(100, function ($keys) {
|
PrivateKey::chunk(100, function ($keys) {
|
||||||
foreach ($keys as $key) {
|
foreach ($keys as $key) {
|
||||||
echo 'Storing key: '.$key->name."\n";
|
|
||||||
$key->storeInFileSystem();
|
$key->storeInFileSystem();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -101,19 +101,13 @@ public function run(): void
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isCloud() && config('coolify.is_windows_docker_desktop') == false) {
|
if (! isCloud() && config('coolify.is_windows_docker_desktop') == false) {
|
||||||
echo "Checking localhost key.\n";
|
|
||||||
$coolify_key_name = '@host.docker.internal';
|
$coolify_key_name = '@host.docker.internal';
|
||||||
$ssh_keys_directory = Storage::disk('ssh-keys')->files();
|
$ssh_keys_directory = Storage::disk('ssh-keys')->files();
|
||||||
$coolify_key = collect($ssh_keys_directory)->firstWhere(fn ($item) => str($item)->contains($coolify_key_name));
|
$coolify_key = collect($ssh_keys_directory)->firstWhere(fn ($item) => str($item)->contains($coolify_key_name));
|
||||||
|
|
||||||
$server = Server::find(0);
|
$server = Server::find(0);
|
||||||
$found = $server->privateKey;
|
$found = $server->privateKey;
|
||||||
if ($found) {
|
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 ($coolify_key) {
|
if ($coolify_key) {
|
||||||
$user = str($coolify_key)->before('@')->after('id.');
|
$user = str($coolify_key)->before('@')->after('id.');
|
||||||
$coolify_key = Storage::disk('ssh-keys')->get($coolify_key);
|
$coolify_key = Storage::disk('ssh-keys')->get($coolify_key);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue