in src/main/scala/com/gu/ssm/SSH.scala [41:62]
def writeHostKey(addressHostKeyTuples: (String, String)*): Attempt[File] = {
// Write key to file.
val prefix = "security_ssm-scala_temporary-host-key"
val suffix = ".tmp"
try {
val hostKeyFile = File.createTempFile(prefix, suffix)
val writer = new PrintWriter(new FileOutputStream(hostKeyFile))
try {
addressHostKeyTuples.foreach { case (address, hostKey) =>
writer.println(s"$address $hostKey")
}
} finally {
writer.close()
}
Attempt.Right(hostKeyFile)
} catch {
case e:IOException => Attempt.Left(
Failure(s"Unable to create host key file", "Error creating host key on disk", UnhandledError, e)
)
}
}