Fix: Private key with ID 2 on dev
This commit is contained in:
@@ -36,18 +36,19 @@ class Show extends Component
|
|||||||
public function loadPublicKey()
|
public function loadPublicKey()
|
||||||
{
|
{
|
||||||
$this->public_key = $this->private_key->getPublicKey();
|
$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()
|
public function delete()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($this->private_key->isEmpty()) {
|
$this->private_key->safeDelete();
|
||||||
$this->private_key->delete();
|
currentTeam()->privateKeys = PrivateKey::where('team_id', currentTeam()->id)->get();
|
||||||
currentTeam()->privateKeys = PrivateKey::where('team_id', currentTeam()->id)->get();
|
return redirect()->route('security.private-key.index');
|
||||||
|
} catch (\Exception $e) {
|
||||||
return redirect()->route('security.private-key.index');
|
$this->dispatch('error', $e->getMessage());
|
||||||
}
|
|
||||||
$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.');
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
@@ -56,8 +57,9 @@ class Show extends Component
|
|||||||
public function changePrivateKey()
|
public function changePrivateKey()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->private_key->private_key = formatPrivateKey($this->private_key->private_key);
|
$this->private_key->updatePrivateKey([
|
||||||
$this->private_key->save();
|
'private_key' => formatPrivateKey($this->private_key->private_key)
|
||||||
|
]);
|
||||||
refresh_server_connection($this->private_key);
|
refresh_server_connection($this->private_key);
|
||||||
$this->dispatch('success', 'Private key updated.');
|
$this->dispatch('success', 'Private key updated.');
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
@@ -178,4 +178,21 @@ class PrivateKey extends BaseModel
|
|||||||
&& $this->githubApps()->count() === 0
|
&& $this->githubApps()->count() === 0
|
||||||
&& $this->gitlabApps()->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,
|
'is_public' => true,
|
||||||
'team_id' => 0,
|
'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