private def setUpStandardScp()

in src/main/scala/com/gu/ssm/Main.scala [126:159]


  private def setUpStandardScp(
                                awsClients: AWSClients,
                                executionTarget: ExecutionTarget,
                                user: String,
                                sism: SingleInstanceSelectionMode,
                                onlyUsePrivateIP: Boolean,
                                rawOutput: Boolean,
                                targetInstancePortNumberOpt: Option[Int],
                                preferredAlgs: List[String],
                                useAgent: Option[Boolean],
                                sourceFile: String,
                                targetFile: String,
                                profile: Option[String],
                                region: Region,
                                tunnelThroughSystemsManager: Boolean): ProgramResult = {
    val fProgramResult = for {
      config <- IO.getSSMConfig(awsClients.ec2Client, awsClients.stsClient, executionTarget)
      sshArtifacts <- Attempt.fromEither(SSH.createKey())
      (privateKeyFile, publicKey) = sshArtifacts
      addPublicKeyCommand = SSH.addTaintedCommand(config.name) + SSH.addPublicKeyCommand(user, publicKey) + SSH.outputHostKeysCommand()
      removePublicKeyCommand = SSH.removePublicKeyCommand(user, publicKey)
      instance <- Attempt.fromEither(Logic.getSSHInstance(config.targets, sism))
      _ <- IO.tagAsTainted(instance.id, config.name, awsClients.ec2Client)
      result <- IO.executeOnInstance(instance.id, config.name, addPublicKeyCommand, awsClients.ssmClient)
      _ <- IO.executeOnInstanceAsync(instance.id, config.name, removePublicKeyCommand, awsClients.ssmClient)
      hostKey <- Attempt.fromEither(Logic.getHostKeyEntry(result, preferredAlgs))
      address <- Attempt.fromEither(Logic.getAddress(instance, onlyUsePrivateIP))
      hostKeyFile <- SSH.writeHostKey((address, hostKey))
    } yield {
      SSH.scpCmdStandard(rawOutput)(privateKeyFile, instance, user, address, targetInstancePortNumberOpt, useAgent, Some(hostKeyFile), sourceFile, targetFile, profile, region, tunnelThroughSystemsManager)
    }
    val programResult = Await.result(fProgramResult.asFuture, Duration.Inf)
    ProgramResult.convertErrorToResult(programResult.map(UI.sshOutput(rawOutput)))
  }