Skip to content

Commit

Permalink
#869 Use observable TLP if possible when executing a responder
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Feb 13, 2019
1 parent 4411840 commit e179b6e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ class ActionOperationSrv @Inject() (
}
}

def findArtifactEntity(entity: BaseEntity): Future[Artifact] = {
import org.elastic4play.services.QueryDSL._

(entity, entity.model) match {
case (a: Artifact, _) Future.successful(a)
case (_, model: ChildModelDef[_, _, _, _])
findSrv(model.parentModel, "_id" ~= entity.parentId.getOrElse(throw InternalError(s"Child entity $entity has no parent ID")), Some("0-1"), Nil)
._1.runWith(Sink.head).flatMap(findArtifactEntity _)
case _ Future.failed(BadRequestError("Artifact not found"))
}
}

def execute(entity: BaseEntity, operation: ActionOperation)(implicit authContext: AuthContext): Future[ActionOperation] = {
if (operation.status == ActionOperationStatus.Waiting) {
Retry()(classOf[VersionConflictEngineException]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ class CortexActionSrv @Inject() (

def findResponderFor(entityType: String, entityId: String): Future[Seq[Responder]] = {
for {
(tlp, pap) getEntity(entityType, entityId)
.flatMap(actionOperationSrv.findCaseEntity)
.map { caze (caze.tlp(), caze.pap()) }
.recover { case _ (0L, 0L) }
entity getEntity(entityType, entityId)
artifactTlp actionOperationSrv
.findArtifactEntity(entity)
.map(a Some(a.tlp()))
.recover { case _ None }
(tlp, pap) actionOperationSrv.findCaseEntity(entity)
.map { caze (artifactTlp.getOrElse(caze.tlp()), caze.pap()) }
.recover { case _ (artifactTlp.getOrElse(0L), 0L) }
query = Json.obj(
"dataTypeList" s"thehive:$entityType")
responders findResponders(query)
Expand Down

0 comments on commit e179b6e

Please sign in to comment.