Skip to content

Commit

Permalink
Fix import: prevent import non-existent param + import with empty bdd (
Browse files Browse the repository at this point in the history
  • Loading branch information
BrownSim committed Jan 26, 2024
1 parent 6f1ad2a commit 41ac8e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Manager/ImportManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ class ImportManager implements ImportManagerInterface

private ParameterConverterInterface $parameterConverter;

private ConfigurationManager $configurationManager;

private AbstractVault $vault;

public function __construct(ParameterManagerInterface $parameterManager, ParameterConverterInterface $parameterConverter, AbstractVault $vault)
public function __construct(ParameterManagerInterface $parameterManager, ParameterConverterInterface $parameterConverter, ConfigurationManager $configurationManager, AbstractVault $vault)
{
$this->parameterManager = $parameterManager;
$this->parameterConverter = $parameterConverter;
$this->configurationManager = $configurationManager;
$this->vault = $vault;
}

Expand All @@ -26,7 +29,9 @@ public function import(File $source): void
$raw = Yaml::parseFile($source->getRealPath());

foreach ($raw as $path => $stringValue) {
$this->parameterManager->set($path, $this->parameterConverter->getUserValue($path, $stringValue));
if ($this->configurationManager->has($path)) {
$this->parameterManager->set($path, $this->parameterConverter->getUserValue($path, $stringValue));
}
}

$this->parameterManager->save();
Expand All @@ -35,9 +40,12 @@ public function import(File $source): void

public function importFromVault(): void
{
foreach ($this->parameterManager->getAll() as $path => $value) {
$stringValue = $this->vault->reveal($path);
$this->parameterManager->set($path, $this->parameterConverter->getUserValue($path, $stringValue));
foreach ($this->configurationManager->getDefinedParameters() as $definition) {
$stringValue = $this->vault->reveal($definition->getPath());

if (null !== $stringValue) {
$this->parameterManager->set($definition->getPath(), $this->parameterConverter->getUserValue($definition->getPath(), $stringValue));
}
}

$this->parameterManager->save();
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<service id="sherlockode_configuration.import_manager" class="Sherlockode\ConfigurationBundle\Manager\ImportManager">
<argument type="service" id="sherlockode_configuration.parameter_manager"/>
<argument type="service" id="sherlockode_configuration.parameter_converter"/>
<argument type="service" id="sherlockode_configuration.configuration_manager"/>
<argument type="service" id="secrets.vault"/>
</service>

Expand Down

0 comments on commit 41ac8e4

Please sign in to comment.