vendor/symfony/framework-bundle/Command/SecretsEncryptFromLocalCommand.php line 33

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\FrameworkBundle\Command;
  11. use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
  12. use Symfony\Component\Console\Attribute\AsCommand;
  13. use Symfony\Component\Console\Command\Command;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. use Symfony\Component\Console\Style\SymfonyStyle;
  18. /**
  19.  * @author Nicolas Grekas <p@tchwork.com>
  20.  *
  21.  * @internal
  22.  */
  23. #[AsCommand(name'secrets:encrypt-from-local'description'Encrypt all local secrets to the vault')]
  24. final class SecretsEncryptFromLocalCommand extends Command
  25. {
  26.     private AbstractVault $vault;
  27.     private ?AbstractVault $localVault;
  28.     public function __construct(AbstractVault $vaultAbstractVault $localVault null)
  29.     {
  30.         $this->vault $vault;
  31.         $this->localVault $localVault;
  32.         parent::__construct();
  33.     }
  34.     protected function configure()
  35.     {
  36.         $this
  37.             ->setHelp(<<<'EOF'
  38. The <info>%command.name%</info> command encrypts all locally overridden secrets to the vault.
  39.     <info>%command.full_name%</info>
  40. EOF
  41.             )
  42.         ;
  43.     }
  44.     protected function execute(InputInterface $inputOutputInterface $output): int
  45.     {
  46.         $io = new SymfonyStyle($input$output instanceof ConsoleOutputInterface $output->getErrorOutput() : $output);
  47.         if (null === $this->localVault) {
  48.             $io->error('The local vault is disabled.');
  49.             return 1;
  50.         }
  51.         foreach ($this->vault->list(true) as $name => $value) {
  52.             $localValue $this->localVault->reveal($name);
  53.             if (null !== $localValue && $value !== $localValue) {
  54.                 $this->vault->seal($name$localValue);
  55.             } elseif (null !== $message $this->localVault->getLastMessage()) {
  56.                 $io->error($message);
  57.                 return 1;
  58.             }
  59.         }
  60.         return 0;
  61.     }
  62. }