From be9d1977d06f3d095e9b78e580abc0f42c1a0ed6 Mon Sep 17 00:00:00 2001 From: To-om Date: Wed, 15 Jul 2020 17:23:23 +0200 Subject: [PATCH] #1410 Add actions query --- ScalliGraph | 2 +- .../cortex/controllers/v0/ActionCtrl.scala | 27 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ScalliGraph b/ScalliGraph index 832f8c8e21..4147c24e1b 160000 --- a/ScalliGraph +++ b/ScalliGraph @@ -1 +1 @@ -Subproject commit 832f8c8e210ac5dfb83be941e00f209b8a06ef53 +Subproject commit 4147c24e1bf33893014d8678b3557c9d089918ca diff --git a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ActionCtrl.scala b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ActionCtrl.scala index 3f2e886583..4c55b8dafd 100644 --- a/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ActionCtrl.scala +++ b/cortex/connector/src/main/scala/org/thp/thehive/connector/cortex/controllers/v0/ActionCtrl.scala @@ -1,14 +1,15 @@ package org.thp.thehive.connector.cortex.controllers.v0 import javax.inject.{Inject, Named, Singleton} +import org.thp.scalligraph.auth.AuthContext import org.thp.scalligraph.controllers.{Entrypoint, FieldsParser} -import org.thp.scalligraph.models.{Database, Entity} -import org.thp.scalligraph.query.{ParamQuery, PublicProperty, Query} -import org.thp.scalligraph.steps.PagedResult +import org.thp.scalligraph.models.{Database, Entity, Schema} +import org.thp.scalligraph.query.{ParamQuery, PublicProperty, Query, SubType} import org.thp.scalligraph.steps.StepsOps._ +import org.thp.scalligraph.steps.{PagedResult, VertexSteps} import org.thp.thehive.connector.cortex.controllers.v0.Conversion._ import org.thp.thehive.connector.cortex.dto.v0.InputAction -import org.thp.thehive.connector.cortex.models.RichAction +import org.thp.thehive.connector.cortex.models.{ActionContext, 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.{AuditRenderer, IdOrName, OutputParam, QueryableCtrl} @@ -18,6 +19,7 @@ import play.api.libs.json.{JsObject, Json, OWrites} import play.api.mvc.{Action, AnyContent, Results} import scala.concurrent.{ExecutionContext, Future} +import scala.reflect.runtime.{universe, universe => ru} @Singleton class ActionCtrl @Inject() ( @@ -31,6 +33,7 @@ class ActionCtrl @Inject() ( observableSrv: ObservableSrv, logSrv: LogSrv, alertSrv: AlertSrv, + schema: Schema, implicit val executionContext: ExecutionContext ) extends QueryableCtrl with AuditRenderer { @@ -64,6 +67,22 @@ class ActionCtrl @Inject() ( ) override val outputQuery: Query = Query.output[RichAction, ActionSteps](_.richAction) + val actionsQuery: Query = new Query { + override val name: String = "actions" + override def checkFrom(t: universe.Type): Boolean = + SubType(t, ru.typeOf[CaseSteps]) || SubType(t, ru.typeOf[ObservableSteps]) || + SubType(t, ru.typeOf[TaskSteps]) || + SubType(t, ru.typeOf[LogSteps]) || + SubType(t, ru.typeOf[AlertSteps]) + override def toType(t: universe.Type): universe.Type = ru.typeOf[ActionSteps] + override def apply(param: Unit, from: Any, authContext: AuthContext): Any = { + val fromSteps = from.asInstanceOf[VertexSteps[_]] + new ActionSteps(from.asInstanceOf[VertexSteps[_]].inTo[ActionContext].raw)(db, fromSteps.graph, schema) + } + } + + override val extraQueries: Seq[ParamQuery[_]] = Seq(actionsQuery) + def create: Action[AnyContent] = entrypoint("create action") .extract("action", FieldsParser[InputAction])