Refactor shared variable type validation
This commit is contained in:
@@ -34,7 +34,7 @@ class Add extends Component
|
|||||||
$this->validate();
|
$this->validate();
|
||||||
if (str($this->value)->startsWith('{{') && str($this->value)->endsWith('}}')) {
|
if (str($this->value)->startsWith('{{') && str($this->value)->endsWith('}}')) {
|
||||||
$type = str($this->value)->after("{{")->before(".")->value;
|
$type = str($this->value)->after("{{")->before(".")->value;
|
||||||
if (!collect(['team', 'project', 'environment'])->contains($type)) {
|
if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) {
|
||||||
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
|
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class All extends Component
|
|||||||
$found->value = $variable;
|
$found->value = $variable;
|
||||||
if (str($found->value)->startsWith('{{') && str($found->value)->endsWith('}}')) {
|
if (str($found->value)->startsWith('{{') && str($found->value)->endsWith('}}')) {
|
||||||
$type = str($found->value)->after("{{")->before(".")->value;
|
$type = str($found->value)->after("{{")->before(".")->value;
|
||||||
if (!collect(['team', 'project', 'environment'])->contains($type)) {
|
if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) {
|
||||||
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
|
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ class All extends Component
|
|||||||
$environment->value = $variable;
|
$environment->value = $variable;
|
||||||
if (str($environment->value)->startsWith('{{') && str($environment->value)->endsWith('}}')) {
|
if (str($environment->value)->startsWith('{{') && str($environment->value)->endsWith('}}')) {
|
||||||
$type = str($environment->value)->after("{{")->before(".")->value;
|
$type = str($environment->value)->after("{{")->before(".")->value;
|
||||||
if (!collect(['team', 'project', 'environment'])->contains($type)) {
|
if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) {
|
||||||
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
|
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class Show extends Component
|
|||||||
}
|
}
|
||||||
if (str($this->env->value)->startsWith('{{') && str($this->env->value)->endsWith('}}')) {
|
if (str($this->env->value)->startsWith('{{') && str($this->env->value)->endsWith('}}')) {
|
||||||
$type = str($this->env->value)->after("{{")->before(".")->value;
|
$type = str($this->env->value)->after("{{")->before(".")->value;
|
||||||
if (!collect(['team', 'project', 'environment'])->contains($type)) {
|
if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) {
|
||||||
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
|
$this->dispatch('error', 'Invalid shared variable type.', "Valid types are: team, project, environment.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class EnvironmentVariable extends Model
|
|||||||
$variable = Str::after($environment_variable, "{$type}.");
|
$variable = Str::after($environment_variable, "{$type}.");
|
||||||
$variable = Str::before($variable, '}}');
|
$variable = Str::before($variable, '}}');
|
||||||
$variable = Str::of($variable)->trim()->value;
|
$variable = Str::of($variable)->trim()->value;
|
||||||
if (!collect(['team', 'project', 'environment'])->contains($type)) {
|
if (!collect(SHARED_VARIABLE_TYPES)->contains($type)) {
|
||||||
return $variable;
|
return $variable;
|
||||||
}
|
}
|
||||||
if ($type === 'environment') {
|
if ($type === 'environment') {
|
||||||
|
|||||||
@@ -34,3 +34,5 @@ const SUPPORTED_OS = [
|
|||||||
'centos fedora rhel ol rocky',
|
'centos fedora rhel ol rocky',
|
||||||
'sles opensuse-leap opensuse-tumbleweed'
|
'sles opensuse-leap opensuse-tumbleweed'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const SHARED_VARIABLE_TYPES = ['team', 'project', 'environment'];
|
||||||
|
|||||||
Reference in New Issue
Block a user