Skip to content

Commit

Permalink
#1410 Add actions query
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jul 15, 2020
1 parent 3a6bcad commit be9d197
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ScalliGraph
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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() (
Expand All @@ -31,6 +33,7 @@ class ActionCtrl @Inject() (
observableSrv: ObservableSrv,
logSrv: LogSrv,
alertSrv: AlertSrv,
schema: Schema,
implicit val executionContext: ExecutionContext
) extends QueryableCtrl
with AuditRenderer {
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit be9d197

Please sign in to comment.