From 0d12b8296e4d4f91517a4a7d4518df2b169787de Mon Sep 17 00:00:00 2001 From: "Gauthier A." Date: Mon, 17 Feb 2025 23:10:21 +0100 Subject: [PATCH 1/5] fix wrong database container name + code simplification --- app/Actions/Database/StartDatabaseProxy.php | 68 ++++----------------- 1 file changed, 11 insertions(+), 57 deletions(-) diff --git a/app/Actions/Database/StartDatabaseProxy.php b/app/Actions/Database/StartDatabaseProxy.php index d9272356c..14be9d2bc 100644 --- a/app/Actions/Database/StartDatabaseProxy.php +++ b/app/Actions/Database/StartDatabaseProxy.php @@ -22,74 +22,28 @@ class StartDatabaseProxy public function handle(StandaloneRedis|StandalonePostgresql|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse|ServiceDatabase $database) { - $internalPort = null; - $type = $database->getMorphClass(); + $databaseType = $database->database_type; $network = data_get($database, 'destination.network'); $server = data_get($database, 'destination.server'); $containerName = data_get($database, 'uuid'); $proxyContainerName = "{$database->uuid}-proxy"; + if ($database->getMorphClass() === \App\Models\ServiceDatabase::class) { $databaseType = $database->databaseType(); // $connectPredefined = data_get($database, 'service.connect_to_docker_network'); $network = $database->service->uuid; $server = data_get($database, 'service.destination.server'); $proxyContainerName = "{$database->service->uuid}-proxy"; - switch ($databaseType) { - case 'standalone-mariadb': - $type = \App\Models\StandaloneMariadb::class; - $containerName = "mariadb-{$database->service->uuid}"; - break; - case 'standalone-mongodb': - $type = \App\Models\StandaloneMongodb::class; - $containerName = "mongodb-{$database->service->uuid}"; - break; - case 'standalone-mysql': - $type = \App\Models\StandaloneMysql::class; - $containerName = "mysql-{$database->service->uuid}"; - break; - case 'standalone-postgresql': - $type = \App\Models\StandalonePostgresql::class; - $containerName = "postgresql-{$database->service->uuid}"; - break; - case 'standalone-redis': - $type = \App\Models\StandaloneRedis::class; - $containerName = "redis-{$database->service->uuid}"; - break; - case 'standalone-keydb': - $type = \App\Models\StandaloneKeydb::class; - $containerName = "keydb-{$database->service->uuid}"; - break; - case 'standalone-dragonfly': - $type = \App\Models\StandaloneDragonfly::class; - $containerName = "dragonfly-{$database->service->uuid}"; - break; - case 'standalone-clickhouse': - $type = \App\Models\StandaloneClickhouse::class; - $containerName = "clickhouse-{$database->service->uuid}"; - break; - case 'standalone-supabase/postgres': - $type = \App\Models\StandalonePostgresql::class; - $containerName = "supabase-db-{$database->service->uuid}"; - break; - } - } - if ($type === \App\Models\StandaloneRedis::class) { - $internalPort = 6379; - } elseif ($type === \App\Models\StandalonePostgresql::class) { - $internalPort = 5432; - } elseif ($type === \App\Models\StandaloneMongodb::class) { - $internalPort = 27017; - } elseif ($type === \App\Models\StandaloneMysql::class) { - $internalPort = 3306; - } elseif ($type === \App\Models\StandaloneMariadb::class) { - $internalPort = 3306; - } elseif ($type === \App\Models\StandaloneKeydb::class) { - $internalPort = 6379; - } elseif ($type === \App\Models\StandaloneDragonfly::class) { - $internalPort = 6379; - } elseif ($type === \App\Models\StandaloneClickhouse::class) { - $internalPort = 9000; + $containerName = "{$database->name}-{$database->service->uuid}"; } + + $internalPort = match ($databaseType) { + 'standalone-mariadb', 'standalone-mysql' => 3306, + 'standalone-postgresql', 'standalone-supabase/postgres' => 5432, + 'standalone-redis', 'standalone-keydb', 'standalone-dragonfly' => 6379, + 'standalone-clickhouse' => 9000, + }; + $configuration_dir = database_proxy_dir($database->uuid); $nginxconf = << Date: Wed, 12 Mar 2025 16:33:00 +0100 Subject: [PATCH 2/5] fix(database): correct container name generation for service databases --- app/Actions/Database/StartDatabaseProxy.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Actions/Database/StartDatabaseProxy.php b/app/Actions/Database/StartDatabaseProxy.php index 14be9d2bc..c16a5638a 100644 --- a/app/Actions/Database/StartDatabaseProxy.php +++ b/app/Actions/Database/StartDatabaseProxy.php @@ -27,21 +27,19 @@ class StartDatabaseProxy $server = data_get($database, 'destination.server'); $containerName = data_get($database, 'uuid'); $proxyContainerName = "{$database->uuid}-proxy"; - if ($database->getMorphClass() === \App\Models\ServiceDatabase::class) { $databaseType = $database->databaseType(); - // $connectPredefined = data_get($database, 'service.connect_to_docker_network'); $network = $database->service->uuid; $server = data_get($database, 'service.destination.server'); $proxyContainerName = "{$database->service->uuid}-proxy"; - $containerName = "{$database->name}-{$database->service->uuid}"; + $containerName = str($database->name)->slug().'-'.$database->s˝ervice->uuid; } - $internalPort = match ($databaseType) { 'standalone-mariadb', 'standalone-mysql' => 3306, 'standalone-postgresql', 'standalone-supabase/postgres' => 5432, 'standalone-redis', 'standalone-keydb', 'standalone-dragonfly' => 6379, 'standalone-clickhouse' => 9000, + 'standalone-mongodb' => 27017, }; $configuration_dir = database_proxy_dir($database->uuid); From d894c3d9036b11a0071bc7cf6855e80623199100 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 12 Mar 2025 16:33:35 +0100 Subject: [PATCH 3/5] feat(database): implement two-step confirmation for database deletion Added a new delete method in the Database component that includes a two-step confirmation process requiring the user to enter their password. If two-step confirmation is disabled, the deletion proceeds without password verification. Additionally, a confirmation modal has been integrated into the database view to prompt users before deletion, enhancing the safety of this critical operation. --- app/Livewire/Project/Service/Database.php | 26 +++++++++++++++++++ .../project/service/database.blade.php | 4 +++ .../livewire/project/service/index.blade.php | 8 +++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/app/Livewire/Project/Service/Database.php b/app/Livewire/Project/Service/Database.php index 9f02db05c..c3b7577e9 100644 --- a/app/Livewire/Project/Service/Database.php +++ b/app/Livewire/Project/Service/Database.php @@ -4,7 +4,10 @@ namespace App\Livewire\Project\Service; use App\Actions\Database\StartDatabaseProxy; use App\Actions\Database\StopDatabaseProxy; +use App\Models\InstanceSettings; use App\Models\ServiceDatabase; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Hash; use Livewire\Component; class Database extends Component @@ -15,6 +18,8 @@ class Database extends Component public $fileStorages; + public $parameters; + protected $listeners = ['refreshFileStorages']; protected $rules = [ @@ -34,12 +39,33 @@ class Database extends Component public function mount() { + $this->parameters = get_route_parameters(); if ($this->database->is_public) { $this->db_url_public = $this->database->getServiceDatabaseUrl(); } $this->refreshFileStorages(); } + public function delete($password) + { + if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) { + if (! Hash::check($password, Auth::user()->password)) { + $this->addError('password', 'The provided password is incorrect.'); + + return; + } + } + + try { + $this->database->delete(); + $this->dispatch('success', 'Database deleted.'); + + return redirect()->route('project.service.configuration', $this->parameters); + } catch (\Throwable $e) { + return handleError($e, $this); + } + } + public function instantSaveExclude() { $this->submit(); diff --git a/resources/views/livewire/project/service/database.blade.php b/resources/views/livewire/project/service/database.blade.php index c18473a14..8ec73b4de 100644 --- a/resources/views/livewire/project/service/database.blade.php +++ b/resources/views/livewire/project/service/database.blade.php @@ -7,6 +7,10 @@

{{ Str::headline($database->name) }}

@endif Save +
diff --git a/resources/views/livewire/project/service/index.blade.php b/resources/views/livewire/project/service/index.blade.php index 8796be966..d5c0c4778 100644 --- a/resources/views/livewire/project/service/index.blade.php +++ b/resources/views/livewire/project/service/index.blade.php @@ -3,8 +3,8 @@
+ class="{{ request()->routeIs('project.service.configuration') ? 'menu-item-active' : '' }}" wire:navigate + href="{{ route('project.service.configuration', [...$parameters, 'stack_service_uuid' => null]) }}"> General @if ($serviceDatabase?->isBackupSolutionAvailable()) Backups + @click.prevent="activeTab = 'backups'; window.location.hash = 'backups'" wire:navigate + href="#backups">Backups @endif
From 18fe524cdbd578d0f9f8bb8b787771f8f80f380c Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 12 Mar 2025 16:34:42 +0100 Subject: [PATCH 4/5] fix(database): limit container name length for database proxy Updated the container name generation logic in StartDatabaseProxy to ensure the resulting name does not exceed 32 characters. This change prevents potential issues with container name length restrictions, enhancing the robustness of the database proxy setup. --- app/Actions/Database/StartDatabaseProxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Actions/Database/StartDatabaseProxy.php b/app/Actions/Database/StartDatabaseProxy.php index c16a5638a..8d7d1ce2e 100644 --- a/app/Actions/Database/StartDatabaseProxy.php +++ b/app/Actions/Database/StartDatabaseProxy.php @@ -32,7 +32,7 @@ class StartDatabaseProxy $network = $database->service->uuid; $server = data_get($database, 'service.destination.server'); $proxyContainerName = "{$database->service->uuid}-proxy"; - $containerName = str($database->name)->slug().'-'.$database->s˝ervice->uuid; + $containerName = substr(str($database->name)->slug().'-'.$database->service->uuid, 0, 32); } $internalPort = match ($databaseType) { 'standalone-mariadb', 'standalone-mysql' => 3306, From 078ef62eb87fd27bef1494779777cd807a852501 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 12 Mar 2025 16:35:47 +0100 Subject: [PATCH 5/5] fix(database): handle unsupported database types in StartDatabaseProxy Added a default case to the switch statement in StartDatabaseProxy to throw an exception for unsupported database types. This change improves error handling and ensures that only valid database types are processed, enhancing the robustness of the database proxy functionality. --- app/Actions/Database/StartDatabaseProxy.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Actions/Database/StartDatabaseProxy.php b/app/Actions/Database/StartDatabaseProxy.php index 8d7d1ce2e..3b36e9b70 100644 --- a/app/Actions/Database/StartDatabaseProxy.php +++ b/app/Actions/Database/StartDatabaseProxy.php @@ -40,6 +40,7 @@ class StartDatabaseProxy 'standalone-redis', 'standalone-keydb', 'standalone-dragonfly' => 6379, 'standalone-clickhouse' => 9000, 'standalone-mongodb' => 27017, + default => throw new \Exception("Unsupported database type: $databaseType"), }; $configuration_dir = database_proxy_dir($database->uuid);