Fix old variables from project was getting prefixed with app for no reason
This commit is contained in:
parent
78854f745a
commit
fc308faa5b
1 changed files with 38 additions and 13 deletions
|
|
@ -43,6 +43,13 @@ class CdEnvVariable implements \Stringable
|
|||
*/
|
||||
private bool $isDefault = false;
|
||||
|
||||
/**
|
||||
* The variable was prefiexed with $k8sPrefix
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private bool $wasPrefixed = false;
|
||||
|
||||
/**
|
||||
* Properties that can be accessed from the object.
|
||||
*
|
||||
|
|
@ -88,8 +95,13 @@ class CdEnvVariable implements \Stringable
|
|||
public static function make(
|
||||
array $params
|
||||
): self {
|
||||
$wasPrefixed = Str::startsWith(Arr::get($params, 'key'), self::$k8sPrefix);
|
||||
self::removeVarNamePrefixes($params);
|
||||
return new self(...$params);
|
||||
$var = new self(...$params);
|
||||
if ($wasPrefixed) {
|
||||
$var->wasPrefixed();
|
||||
}
|
||||
return $var;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -108,7 +120,7 @@ class CdEnvVariable implements \Stringable
|
|||
}
|
||||
|
||||
/**
|
||||
* Return is default.
|
||||
* Set is default.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
|
|
@ -118,6 +130,17 @@ class CdEnvVariable implements \Stringable
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set was prefixed.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function wasPrefixed(): self
|
||||
{
|
||||
$this->wasPrefixed = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize var name
|
||||
*
|
||||
|
|
@ -125,20 +148,23 @@ class CdEnvVariable implements \Stringable
|
|||
*/
|
||||
public function getFormatedGitlabKey(): string
|
||||
{
|
||||
$key = $this->key;
|
||||
// * Format with wanted prefixes
|
||||
if ($this->isDefault) {
|
||||
return sprintf(
|
||||
'%s_%s_%s',
|
||||
self::$k8sPrefix,
|
||||
$key = sprintf(
|
||||
'%s_%s',
|
||||
self::$prefix,
|
||||
Str::upper($this->key)
|
||||
$key
|
||||
);
|
||||
}
|
||||
return sprintf(
|
||||
'%s_%s',
|
||||
self::$k8sPrefix,
|
||||
str::upper($this->key)
|
||||
);
|
||||
if ($this->wasPrefixed) {
|
||||
$key = sprintf(
|
||||
'%s_%s',
|
||||
self::$k8sPrefix,
|
||||
$key
|
||||
);
|
||||
}
|
||||
return Str::upper($key);
|
||||
}
|
||||
|
||||
// * PRIVATE
|
||||
|
|
@ -177,8 +203,7 @@ class CdEnvVariable implements \Stringable
|
|||
|
||||
$printStr = $printStr->append(\str_pad('value', $titlePad, pad_type: \STR_PAD_LEFT))
|
||||
->append(' => ');
|
||||
$value = $this->masked ?
|
||||
Str::mask($this->value, '*', 0, intval(ceil(strlen($this->value) * 0.65))) : $this->value;
|
||||
$value = $this->masked ? '*********' : $this->value;
|
||||
$printStr = $printStr->append("`{$value}`")->newLine();
|
||||
|
||||
$printStr = $printStr->append(\str_pad('environment_scope', $titlePad, pad_type: \STR_PAD_LEFT))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue