Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/savage.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rebert <code@rebertia.com>2015-03-24 08:45:49 +0300
committerChris Rebert <code@rebertia.com>2015-03-24 08:45:49 +0300
commit456e45e703460f05f081395fc115b3481ef8f505 (patch)
treeea7a2abf36d56b7994d8e97adb388c5ac8756aeb
parentda96b788483ea34b6035190c8358b4ed5bec1fb9 (diff)
add more Travis-related logging
-rw-r--r--src/main/scala/com/getbootstrap/savage/server/SavageWebService.scala3
-rw-r--r--src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala16
-rw-r--r--src/main/scala/com/getbootstrap/savage/server/TravisWebHookDirectives.scala7
3 files changed, 20 insertions, 6 deletions
diff --git a/src/main/scala/com/getbootstrap/savage/server/SavageWebService.scala b/src/main/scala/com/getbootstrap/savage/server/SavageWebService.scala
index 091f295..032fad7 100644
--- a/src/main/scala/com/getbootstrap/savage/server/SavageWebService.scala
+++ b/src/main/scala/com/getbootstrap/savage/server/SavageWebService.scala
@@ -90,6 +90,9 @@ class SavageWebService(
}
}
}
+ else {
+ log.info(s"Ignoring authentic Travis event from irrelevant ${event.branchName}")
+ }
complete(StatusCodes.OK)
}
}
diff --git a/src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala b/src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala
index 87ed804..163c3e2 100644
--- a/src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala
+++ b/src/main/scala/com/getbootstrap/savage/server/TravisAuthDirectives.scala
@@ -1,6 +1,7 @@
package com.getbootstrap.savage.server
import scala.util.Try
+import akka.event.LoggingAdapter
import spray.http.FormData
import spray.routing.{Directive1, MalformedHeaderRejection, MalformedRequestContentRejection, ValidationRejection}
import spray.routing.directives.{BasicDirectives, HeaderDirectives, RouteDirectives, MarshallingDirectives}
@@ -16,26 +17,33 @@ trait TravisAuthDirectives {
private val authorization = "Authorization"
private val authorizationHeaderValue = headerValueByName(authorization)
- val travisAuthorization: Directive1[Array[Byte]] = authorizationHeaderValue.flatMap { hex =>
+ def travisAuthorization(log: LoggingAdapter): Directive1[Array[Byte]] = authorizationHeaderValue.flatMap { hex =>
Try{ javax.xml.bind.DatatypeConverter.parseHexBinary(hex) }.toOption match {
case Some(bytesFromHex) => provide(bytesFromHex)
- case None => reject(MalformedHeaderRejection(authorization, "Malformed SHA-256 hex digest"))
+ case None => {
+ log.error(s"Received Travis request with malformed hex digest in ${authorization} header!")
+ reject(MalformedHeaderRejection(authorization, "Malformed SHA-256 hex digest"))
+ }
}
}
private val formDataEntity = entity(as[FormData])
- def stringEntityIfTravisAuthValid(travisToken: String, repo: RepositoryId): Directive1[String] = travisAuthorization.flatMap { hash =>
+ def stringEntityIfTravisAuthValid(travisToken: String, repo: RepositoryId, log: LoggingAdapter): Directive1[String] = travisAuthorization(log).flatMap { hash =>
formDataEntity.flatMap { formData =>
val plainText = repo.generateId + travisToken
val auth = new Sha256(hash = hash, plainText = plainText.utf8Bytes)
if (auth.isValid) {
formData.fields.toMap.get("payload") match {
case Some(string) => provide(string)
- case None => reject(MalformedRequestContentRejection("Request body form data lacked required `payload` field"))
+ case None => {
+ log.error("Received Travis request that was missing the `payload` field!")
+ reject(MalformedRequestContentRejection("Request body form data lacked required `payload` field"))
+ }
}
}
else {
+ log.error("Received Travis request with incorrect hash!")
reject(ValidationRejection("Incorrect SHA-256 hash"))
}
}
diff --git a/src/main/scala/com/getbootstrap/savage/server/TravisWebHookDirectives.scala b/src/main/scala/com/getbootstrap/savage/server/TravisWebHookDirectives.scala
index 90f1e1a..b793a4f 100644
--- a/src/main/scala/com/getbootstrap/savage/server/TravisWebHookDirectives.scala
+++ b/src/main/scala/com/getbootstrap/savage/server/TravisWebHookDirectives.scala
@@ -14,9 +14,12 @@ trait TravisWebHookDirectives {
import TravisAuthDirectives.stringEntityIfTravisAuthValid
import TravisJsonProtocol._
- def authenticatedTravisEvent(travisToken: String, repo: RepositoryId, log: LoggingAdapter): Directive1[TravisPayload] = stringEntityIfTravisAuthValid(travisToken, repo).flatMap{ entityJsonString =>
+ def authenticatedTravisEvent(travisToken: String, repo: RepositoryId, log: LoggingAdapter): Directive1[TravisPayload] = stringEntityIfTravisAuthValid(travisToken, repo, log).flatMap{ entityJsonString =>
Try { entityJsonString.parseJson.convertTo[TravisPayload] } match {
- case Failure(exc) => reject(ValidationRejection("JSON was either malformed or did not match expected schema!"))
+ case Failure(exc) => {
+ log.error("Received Travis request with bad JSON!")
+ reject(ValidationRejection("JSON was either malformed or did not match expected schema!"))
+ }
case Success(payload) => provide(payload)
}
}