Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     Registry::set('output', $output);
     $instance = $input->getArgument('instance');
     $repository = new Repository();
     $instance = $repository->findEc2Instance($instance);
     if (!$instance instanceof Instance) {
         throw new \Exception('Could not find instance');
     }
     $output->writeln('[Found instance: ' . $instance->getDefaultUsername() . '@' . $instance->getConnectionIp() . ']');
     $connection = $instance->getSshConnection();
     if ($command = $input->getOption('command')) {
         $commandObj = new \AwsInspector\Ssh\Command($connection, $command);
         if ($input->getOption('print')) {
             $output->writeln($commandObj->__toString());
             return 0;
         }
         $res = $commandObj->exec();
         $output->writeln($res['output']);
         return $res['returnVar'];
     }
     if ($input->getOption('print')) {
         $output->writeln($connection->__toString());
         return 0;
     }
     $connection->connect();
     return 0;
 }
Example #2
0
 public function __toString()
 {
     $parts = ['ssh'];
     if ($this->privateKey) {
         $parts[] = '-i ' . $this->privateKey->getPrivateKeyFile();
     }
     if (!is_null($this->jumpHost)) {
         if ($output = Registry::get('output')) {
             /* @var $output OutputInterface */
             $output->writeln("[Using jump host: " . $this->jumpHost->getDefaultUsername() . '@' . $this->jumpHost->getPublicIpAddress() . "]");
         }
         $proxyCommand = new Command($this->jumpHost->getSshConnection(), 'nc %h %p');
         $parts[] = '-o ProxyCommand="' . $proxyCommand->__toString() . '"';
     }
     if ($this->multiplex) {
         $connection = "~/mux_{$this->username}@{$this->host}:22";
         self::$multiplexedConnections[$connection] = "{$connection} {$this->host}";
         $parts[] = "-o ControlPersist=yes -o ControlMaster=auto -S {$connection}";
     }
     $parts[] = '-o ConnectTimeout=5';
     //$parts[] = '-o LogLevel=QUIET';
     $parts[] = '-o StrictHostKeyChecking=no';
     // $parts[] = '-t'; // Force pseudo-tty allocation.
     $parts[] = "{$this->username}@{$this->host}";
     return implode(' ', $parts);
 }
 /**
  * @test
  */
 public function getReturnsFalseIfExpectedKeyIsNotAvailable()
 {
     $value = \AwsInspector\Registry::get('key_phpunit_getReturnsFalseIfExpectedKeyIsNotAvailable');
     $this->assertFalse($value);
 }