Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
hhit
config-generator
Commits
9799bb18
Commit
9799bb18
authored
Mar 06, 2021
by
Hendrik Heneke
Browse files
Add environment to values.
parent
56ebc243
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
6 deletions
+14
-6
fixture/cfgen/users.json.hbs
fixture/cfgen/users.json.hbs
+2
-1
src/Generator/Factory.php
src/Generator/Factory.php
+1
-1
src/Generator/Values/ValuesLoader.php
src/Generator/Values/ValuesLoader.php
+7
-2
src/Generator/Values/ValuesLoaderFactory.php
src/Generator/Values/ValuesLoaderFactory.php
+4
-2
No files found.
fixture/cfgen/users.json.hbs
View file @
9799bb18
...
...
@@ -9,5 +9,6 @@
{{/
each
}}
},
"version": 2,
"secret": "
{{
secret
}}
"
"secret": "
{{
secret
}}
",
"env": "
{{
_env
}}
"
}
src/Generator/Factory.php
View file @
9799bb18
...
...
@@ -95,7 +95,7 @@ class Factory
private
function
createValuesLoaderFactory
():
ValuesLoaderFactory
{
return
new
ValuesLoaderFactory
(
$this
->
createSecretProviderFactory
());
return
new
ValuesLoaderFactory
(
$this
->
createSecretProviderFactory
()
,
$this
->
env
);
}
private
function
createValidatorFactory
():
ValidatorFactory
...
...
src/Generator/Values/ValuesLoader.php
View file @
9799bb18
...
...
@@ -11,17 +11,23 @@ class ValuesLoader extends JsonReader
{
private
array
$context
=
[];
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
);
$this
->
provider
=
$provider
;
$this
->
env
=
$env
;
}
public
function
getValues
()
{
if
(
!
$this
->
context
)
{
$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
;
}
...
...
@@ -45,7 +51,6 @@ class ValuesLoader extends JsonReader
}
}
}
return
$array
;
}
}
src/Generator/Values/ValuesLoaderFactory.php
View file @
9799bb18
...
...
@@ -9,14 +9,16 @@ use HHIT\ConfigGenerator\Generator\Secrets\SecretProviderFactory;
class
ValuesLoaderFactory
{
private
SecretProviderFactory
$secretProviderFactory
;
private
string
$env
;
public
function
__construct
(
SecretProviderFactory
$secretProviderFactory
)
public
function
__construct
(
SecretProviderFactory
$secretProviderFactory
,
string
$env
)
{
$this
->
secretProviderFactory
=
$secretProviderFactory
;
$this
->
env
=
$env
;
}
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
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment