Commit 9799bb18 authored by Hendrik Heneke's avatar Hendrik Heneke
Browse files

Add environment to values.

parent 56ebc243
...@@ -9,5 +9,6 @@ ...@@ -9,5 +9,6 @@
{{/each}} {{/each}}
}, },
"version": 2, "version": 2,
"secret": "{{secret}}" "secret": "{{secret}}",
"env": "{{_env}}"
} }
...@@ -95,7 +95,7 @@ class Factory ...@@ -95,7 +95,7 @@ class Factory
private function createValuesLoaderFactory(): ValuesLoaderFactory private function createValuesLoaderFactory(): ValuesLoaderFactory
{ {
return new ValuesLoaderFactory($this->createSecretProviderFactory()); return new ValuesLoaderFactory($this->createSecretProviderFactory(), $this->env);
} }
private function createValidatorFactory(): ValidatorFactory private function createValidatorFactory(): ValidatorFactory
......
...@@ -11,17 +11,23 @@ class ValuesLoader extends JsonReader ...@@ -11,17 +11,23 @@ class ValuesLoader extends JsonReader
{ {
private array $context = []; private array $context = [];
private SecretProviderInterface $provider; private SecretProviderInterface $provider;
private string $env;
public function __construct(File $file, SecretProviderInterface $provider) public function __construct(File $file, SecretProviderInterface $provider, string $env)
{ {
parent::__construct($file); parent::__construct($file);
$this->provider = $provider; $this->provider = $provider;
$this->env = $env;
} }
public function getValues() public function getValues()
{ {
if (!$this->context) { if (!$this->context) {
$this->context = $this->postProcess($this->readAsJson()); $this->context = $this->postProcess($this->readAsJson());
if (array_key_exists('_env', $this->context)) {
throw new \RuntimeException('_env is a reserved value - do not define it manually!');
}
$this->context['_env'] = $this->env;
} }
return $this->context; return $this->context;
} }
...@@ -45,7 +51,6 @@ class ValuesLoader extends JsonReader ...@@ -45,7 +51,6 @@ class ValuesLoader extends JsonReader
} }
} }
} }
return $array; return $array;
} }
} }
...@@ -9,14 +9,16 @@ use HHIT\ConfigGenerator\Generator\Secrets\SecretProviderFactory; ...@@ -9,14 +9,16 @@ use HHIT\ConfigGenerator\Generator\Secrets\SecretProviderFactory;
class ValuesLoaderFactory class ValuesLoaderFactory
{ {
private SecretProviderFactory $secretProviderFactory; private SecretProviderFactory $secretProviderFactory;
private string $env;
public function __construct(SecretProviderFactory $secretProviderFactory) public function __construct(SecretProviderFactory $secretProviderFactory, string $env)
{ {
$this->secretProviderFactory = $secretProviderFactory; $this->secretProviderFactory = $secretProviderFactory;
$this->env = $env;
} }
public function create(File $file, string $vaultType): ValuesLoader public function create(File $file, string $vaultType): ValuesLoader
{ {
return new ValuesLoader($file, $this->secretProviderFactory->create($vaultType)); return new ValuesLoader($file, $this->secretProviderFactory->create($vaultType), $this->env);
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment