Skip to content

Commit

Permalink
#1410 Fix customField conversion in webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jul 6, 2020
1 parent e078b9b commit 1bc030e
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ class Webhook(

// This method change the format of audit details when it contains custom field.
// The custom field type is added to match TheHive 3 webhook format.
def fixCustomFieldDetails(objectType: String, details: String)(implicit graph: Graph): JsValue =
def fixCustomFieldDetails(objectType: String, details: String)(implicit graph: Graph): JsValue = {
val detailsJson = Json.parse(details)
objectType match {
case "Case" | "Alert" | "CaseTemplate" =>
val j = Json.parse(details)
j.asOpt[JsObject].fold(j) { o =>
detailsJson.asOpt[JsObject].fold(detailsJson) { o =>
JsObject(o.fields.map {
case keyValue @ (key, value) if key.startsWith("customField.") =>
val fieldName = key.drop(12)
Expand All @@ -128,7 +128,9 @@ class Webhook(
case keyValue => keyValue
})
}
case _ => detailsJson
}
}

def buildMessage(version: Int, audit: Audit with Entity)(implicit graph: Graph): Try[JsObject] =
version match {
Expand Down

0 comments on commit 1bc030e

Please sign in to comment.