Skip to content

Commit

Permalink
#1550 Fix case use in describe API
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Sep 25, 2020
1 parent 30573d8 commit e0a2786
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
33 changes: 19 additions & 14 deletions thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,23 @@ class DescribeCtrl @Inject() (
)
).toOption

val entityDescriptions: Seq[EntityDescription] = Seq(
EntityDescription("case", "/case", caseCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case", _))),
EntityDescription("case_task", "/case/task", taskCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case_task", _))),
EntityDescription("alert", "/alert", alertCtrl.publicData.publicProperties.list.flatMap(propertyToJson("alert", _))),
EntityDescription("case_artifact", "/case/artifact", observableCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case_artifact", _))),
EntityDescription("user", "/user", userCtrl.publicData.publicProperties.list.flatMap(propertyToJson("user", _))),
EntityDescription("case_task_log", "/case/task/log", logCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case_task_log", _))),
EntityDescription("audit", "/audit", auditCtrl.publicData.publicProperties.list.flatMap(propertyToJson("audit", _)))
) ++ describeCortexEntity("case_artifact_job", "/connector/cortex/job", "JobCtrl") ++
describeCortexEntity("action", "/connector/cortex/action", "ActionCtrl")
def entityDescriptions: Seq[EntityDescription] =
cacheApi.getOrElseUpdate(s"describe.v0", cacheExpire) {
Seq(
EntityDescription("case", "/case", caseCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case", _))),
EntityDescription("case_task", "/case/task", taskCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case_task", _))),
EntityDescription("alert", "/alert", alertCtrl.publicData.publicProperties.list.flatMap(propertyToJson("alert", _))),
EntityDescription(
"case_artifact",
"/case/artifact",
observableCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case_artifact", _))
),
EntityDescription("user", "/user", userCtrl.publicData.publicProperties.list.flatMap(propertyToJson("user", _))),
EntityDescription("case_task_log", "/case/task/log", logCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case_task_log", _))),
EntityDescription("audit", "/audit", auditCtrl.publicData.publicProperties.list.flatMap(propertyToJson("audit", _)))
) ++ describeCortexEntity("case_artifact_job", "/connector/cortex/job", "JobCtrl") ++
describeCortexEntity("action", "/connector/cortex/action", "ActionCtrl")
}

implicit val propertyDescriptionWrites: Writes[PropertyDescription] =
Json.writes[PropertyDescription].transform((_: JsObject) + ("description" -> JsString("")))
Expand Down Expand Up @@ -179,17 +186,15 @@ class DescribeCtrl @Inject() (
.auth { _ =>
entityDescriptions
.collectFirst {
case desc if desc.label == modelName => Success(Results.Ok(cacheApi.getOrElseUpdate(s"describe.v0.$modelName", cacheExpire)(desc.toJson)))
case desc if desc.label == modelName => Success(Results.Ok(desc.toJson))
}
.getOrElse(Failure(NotFoundError(s"Model $modelName not found")))
}

def describeAll: Action[AnyContent] =
entrypoint("describe all models")
.auth { _ =>
val descriptors = entityDescriptions.map { desc =>
desc.label -> cacheApi.getOrElseUpdate(s"describe.v0.${desc.label}", cacheExpire)(desc.toJson)
}
val descriptors = entityDescriptions.map(desc => desc.label -> desc.toJson)
Success(Results.Ok(JsObject(descriptors)))
}
}
29 changes: 15 additions & 14 deletions thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,19 @@ class DescribeCtrl @Inject() (
)
).toOption

val entityDescriptions: Seq[EntityDescription] = Seq(
EntityDescription("case", caseCtrl.publicProperties.list.flatMap(propertyToJson("case", _))),
EntityDescription("case_task", taskCtrl.publicProperties.list.flatMap(propertyToJson("case_task", _))),
EntityDescription("alert", alertCtrl.publicProperties.list.flatMap(propertyToJson("alert", _))),
EntityDescription("case_artifact", observableCtrl.publicProperties.list.flatMap(propertyToJson("case_artifact", _))),
EntityDescription("user", userCtrl.publicProperties.list.flatMap(propertyToJson("user", _))),
// EntityDescription("case_task_log", logCtrl.publicProperties.list.flatMap(propertyToJson("case_task_log", _))),
EntityDescription("audit", auditCtrl.publicProperties.list.flatMap(propertyToJson("audit", _)))
) ++ describeCortexEntity("case_artifact_job", "/connector/cortex/job", "JobCtrl") ++
describeCortexEntity("action", "/connector/cortex/action", "ActionCtrl")
def entityDescriptions: Seq[EntityDescription] =
cacheApi.getOrElseUpdate(s"describe.v1", cacheExpire) {
Seq(
EntityDescription("case", caseCtrl.publicProperties.list.flatMap(propertyToJson("case", _))),
EntityDescription("case_task", taskCtrl.publicProperties.list.flatMap(propertyToJson("case_task", _))),
EntityDescription("alert", alertCtrl.publicProperties.list.flatMap(propertyToJson("alert", _))),
EntityDescription("case_artifact", observableCtrl.publicProperties.list.flatMap(propertyToJson("case_artifact", _))),
EntityDescription("user", userCtrl.publicProperties.list.flatMap(propertyToJson("user", _))),
// EntityDescription("case_task_log", logCtrl.publicProperties.list.flatMap(propertyToJson("case_task_log", _))),
EntityDescription("audit", auditCtrl.publicProperties.list.flatMap(propertyToJson("audit", _)))
) ++ describeCortexEntity("case_artifact_job", "/connector/cortex/job", "JobCtrl") ++
describeCortexEntity("action", "/connector/cortex/action", "ActionCtrl")
}

implicit val propertyDescriptionWrites: Writes[PropertyDescription] =
Json.writes[PropertyDescription].transform((_: JsObject) + ("description" -> JsString("")))
Expand Down Expand Up @@ -187,17 +190,15 @@ class DescribeCtrl @Inject() (
.auth { _ =>
entityDescriptions
.collectFirst {
case desc if desc.label == modelName => Success(Results.Ok(cacheApi.getOrElseUpdate(s"describe.v1.$modelName", cacheExpire)(desc.toJson)))
case desc if desc.label == modelName => Success(Results.Ok(desc.toJson))
}
.getOrElse(Failure(NotFoundError(s"Model $modelName not found")))
}

def describeAll: Action[AnyContent] =
entrypoint("describe all models")
.auth { _ =>
val descriptors = entityDescriptions.map { desc =>
desc.label -> cacheApi.getOrElseUpdate(s"describe.v1.${desc.label}", cacheExpire)(desc.toJson)
}
val descriptors = entityDescriptions.map(desc => desc.label -> desc.toJson)
Success(Results.Ok(JsObject(descriptors)))
}
}

0 comments on commit e0a2786

Please sign in to comment.