From 567b45060c240670df5f7989db380f97ed6ab187 Mon Sep 17 00:00:00 2001 From: Petrisor Ciprian Daniel Date: Sat, 6 Jul 2024 22:13:31 +0300 Subject: [PATCH] [FrameworkBundle] Add `exit` option to `secrets:decrypt-to-local` command --- src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../Command/SecretsDecryptToLocalCommand.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index f2470d542f3e5..2db5b9674983e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG * Derivate `kernel.secret` from the decryption secret when its env var is not defined * Make the `config/` directory optional in `MicroKernelTrait`, add support for service arguments in the invokable Kernel class, and register `FrameworkBundle` by default when the `bundles.php` file is missing + * Add `exit` option for `secrets:decrypt-to-local` command 7.1 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/SecretsDecryptToLocalCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/SecretsDecryptToLocalCommand.php index b078769d8fe30..e98a6d54d459d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/SecretsDecryptToLocalCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/SecretsDecryptToLocalCommand.php @@ -38,15 +38,20 @@ public function __construct( protected function configure(): void { $this + ->addOption('exit', null, InputOption::VALUE_NONE, 'Returns a non-zero exit code if any errors are encountered') ->addOption('force', 'f', InputOption::VALUE_NONE, 'Force overriding of secrets that already exist in the local vault') ->setHelp(<<<'EOF' The %command.name% command decrypts all secrets and copies them in the local vault. %command.full_name% -When the option --force is provided, secrets that already exist in the local vault are overriden. +When the --force option is provided, secrets that already exist in the local vault are overriden. %command.full_name% --force + +When the --exit option is provided, the command will return a non-zero exit code if any errors are encountered. + + %command.full_name% --exit EOF ) ; @@ -83,9 +88,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int ]); } + $hadErrors = false; foreach ($secrets as $k => $v) { if (null === $v) { $io->error($this->vault->getLastMessage() ?? \sprintf('Secret "%s" has been skipped as there was an error reading it.', $k)); + $hadErrors = true; continue; } @@ -93,6 +100,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $io->note($this->localVault->getLastMessage()); } + if ($hadErrors && $input->getOption('exit')) { + return 1; + } + return 0; } }