getSshConnection() 공개 메소드

Get SSH connection
public getSshConnection ( $multiplex = null ) : Connection
리턴 AwsInspector\Ssh\Connection
예제 #1
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);
 }
예제 #2
0
 /**
  * @test
  */
 public function user()
 {
     $instance = new Instance(['Tags' => [['Key' => 'inspector', 'Value' => 'User:Foo']], 'PrivateIpAddress' => '4.5.7.6']);
     $this->assertEquals('User:Foo', $instance->getTag('inspector'));
     $connection = $instance->getSshConnection();
     $this->assertEquals('4.5.7.6', $connection->getHost());
     $this->assertEquals('Foo', $connection->getUsername());
 }