fix: prevent overwrite already existing env variables in services

This commit is contained in:
Andras Bacsai 2023-09-22 15:46:30 +02:00
parent 3fc544e0b9
commit 31b0ccba99

View File

@ -313,7 +313,12 @@ public function parse(bool $isNew = false): Collection
$variableName = Str::of(replaceVariables(Str::of($value))); $variableName = Str::of(replaceVariables(Str::of($value)));
$generatedValue = null; $generatedValue = null;
if ($variableName->startsWith('SERVICE_USER')) { if ($variableName->startsWith('SERVICE_USER')) {
$generatedValue = Str::random(10); $variableDefined = EnvironmentVariable::whereServiceId($this->id)->where('key', $variableName->value())->first();
if (!$variableDefined) {
$generatedValue = Str::random(10);
} else {
$generatedValue = $variableDefined->value;
}
if (!$envs->has($variableName->value())) { if (!$envs->has($variableName->value())) {
$envs->put($variableName->value(), $generatedValue); $envs->put($variableName->value(), $generatedValue);
EnvironmentVariable::updateOrCreate([ EnvironmentVariable::updateOrCreate([
@ -327,7 +332,12 @@ public function parse(bool $isNew = false): Collection
]); ]);
} }
} else if ($variableName->startsWith('SERVICE_PASSWORD')) { } else if ($variableName->startsWith('SERVICE_PASSWORD')) {
$generatedValue = Str::password(symbols: false); $variableDefined = EnvironmentVariable::whereServiceId($this->id)->where('key', $variableName->value())->first();
if (!$variableDefined) {
$generatedValue = Str::password(symbols: false);
} else {
$generatedValue = $variableDefined->value;
}
if (!$envs->has($variableName->value())) { if (!$envs->has($variableName->value())) {
$envs->put($variableName->value(), $generatedValue); $envs->put($variableName->value(), $generatedValue);
EnvironmentVariable::updateOrCreate([ EnvironmentVariable::updateOrCreate([