Пример #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('');
     $SafeController = new SafeController();
     try {
         $safes = $SafeController->listSafes();
     } catch (\Exception $e) {
         $output->writeln('<error>FAILED</error>');
         $output->writeln('');
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return;
     }
     $SecretController = new SecretController();
     $rows = array();
     foreach ($safes as $key => $safe) {
         if ($input->getOption('signature')) {
             $rows[] = array($safe->getName(), $safe->getPublicKey()->getKeySignature(), count($SecretController->listSecrets($safe)), $safe->getCreated()->format('Y-m-d H:i:s'), $safe->getUpdated()->format('Y-m-d H:i:s'));
         } else {
             $rows[] = array($safe->getName(), count($SecretController->listSecrets($safe)), $safe->getCreated()->format('Y-m-d H:i:s'), $safe->getUpdated()->format('Y-m-d H:i:s'));
         }
     }
     $table = $this->getHelper('table');
     if ($input->getOption('signature')) {
         $table->setHeaders(array('Safe Name', 'Signature', '# Secrets', 'Created', 'Updated'))->setRows($rows);
     } else {
         $table->setHeaders(array('Safe Name', '# Secrets', 'Created', 'Updated'))->setRows($rows);
     }
     $table->render($output);
     $output->writeln('');
 }
Пример #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $SafeController = new SafeController();
     $safeName = $input->getArgument('safe');
     if (empty($safeName)) {
         $safeNames = $SafeController->getSafeNames();
         $helper = $this->getHelper('question');
         $question = new ChoiceQuestion('<question>Please select the safe for this secret:</question> ', $safeNames);
         $safeName = $helper->ask($input, $output, $question);
     }
     if (empty($safeName)) {
         throw new \Exception("Invalid safe name");
     }
     $output->writeln('');
     $SafeController = new SafeController();
     $safe = $SafeController->view($safeName);
     $SecretController = new SecretController();
     try {
         $secrets = $SecretController->listSecrets($safe);
     } catch (\Exception $e) {
         $output->writeln('<error>FAILED</error>');
         $output->writeln('');
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return;
     }
     $rows = array();
     foreach ($secrets as $key => $secret) {
         if ($input->getOption('signature')) {
             $rows[] = array($secret->getKey(), hash('sha256', $secret->getValue()), strlen($secret->getValue()), $secret->getCreated()->format('Y-m-d H:i:s'), $secret->getUpdated()->format('Y-m-d H:i:s'));
         } else {
             $rows[] = array($secret->getKey(), strlen($secret->getValue()), $secret->getCreated()->format('Y-m-d H:i:s'), $secret->getUpdated()->format('Y-m-d H:i:s'));
         }
     }
     $table = $this->getHelper('table');
     if ($input->getOption('signature')) {
         $table->setHeaders(array('Key Name', 'Signature', 'Length', 'Created', 'Updated'))->setRows($rows);
     } else {
         $table->setHeaders(array('Key Name', 'Length', 'Created', 'Updated'))->setRows($rows);
     }
     $table->render($output);
     $output->writeln('');
 }