def sshCmdBastion()

in src/main/scala/com/gu/ssm/SSH.scala [131:153]


  def sshCmdBastion(rawOutput: Boolean)(privateKeyFile: File, bastionInstance: Instance, targetInstance: Instance, targetInstanceUser: String, bastionIpAddress: String, targetIpAddress: String, bastionPortNumberOpt: Option[Int], bastionUser: String, targetInstancePortNumberOpt: Option[Int], useAgent: Option[Boolean], hostsFile: Option[File]): (InstanceId, Seq[Output]) = {
    val bastionPort = bastionPortNumberOpt.getOrElse(22)
    val targetPort = targetInstancePortNumberOpt.getOrElse(22)
    val hostsFileString = hostsFile.map(file => s""" -o "UserKnownHostsFile $file" -o "StrictHostKeyChecking yes"""").getOrElse("")
    val identityFragment = s"-i ${privateKeyFile.getCanonicalFile.toString}"
    val proxyFragment = s"""-o 'ProxyCommand ssh -o "IdentitiesOnly yes" $identityFragment$hostsFileString -p $bastionPort $bastionUser@$bastionIpAddress nc $targetIpAddress $targetPort'"""
    val stringFragmentTTOptions = if(rawOutput) { " -t -t" } else { "" }
    val useAgentFragment = useAgent match {
      case None => ""
      case Some(decision) => if(decision) " -A" else " -a"
    }
    val connectionString =
      s"""ssh$useAgentFragment -o "IdentitiesOnly yes" $identityFragment$hostsFileString $proxyFragment$stringFragmentTTOptions $targetInstanceUser@$targetIpAddress"""
    val cmd = if(rawOutput) {
      Seq(Out(s"$connectionString", newline = false))
    }else{
      Seq(
        Metadata(s"# Dryrun mode. The command below will remain valid for $sshCredentialsLifetimeSeconds seconds:"),
        Out(s"$connectionString;")
      )
    }
    (targetInstance.id, cmd)
  }