예제 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $clicDir = $input->getOption('clic-dir');
     if (!$clicDir) {
         $clicDir = $configHelper->getConfiguration()->getClicDirectory();
     }
     $backupFile = new \SplFileInfo($clicDir . '/settings-backup/' . sha1($configHelper->getConfigurationFile()->getPathname()) . '/' . $input->getArgument('version'));
     if (!$backupFile->isFile()) {
         throw new NotAFileException($backupFile);
     }
     try {
         $config = new GlobalConfiguration($backupFile);
         $config->getConfig();
     } catch (\Exception $ex) {
         $output->writeln(sprintf('<error>Cannot restore %s: %s</error>', $backupFile, $ex->getMessage()));
         return 1;
     }
     FsUtil::file_put_contents($configHelper->getConfigurationFile(), FsUtil::file_get_contents($backupFile));
     $output->writeln(sprintf('Restored %s to version %s', $configHelper->getConfigurationFile(), $backupFile->getRealPath()));
 }
예제 #2
0
 public function write()
 {
     $this->validate();
     FsUtil::file_put_contents($this->getConfigFile()->getPathname(), json_encode($this->config, JSON_PRETTY_PRINT));
 }
예제 #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     try {
         $configHelper->getConfiguration()->getRepositoryConfiguration($input->getArgument('repository'));
         throw new RepositoryExistsException($input->getArgument('repository'));
     } catch (NoSuchRepositoryException $ex) {
         // no op
     }
     if (!Util::isSshRepositoryUrl($input->getArgument('repository'))) {
         throw new NoSshRepositoryException($input->getArgument('repository'));
     }
     $repositoryConfig = new RepositoryConfiguration();
     $repositoryConfig->setSshAlias($input->getOption('alias') ?: sha1($input->getArgument('repository') . time()));
     $sshKeyFile = new \SplFileInfo($input->getArgument('key'));
     if (!$sshKeyFile->isFile()) {
         throw new NotAFileException($sshKeyFile);
     }
     $repositoryConfig->setIdentityFile($sshKeyFile->getRealPath());
     $sshConfigFile = new \SplFileInfo($configHelper->getConfiguration()->getSshDirectory() . '/config');
     if (!file_exists($sshConfigFile->getPathname())) {
         FsUtil::touch($sshConfigFile->getPathname());
     }
     if (!$sshConfigFile->isFile()) {
         throw new NotAFileException($sshConfigFile);
     }
     if (!$sshConfigFile->isReadable()) {
         throw new UnreadableFileException($sshConfigFile);
     }
     if (!$sshConfigFile->isWritable()) {
         throw new UnwritableFileException($sshConfigFile);
     }
     $sshConfigLines = file($sshConfigFile);
     try {
         if (Util::addSshAliasLines($sshConfigLines, $input->getArgument('repository'), $repositoryConfig)) {
             FsUtil::file_put_contents($sshConfigFile, implode(PHP_EOL, $sshConfigLines));
             $output->writeln(sprintf('Added section <info>%s</info> to <info>%s</info>', 'Host ' . $repositoryConfig->getSshAlias(), $sshConfigFile->getPathname()), OutputInterface::VERBOSITY_VERBOSE);
         } else {
             $output->writeln(sprintf('Added section <info>%s</info> already exists in <info>%s</info>', 'Host ' . $repositoryConfig->getSshAlias(), $sshConfigFile->getPathname()), OutputInterface::VERBOSITY_VERBOSE);
         }
     } catch (SshAliasExistsException $ex) {
         throw new SshAliasExistsException($ex->getAliasName(), $ex->getLineNumber(), $sshConfigFile);
     }
     $configHelper->getConfiguration()->setRepositoryConfiguration($input->getArgument('repository'), $repositoryConfig);
     $configHelper->getConfiguration()->write();
     $output->writeln(sprintf('Registered private key <info>%s</info> for repository <info>%s</info>', $repositoryConfig->getIdentityFile(), $input->getArgument('repository')));
     return 0;
 }
예제 #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configHelper = $this->getHelper('configuration');
     /* @var $configHelper GlobalConfigurationHelper */
     $questionHelper = $this->getHelper('question');
     /* @var $questionHelper QuestionHelper */
     $sshConfig = new \SplFileInfo($configHelper->getConfiguration()->getSshDirectory() . '/config');
     if (!$sshConfig->isFile()) {
         throw new NotAFileException($sshConfig);
     }
     if (!$sshConfig->isReadable()) {
         throw new UnreadableFileException($sshConfig);
     }
     if (!$sshConfig->isWritable()) {
         throw new UnwritableFileException($sshConfig);
     }
     $sshConfigLines = file($sshConfig->getPathname());
     $repoName = $input->getArgument('repository');
     $repositoryConfig = $configHelper->getConfiguration()->getRepositoryConfiguration($repoName);
     if (!$questionHelper->ask($input, $output, new ConfirmationQuestion(sprintf('Are you sure you want to remove the ssh key for "%s"? This action is irreversible.', $repoName)))) {
         return 1;
     }
     $sshKeyFile = $repositoryConfig->getIdentityFile();
     $this->unlinkFile($output, $sshKeyFile);
     $this->unlinkFile($output, $sshKeyFile . '.pub');
     if (Util::removeSshAliasLines($sshConfigLines, $repositoryConfig)) {
         $output->writeln(sprintf('Removed section <info>Host %s</info> from <info>%s</info>', $repositoryConfig->getSshAlias(), $sshConfig->getPathname()), OutputInterface::VERBOSITY_VERBOSE);
     }
     $output->writeln(sprintf('Removed repository <info>%s</info>', $repoName));
     $configHelper->getConfiguration()->removeRepositoryConfiguration($repoName);
     FsUtil::file_put_contents($sshConfig->getPathname(), implode('', $sshConfigLines));
     $configHelper->getConfiguration()->write();
     return 0;
 }