Skip to content

Commit

Permalink
Fix MISP configuration format
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Mar 2, 2020
1 parent 1b96726 commit 9d635d5
Showing 1 changed file with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package org.thp.thehive.connector.misp.services

import scala.concurrent.duration.Duration
import scala.concurrent.{ExecutionContext, Future}
import play.api.libs.json.{Format, JsObject, JsString, Json}

import play.api.libs.json._
import play.api.libs.ws.WSClient
import play.api.libs.ws.ahc.AhcWSClientConfig

import akka.stream.Materializer
import gremlin.scala.P
import javax.inject.Inject
Expand Down Expand Up @@ -34,7 +36,57 @@ case class TheHiveMispClientConfig(

object TheHiveMispClientConfig {
implicit val purposeFormat: Format[MispPurpose.Value] = Json.formatEnum(MispPurpose)
implicit val format: Format[TheHiveMispClientConfig] = Json.using[Json.WithDefaultValues].format[TheHiveMispClientConfig]
val reads: Reads[TheHiveMispClientConfig] = {
for {
name <- (JsPath \ "name").read[String]
url <- (JsPath \ "url").read[String]
auth <- (JsPath \ "auth").read[Authentication]
wsConfig <- (JsPath \ "wsConfig").readWithDefault[ProxyWSConfig](ProxyWSConfig(AhcWSClientConfig(), None))
maxAge <- (JsPath \ "maxAge").readNullable[Duration]
excludedOrganisations <- (JsPath \ "exclusion" \ "organisations").readWithDefault[Seq[String]](Nil)
excludedTags <- (JsPath \ "exclusion" \ "tags").readWithDefault[Set[String]](Set.empty)
whitelistTags <- (JsPath \ "whitelist" \ "tags").readWithDefault[Set[String]](Set.empty)
purpose <- (JsPath \ "purpose").readWithDefault[MispPurpose.Value](MispPurpose.ImportAndExport)
caseTemplate <- (JsPath \ "caseTemplate").readNullable[String]
artifactTags <- (JsPath \ "tags").readWithDefault[Seq[String]](Nil)
exportCaseTags <- (JsPath \ "exportCaseTags").readWithDefault[Boolean](false)
includedTheHiveOrganisations <- (JsPath \ "includedTheHiveOrganisations").readWithDefault[Seq[String]](Seq("*"))
excludedTheHiveOrganisations <- (JsPath \ "excludedTheHiveOrganisations").readWithDefault[Seq[String]](Nil)
} yield TheHiveMispClientConfig(
name,
url,
auth,
wsConfig,
maxAge,
excludedOrganisations,
excludedTags,
whitelistTags,
purpose,
caseTemplate,
artifactTags,
exportCaseTags,
includedTheHiveOrganisations,
excludedTheHiveOrganisations
)
}
val writes: Writes[TheHiveMispClientConfig] = Writes[TheHiveMispClientConfig] { cfg =>
Json.obj(
"name" -> cfg.name,
"url" -> cfg.url,
"auth" -> cfg.auth,
"wsConfig" -> cfg.wsConfig,
"maxAge" -> cfg.maxAge,
"exclusion" -> Json.obj("organisations" -> cfg.excludedOrganisations, "tags" -> cfg.excludedTags),
"whitelistTags" -> Json.obj("whitelist" -> cfg.whitelistTags),
"purpose" -> cfg.purpose,
"caseTemplate" -> cfg.caseTemplate,
"tags" -> cfg.artifactTags,
"exportCaseTags" -> cfg.exportCaseTags,
"includedTheHiveOrganisations" -> cfg.includedTheHiveOrganisations,
"excludedTheHiveOrganisations" -> cfg.excludedTheHiveOrganisations
)
}
implicit val format: Format[TheHiveMispClientConfig] = Format[TheHiveMispClientConfig](reads, writes)
}

class TheHiveMispClient(
Expand Down

0 comments on commit 9d635d5

Please sign in to comment.