Skip to content

Commit 301e8c5

Browse files
bug #62078 [FrameworkBundle] Fix secrets:encrypt-from-local (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle] Fix secrets:encrypt-from-local | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT The config change fixes the "local-vault" not accounting for `APP_RUNTIME_ENV` The command change skips values not found in the local-vault, because why fail? this is just annoying... (encrypting from local shouldn't fail if not all variables are listed in the local vault. When this happens, we should just keep the existing value in the encrypted vault) Commits ------- df20e13 [FrameworkBundle] Fix secrets:encrypt-from-local
2 parents 68cd755 + df20e13 commit 301e8c5

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/SecretsEncryptFromLocalCommand.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6161
}
6262

6363
foreach ($this->vault->list(true) as $name => $value) {
64-
$localValue = $this->localVault->reveal($name);
64+
if (null === $localValue = $this->localVault->reveal($name)) {
65+
continue;
66+
}
6567

66-
if (null !== $localValue && $value !== $localValue) {
68+
if ($value !== $localValue) {
6769
$this->vault->seal($name, $localValue);
68-
} elseif (null !== $message = $this->localVault->getLastMessage()) {
69-
$io->error($message);
70-
71-
return 1;
70+
$io->note($this->vault->getLastMessage());
7271
}
7372
}
7473

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private function addSecretsSection(ArrayNodeDefinition $rootNode): void
204204
->canBeDisabled()
205205
->children()
206206
->scalarNode('vault_directory')->defaultValue('%kernel.project_dir%/config/secrets/%kernel.runtime_environment%')->cannotBeEmpty()->end()
207-
->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.%kernel.environment%.local')->end()
207+
->scalarNode('local_dotenv_file')->defaultValue('%kernel.project_dir%/.env.%kernel.runtime_environment%.local')->end()
208208
->scalarNode('decryption_env_var')->defaultValue('base64:default::SYMFONY_DECRYPTION_SECRET')->end()
209209
->end()
210210
->end()

src/Symfony/Bundle/FrameworkBundle/Tests/Command/SecretsEncryptFromLocalCommandTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testDoesNotSealIfSameValue()
9292
$this->assertSame('same-value', $revealed);
9393
}
9494

95-
public function testFailsIfLocalSecretIsMissing()
95+
public function testStillSucceedsIfLocalSecretIsMissing()
9696
{
9797
$vault = new SodiumVault($this->vaultDir);
9898
$vault->generateKeys();
@@ -105,7 +105,8 @@ public function testFailsIfLocalSecretIsMissing()
105105
$command = new SecretsEncryptFromLocalCommand($vault, $localVault);
106106
$tester = new CommandTester($command);
107107

108-
$this->assertSame(1, $tester->execute([]));
109-
$this->assertStringContainsString('Secret "MISSING_IN_LOCAL" not found', $tester->getDisplay());
108+
$this->assertSame(0, $tester->execute([]));
109+
$revealed = $vault->reveal('MISSING_IN_LOCAL');
110+
$this->assertSame('prod-only', $revealed);
110111
}
111112
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported() ? 'semaphor
856856
'secrets' => [
857857
'enabled' => true,
858858
'vault_directory' => '%kernel.project_dir%/config/secrets/%kernel.runtime_environment%',
859-
'local_dotenv_file' => '%kernel.project_dir%/.env.%kernel.environment%.local',
859+
'local_dotenv_file' => '%kernel.project_dir%/.env.%kernel.runtime_environment%.local',
860860
'decryption_env_var' => 'base64:default::SYMFONY_DECRYPTION_SECRET',
861861
],
862862
'http_cache' => [

0 commit comments

Comments
 (0)