From e0a27868051fecd85d109479cc8f0700d0341817 Mon Sep 17 00:00:00 2001 From: To-om Date: Fri, 25 Sep 2020 08:57:08 +0200 Subject: [PATCH] #1550 Fix case use in describe API --- .../thehive/controllers/v0/DescribeCtrl.scala | 33 +++++++++++-------- .../thehive/controllers/v1/DescribeCtrl.scala | 29 ++++++++-------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala index 77db1bb1c9..8acaf7294b 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/DescribeCtrl.scala @@ -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(""))) @@ -179,7 +186,7 @@ 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"))) } @@ -187,9 +194,7 @@ class DescribeCtrl @Inject() ( 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))) } } diff --git a/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala index 1c5c2b6ec4..24c63afeea 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/DescribeCtrl.scala @@ -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(""))) @@ -187,7 +190,7 @@ 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"))) } @@ -195,9 +198,7 @@ class DescribeCtrl @Inject() ( 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))) } }