Fix: Private key with ID 2 on dev
This commit is contained in:
@@ -36,18 +36,19 @@ class Show extends Component
|
||||
public function loadPublicKey()
|
||||
{
|
||||
$this->public_key = $this->private_key->getPublicKey();
|
||||
if ($this->public_key === 'Error loading private key') {
|
||||
$this->dispatch('error', 'Failed to load public key. The private key may be invalid.');
|
||||
}
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
try {
|
||||
if ($this->private_key->isEmpty()) {
|
||||
$this->private_key->delete();
|
||||
currentTeam()->privateKeys = PrivateKey::where('team_id', currentTeam()->id)->get();
|
||||
|
||||
return redirect()->route('security.private-key.index');
|
||||
}
|
||||
$this->dispatch('error', 'This private key is in use and cannot be deleted. Please delete all servers, applications, and GitHub/GitLab apps that use this private key before deleting it.');
|
||||
$this->private_key->safeDelete();
|
||||
currentTeam()->privateKeys = PrivateKey::where('team_id', currentTeam()->id)->get();
|
||||
return redirect()->route('security.private-key.index');
|
||||
} catch (\Exception $e) {
|
||||
$this->dispatch('error', $e->getMessage());
|
||||
} catch (\Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
@@ -56,8 +57,9 @@ class Show extends Component
|
||||
public function changePrivateKey()
|
||||
{
|
||||
try {
|
||||
$this->private_key->private_key = formatPrivateKey($this->private_key->private_key);
|
||||
$this->private_key->save();
|
||||
$this->private_key->updatePrivateKey([
|
||||
'private_key' => formatPrivateKey($this->private_key->private_key)
|
||||
]);
|
||||
refresh_server_connection($this->private_key);
|
||||
$this->dispatch('success', 'Private key updated.');
|
||||
} catch (\Throwable $e) {
|
||||
|
@@ -178,4 +178,21 @@ class PrivateKey extends BaseModel
|
||||
&& $this->githubApps()->count() === 0
|
||||
&& $this->gitlabApps()->count() === 0;
|
||||
}
|
||||
|
||||
public function isInUse()
|
||||
{
|
||||
return $this->servers()->exists()
|
||||
|| $this->applications()->exists()
|
||||
|| $this->githubApps()->exists()
|
||||
|| $this->gitlabApps()->exists();
|
||||
}
|
||||
|
||||
public function safeDelete()
|
||||
{
|
||||
if ($this->isInUse()) {
|
||||
throw new \Exception('This private key is in use and cannot be deleted.');
|
||||
}
|
||||
|
||||
$this->delete();
|
||||
}
|
||||
}
|
||||
|
@@ -20,19 +20,5 @@ class GitlabAppSeeder extends Seeder
|
||||
'is_public' => true,
|
||||
'team_id' => 0,
|
||||
]);
|
||||
GitlabApp::create([
|
||||
'id' => 2,
|
||||
'name' => 'coolify-laravel-development-private-gitlab',
|
||||
'api_url' => 'https://gitlab.com/api/v4',
|
||||
'html_url' => 'https://gitlab.com',
|
||||
'app_id' => 1234,
|
||||
'app_secret' => '1234',
|
||||
'oauth_id' => 1234,
|
||||
'deploy_key_id' => '1234',
|
||||
'public_key' => 'dfjasiourj',
|
||||
'webhook_token' => '4u3928u4y392',
|
||||
'private_key_id' => 2,
|
||||
'team_id' => 0,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user