AwsInspector\Ssh\Connection::__toString PHP Method

__toString() public method

public __toString ( )
    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=ERROR';
        $parts[] = '-o StrictHostKeyChecking=no';
        $parts[] = '-o UserKnownHostsFile=/dev/null';
        // avoid "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!"
        // $parts[] = '-t'; // Force pseudo-tty allocation.
        $parts[] = "{$this->username}@{$this->host}";
        return implode(' ', $parts);
    }

Usage Example

 /**
  * @test
  */
 public function withJumpHost()
 {
     $jumpHost = new Instance(['Tags' => [], 'PrivateIpAddress' => '4.5.7.6']);
     $connection = new Connection('TestUsername', '1.2.3.4', null, $jumpHost);
     $this->assertEquals('ssh -o ProxyCommand="ssh -o ConnectTimeout=5 -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected] \'nc %h %p\'" -o ConnectTimeout=5 -o LogLevel=ERROR -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected]', $connection->__toString());
 }