fix: multiline env variables

This commit is contained in:
Andras Bacsai
2024-03-15 22:02:37 +01:00
parent 657c7d8cff
commit 3ea3674407
13 changed files with 106 additions and 25 deletions

View File

@@ -49,7 +49,7 @@ class EnvironmentVariable extends Model
set: fn (?string $value = null) => $this->set_environment_variables($value),
);
}
public function realValue(): Attribute
public function resource()
{
$resource = null;
if ($this->application_id) {
@@ -71,9 +71,19 @@ class EnvironmentVariable extends Model
}
}
}
return $resource;
}
public function realValue(): Attribute
{
$resource = $this->resource();
return Attribute::make(
get: function () use ($resource) {
return $this->get_real_environment_variables($this->value, $resource);
$env = $this->get_real_environment_variables($this->value, $resource);
return data_get($env, 'value', $env);
if (is_string($env)) {
return $env;
}
return $env->value;
}
);
}
@@ -89,7 +99,7 @@ class EnvironmentVariable extends Model
}
);
}
private function get_real_environment_variables(?string $environment_variable = null, $resource = null): string|null
private function get_real_environment_variables(?string $environment_variable = null, $resource = null)
{
if (!$environment_variable || !$resource) {
return null;
@@ -112,7 +122,7 @@ class EnvironmentVariable extends Model
}
$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->value;
return $environment_variable_found;
}
}
return $environment_variable;