feat: required envs

This commit is contained in:
Andras Bacsai
2024-10-11 14:38:22 +02:00
parent ca2d946064
commit 88f1e58c63
9 changed files with 214 additions and 128 deletions

View File

@@ -39,6 +39,7 @@ class Navbar extends Component
return [
"echo-private:user.{$userId},ServiceStatusChanged" => 'serviceStarted',
"envsUpdated" => '$refresh',
];
}

View File

@@ -37,6 +37,7 @@ class Show extends Component
'env.is_literal' => 'required|boolean',
'env.is_shown_once' => 'required|boolean',
'env.real_value' => 'nullable',
'env.is_required' => 'required|boolean',
];
protected $validationAttributes = [
@@ -46,6 +47,7 @@ class Show extends Component
'env.is_multiline' => 'Multiline',
'env.is_literal' => 'Literal',
'env.is_shown_once' => 'Shown Once',
'env.is_required' => 'Required',
];
public function refresh()
@@ -109,14 +111,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 ($this->env->is_required && str($this->env->real_value)->isEmpty()) {
$oldValue = $this->env->getOriginal('value');
$this->env->value = $oldValue;
$this->dispatch('error', 'Required environment variable cannot be empty.');
return;
}
$this->serialize();
$this->env->save();
$this->dispatch('success', 'Environment variable updated.');

View File

@@ -44,7 +44,7 @@ class EnvironmentVariable extends Model
'version' => 'string',
];
protected $appends = ['real_value', 'is_shared'];
protected $appends = ['real_value', 'is_shared', 'is_really_required'];
protected static function booted()
{
@@ -130,6 +130,13 @@ class EnvironmentVariable extends Model
);
}
protected function isReallyRequired(): Attribute
{
return Attribute::make(
get: fn () => $this->is_required && str($this->real_value)->isEmpty(),
);
}
protected function isShared(): Attribute
{
return Attribute::make(

View File

@@ -1232,7 +1232,6 @@ class Service extends BaseModel
public function environment_variables(): HasMany
{
return $this->hasMany(EnvironmentVariable::class)->orderByRaw("LOWER(key) LIKE LOWER('SERVICE%') DESC, LOWER(key) ASC");
}
@@ -1316,4 +1315,20 @@ class Service extends BaseModel
return $networks;
}
protected function isDeployable(): Attribute
{
return Attribute::make(
get: function () {
$envs = $this->environment_variables()->where('is_required', true)->get();
foreach ($envs as $env) {
if ($env->is_really_required) {
return false;
}
}
return true;
}
);
}
}