Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: several shared environment variables in one value, parsed correctly

Andras Bacsaid7350fad7698
diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Add.php b/app/Livewire/Project/Shared/EnvironmentVariable/Add.php
index b732b6b52d..a859c90b02 100644
--- a/app/Livewire/Project/Shared/EnvironmentVariable/Add.php
+++ b/app/Livewire/Project/Shared/EnvironmentVariable/Add.php
@@ -48,14 +48,14 @@ class Add extends Component
public function submit()
{
$this->validate();
- if (str($this->value)->startsWith('{{') && str($this->value)->endsWith('}}')) {
- $type = str($this->value)->after('{{')->before('.')->value;
- if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
- $this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
-
- return;
- }
- }
+ // if (str($this->value)->startsWith('{{') && str($this->value)->endsWith('}}')) {
+ // $type = str($this->value)->after('{{')->before('.')->value;
+ // if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
+ // $this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
+
+ // return;
+ // }
+ // }
$this->dispatch('saveKey', [
'key' => $this->key,
'value' => $this->value,
diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Livewire/Project/Shared/EnvironmentVariable/All.php
index 5fceda8089..9e67602937 100644
--- a/app/Livewire/Project/Shared/EnvironmentVariable/All.php
+++ b/app/Livewire/Project/Shared/EnvironmentVariable/All.php
@@ -125,14 +125,14 @@ class All extends Component
continue;
}
$found->value = $variable;
- if (str($found->value)->startsWith('{{') && str($found->value)->endsWith('}}')) {
- $type = str($found->value)->after('{{')->before('.')->value;
- if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
- $this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
+ // if (str($found->value)->startsWith('{{') && str($found->value)->endsWith('}}')) {
+ // $type = str($found->value)->after('{{')->before('.')->value;
+ // if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
+ // $this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
- return;
- }
- }
+ // return;
+ // }
+ // }
$found->save();
continue;
@@ -140,14 +140,14 @@ class All extends Component
$environment = new EnvironmentVariable;
$environment->key = $key;
$environment->value = $variable;
- if (str($environment->value)->startsWith('{{') && str($environment->value)->endsWith('}}')) {
- $type = str($environment->value)->after('{{')->before('.')->value;
- if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
- $this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
+ // if (str($environment->value)->startsWith('{{') && str($environment->value)->endsWith('}}')) {
+ // $type = str($environment->value)->after('{{')->before('.')->value;
+ // if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
+ // $this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
- return;
- }
- }
+ // return;
+ // }
+ // }
$environment->is_build_time = false;
$environment->is_multiline = false;
$environment->is_preview = $isPreview ? true : false;
diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php
index b291bfcfe2..e638716027 100644
--- a/app/Livewire/Project/Shared/EnvironmentVariable/Show.php
+++ b/app/Livewire/Project/Shared/EnvironmentVariable/Show.php
@@ -108,14 +108,14 @@ class Show extends Component
} else {
$this->validate();
}
- if (str($this->env->value)->startsWith('{{') && str($this->env->value)->endsWith('}}')) {
- $type = str($this->env->value)->after('{{')->before('.')->value;
- if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
- $this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
-
- return;
- }
- }
+ // if (str($this->env->value)->startsWith('{{') && str($this->env->value)->endsWith('}}')) {
+ // $type = str($this->env->value)->after('{{')->before('.')->value;
+ // if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
+ // $this->dispatch('error', 'Invalid shared variable type.', 'Valid types are: team, project, environment.');
+
+ // return;
+ // }
+ // }
$this->serialize();
$this->env->save();
$this->dispatch('success', 'Environment variable updated.');
diff --git a/app/Models/EnvironmentVariable.php b/app/Models/EnvironmentVariable.php
index 28cf0ef934..5e1d8ae139 100644
--- a/app/Models/EnvironmentVariable.php
+++ b/app/Models/EnvironmentVariable.php
@@ -5,7 +5,6 @@ namespace App\Models;
use App\Models\EnvironmentVariable as ModelsEnvironmentVariable;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
-use Illuminate\Support\Str;
use OpenApi\Attributes as OA;
use Symfony\Component\Yaml\Yaml;
use Visus\Cuid2\Cuid2;
@@ -200,28 +199,33 @@ class EnvironmentVariable extends Model
return null;
}
$environment_variable = trim($environment_variable);
- $type = str($environment_variable)->after('{{')->before('.')->value;
- if (str($environment_variable)->startsWith('{{'.$type) && str($environment_variable)->endsWith('}}')) {
- $variable = Str::after($environment_variable, "{$type}.");
- $variable = Str::before($variable, '}}');
- $variable = str($variable)->trim()->value;
+ $sharedEnvsFound = str($environment_variable)->matchAll('/{{(.*?)}}/');
+ if ($sharedEnvsFound->isEmpty()) {
+ return $environment_variable;
+ }
+ foreach ($sharedEnvsFound as $sharedEnv) {
+ $type = str($sharedEnv)->match('/(.*?)\./');
if (! collect(SHARED_VARIABLE_TYPES)->contains($type)) {
- return $variable;
+ continue;
}
- if ($type === 'environment') {
+ $variable = str($sharedEnv)->match('/\.(.*)/');
+ if ($type->value() === 'environment') {
$id = $resource->environment->id;
- } elseif ($type === 'project') {
+ } elseif ($type->value() === 'project') {
$id = $resource->environment->project->id;
- } else {
+ } elseif ($type->value() === 'team') {
$id = $resource->team()->id;
}
+ if (is_null($id)) {
+ continue;
+ }
$environment_variable_found = SharedEnvironmentVariable::where('type', $type)->where('key', $variable)->where('team_id', $resource->team()->id)->where("{$type}_id", $id)->first();
if ($environment_variable_found) {
- return $environment_variable_found;
+ $environment_variable = str($environment_variable)->replace("{{{$sharedEnv}}}", $environment_variable_found->value);
}
}
- return $environment_variable;
+ return str($environment_variable)->value();
}
private function get_environment_variables(?string $environment_variable = null): ?string
diff --git a/bootstrap/helpers/services.php b/bootstrap/helpers/services.php
index 6d03ea2f5a..d4e9ebcde5 100644
--- a/bootstrap/helpers/services.php
+++ b/bootstrap/helpers/services.php
@@ -128,7 +128,6 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
if ($port) {
$variableName = $variableName."_$port";
$generatedEnv = EnvironmentVariable::where('service_id', $resource->service_id)->where('key', $variableName)->first();
- // ray($generatedEnv);
if ($generatedEnv) {
$generatedEnv->value = $fqdn.$path;
$generatedEnv->save();