From 85c3270dcc4270a6c9616bb68401105493370b45 Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:44:17 +0200 Subject: [PATCH] update helper and disable input if variable is shared --- .../Project/Database/Redis/General.php | 9 +++++++++ app/Models/StandaloneRedis.php | 12 ++++++++---- .../project/database/redis/general.blade.php | 19 +++++++++++++++---- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/app/Livewire/Project/Database/Redis/General.php b/app/Livewire/Project/Database/Redis/General.php index ab9b0756d..20a881523 100644 --- a/app/Livewire/Project/Database/Redis/General.php +++ b/app/Livewire/Project/Database/Redis/General.php @@ -4,6 +4,7 @@ use App\Actions\Database\StartDatabaseProxy; use App\Actions\Database\StopDatabaseProxy; +use App\Models\EnvironmentVariable; use App\Models\Server; use App\Models\StandaloneRedis; use Exception; @@ -144,6 +145,14 @@ public function render() return view('livewire.project.database.redis.general'); } + public function isSharedVariable($name) + { + return EnvironmentVariable::where('key', $name) + ->where('standalone_redis_id', $this->database->id) + ->where('is_shared', true) + ->exists(); + } + private function updateEnvironmentVariable($key, $value) { $envVar = $this->database->runtime_environment_variables() diff --git a/app/Models/StandaloneRedis.php b/app/Models/StandaloneRedis.php index e71eacc45..188982f47 100644 --- a/app/Models/StandaloneRedis.php +++ b/app/Models/StandaloneRedis.php @@ -21,7 +21,7 @@ class StandaloneRedis extends BaseModel ]; protected $attributes = [ - 'redis_username' => 'redis', + 'redis_username' => 'default', ]; protected static function booted() @@ -220,7 +220,8 @@ protected function internalDbUrl(): Attribute return new Attribute( get: function () { $redis_version = $this->get_redis_version(); - $username_part = version_compare($redis_version, '6.0', '>=') ? "{$this->redis_username}:" : ""; + $username_part = version_compare($redis_version, '6.0', '>=') ? "{$this->redis_username}:" : ''; + return "redis://{$username_part}{$this->redis_password}@{$this->uuid}:6379/0"; } ); @@ -232,9 +233,11 @@ protected function externalDbUrl(): Attribute get: function () { if ($this->is_public && $this->public_port) { $redis_version = $this->get_redis_version(); - $username_part = version_compare($redis_version, '6.0', '>=') ? "{$this->redis_username}:" : ""; + $username_part = version_compare($redis_version, '6.0', '>=') ? "{$this->redis_username}:" : ''; + return "redis://{$username_part}{$this->redis_password}@{$this->destination->server->getIp}:{$this->public_port}/0"; } + return null; } ); @@ -243,6 +246,7 @@ protected function externalDbUrl(): Attribute private function get_redis_version() { $image_parts = explode(':', $this->image); + return $image_parts[1] ?? '0.0'; } @@ -309,9 +313,9 @@ public function getMetrics(int $mins = 5) return $parsedCollection->toArray(); } } + public function isBackupSolutionAvailable() { return false; } } - diff --git a/resources/views/livewire/project/database/redis/general.blade.php b/resources/views/livewire/project/database/redis/general.blade.php index c5ab13d94..e61c210b0 100644 --- a/resources/views/livewire/project/database/redis/general.blade.php +++ b/resources/views/livewire/project/database/redis/general.blade.php @@ -16,11 +16,22 @@ $redis_version = explode(':', $database->image)[1] ?? '0.0'; @endphp @if (version_compare($redis_version, '6.0', '>=')) - + @endif - +