Skip to content

Commit

Permalink
#1348 Include parent objects in responder request
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed May 21, 2020
1 parent afe23df commit ec758cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.thp.thehive.connector.cortex.dto.v0.InputAction
import org.thp.thehive.connector.cortex.models.RichAction
import org.thp.thehive.connector.cortex.services.{ActionSrv, ActionSteps, EntityHelper}
import org.thp.thehive.controllers.v0.Conversion.{toObjectType, _}
import org.thp.thehive.controllers.v0.{IdOrName, OutputParam, QueryableCtrl}
import org.thp.thehive.controllers.v0.{AuditRenderer, IdOrName, OutputParam, QueryableCtrl}
import org.thp.thehive.models._
import org.thp.thehive.services._
import play.api.libs.json.{JsObject, Json, OWrites}
Expand All @@ -32,16 +32,17 @@ class ActionCtrl @Inject() (
logSrv: LogSrv,
alertSrv: AlertSrv,
implicit val executionContext: ExecutionContext
) extends QueryableCtrl {
) extends QueryableCtrl
with AuditRenderer {

implicit val entityWrites: OWrites[Entity] = OWrites[Entity] { entity =>
db.roTransaction { implicit graph =>
entity match {
case c: Case => caseSrv.get(c).richCaseWithoutPerms.getOrFail("Case").map(_.toJson.as[JsObject])
case t: Task => taskSrv.get(t).richTask.getOrFail("Task").map(_.toJson.as[JsObject])
case o: Observable => observableSrv.get(o).richObservable.getOrFail("Observable").map(_.toJson.as[JsObject])
case l: Log => logSrv.get(l).richLog.getOrFail("Log").map(_.toJson.as[JsObject])
case a: Alert => alertSrv.get(a).richAlert.getOrFail("Alert").map(_.toJson.as[JsObject])
case c: Case => caseToJson(caseSrv.get(c)).getOrFail("Case")
case t: Task => taskToJson(taskSrv.get(t)).getOrFail("Task")
case o: Observable => observableToJson(observableSrv.get(o)).getOrFail("Observable")
case l: Log => logToJson(logSrv.get(l)).getOrFail("Log")
case a: Alert => alertToJson(alertSrv.get(a)).getOrFail("Alert")
}
}
.getOrElse(Json.obj("_type" -> entity._model.label, "_id" -> entity._id))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.thp.thehive.connector.cortex

import org.thp.scalligraph.steps.StepsOps._
import org.thp.thehive.connector.cortex.models.ObservableJob
import org.thp.thehive.services.ObservableSteps

package object services {
implicit class RichObservableSteps(observableSteps: ObservableSteps) {
def jobs: JobSteps = new JobSteps(observableSteps.outTo[ObservableJob].raw)(observableSteps.db, observableSteps.graph)
}
}

0 comments on commit ec758cf

Please sign in to comment.