Skip to content

Instantly share code, notes, and snippets.

@trane
Created October 19, 2015 22:35
Show Gist options
  • Select an option

  • Save trane/349885fe5c7ef65fb21b to your computer and use it in GitHub Desktop.

Select an option

Save trane/349885fe5c7ef65fb21b to your computer and use it in GitHub Desktop.
private def secretTryFromString(s: String): Try[Secret] = {
Parse.parseOptions(s) match {
case Some(json) => SecretEncoder.EncodeJson.decode(json)
case None => Failure(s"unable to decode secret from string $s")
}
}
def getValue[A,B](k: String): Future[Try[String]] = {
getConsulResponse(k).map(str =>
str.decodeOption[ConsulResponse] match {
case Some(res) => Success(res.value)
case None => Failure(s"unable to decode consulresponse $str")
}
)
val s = getConsulResponse(k)
val decodedJSONList = s.map(a => a.decodeOption[List[ConsulSecretStore.ConsulResponse]].getOrElse( List() ))
decodedJSONList.map(a=> Try(base64Decode(a.headOption.get.Value) ) )
//compiler warns about get here. Not sure what the best way to fail is though
}
import SecretEncoder.EncodeJson.SecretCodecJson
implicit val SecretsCodecJson: argonaut.CodecJson[Secrets] =
casecodec2(Secrets.apply, Secrets.unapply)("current", "previous")
def res2Secrets(cs: ConsulResponse): Try[Secrets] =
Base64StringEncoder.decode(cs.value).flatMap(_.decodeOption[Secrets] match {
case Some(s) => Success(s)
case None => Failure("unable to decode...")
})
val cs = ConsulResponse(_, _, _, _, _, base64)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment