in app/controllers/Api.scala [355:396]
def dataKeysList = summary[Data](
prismDataStore.dataAgent,
d => Some(Json.toJson(d.key)),
"keys"
)
def dataLookup(key: String) = Action.async { implicit request =>
ApiResult.filter {
val app = request.getQueryString("app")
val stage = request.getQueryString("stage")
val stack = request.getQueryString("stack")
val validKey =
prismDataStore.dataAgent.getTuples.filter(_._2.key == key).toSeq
val errors: Map[String, String] = Map.empty ++
(if (app.isEmpty) Some("app" -> "Must specify app") else None) ++
(if (stage.isEmpty) Some("stage" -> "Must specify stage") else None) ++
(if (stage.isEmpty) Some("stack" -> "Must specify stack") else None) ++
(if (validKey.isEmpty) Some("key" -> s"The key name $key was not found")
else None) ++
(if (validKey.size > 1)
Some("key" -> s"The key name $key was matched multiple times")
else None)
if (errors.nonEmpty)
throw ApiCallException(Json.toJson(errors).as[JsObject])
val (label, data) = validKey.head
data
.firstMatchingData(stack.get, app.get, stage.get)
.map(data => Map(label -> Seq(data)))
.getOrElse {
throw ApiCallException(
Json.obj(
"value" -> s"Key $key has no matching value for stack=$stack, app=$app and stage=$stage"
)
)
}
} reduce { result =>
Json.toJson(result.head._2.head)
}
}