From 6937494b23383c8cc8fa60c0eaee2985994f17e5 Mon Sep 17 00:00:00 2001 From: To-om Date: Tue, 7 Jul 2020 13:30:09 +0200 Subject: [PATCH] #1415 Remove flow max age --- .../thehive/controllers/v0/AuditCtrl.scala | 37 ++----------------- .../thp/thehive/controllers/v0/Router.scala | 4 +- thehive/conf/reference.conf | 4 -- .../controllers/v0/AuditCtrlTest.scala | 2 +- 4 files changed, 6 insertions(+), 41 deletions(-) diff --git a/thehive/app/org/thp/thehive/controllers/v0/AuditCtrl.scala b/thehive/app/org/thp/thehive/controllers/v0/AuditCtrl.scala index 1372589b55..9a06329de6 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/AuditCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/AuditCtrl.scala @@ -1,7 +1,5 @@ package org.thp.thehive.controllers.v0 -import java.util.Date - import akka.actor.ActorRef import akka.pattern.ask import akka.util.Timeout @@ -9,8 +7,6 @@ import javax.inject.{Inject, Named, Singleton} import org.thp.scalligraph.controllers.{Entrypoint, FieldsParser} import org.thp.scalligraph.models.{Database, Schema} import org.thp.scalligraph.query.{ParamQuery, Query} -import org.thp.scalligraph.services.config.ApplicationConfig.durationFormat -import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import org.thp.scalligraph.steps.PagedResult import org.thp.scalligraph.steps.StepsOps._ import org.thp.thehive.controllers.v0.Conversion._ @@ -21,7 +17,7 @@ import play.api.libs.json.{JsArray, JsObject, Json} import play.api.mvc.{Action, AnyContent, Results} import scala.concurrent.ExecutionContext -import scala.concurrent.duration.{Duration, DurationInt} +import scala.concurrent.duration.DurationInt @Singleton class AuditCtrl @Inject() ( @@ -29,7 +25,6 @@ class AuditCtrl @Inject() ( properties: Properties, auditSrv: AuditSrv, @Named("flow-actor") flowActor: ActorRef, - appConfig: ApplicationConfig, val caseSrv: CaseSrv, val taskSrv: TaskSrv, val userSrv: UserSrv, @@ -39,10 +34,7 @@ class AuditCtrl @Inject() ( ) extends QueryableCtrl with AuditRenderer { - val maxFlowAgeConfig: ConfigItem[Duration, Duration] = appConfig.item[Duration]("flow.maxAge", "Max age of items shown in flow") - def maxFlowAge: Duration = maxFlowAgeConfig.get - def flowFromDate = new Date(System.currentTimeMillis() - maxFlowAge.toMillis) - implicit val timeout: Timeout = Timeout(5.minutes) + implicit val timeout: Timeout = Timeout(5.minutes) override val getQuery: ParamQuery[IdOrName] = Query.initWithParam[IdOrName, AuditSteps]( "getAudit", @@ -64,7 +56,7 @@ class AuditCtrl @Inject() ( ) override val outputQuery: Query = Query.output[RichAudit, AuditSteps](_.richAudit) - def flow(caseId: Option[String], count: Option[Int]): Action[AnyContent] = + def flow(caseId: Option[String]): Action[AnyContent] = entryPoint("audit flow") .asyncAuth { implicit request => (flowActor ? FlowId(request.organisation, caseId.filterNot(_ == "any"))).map { @@ -91,28 +83,5 @@ class AuditCtrl @Inject() ( } Results.Ok(JsArray(audits)) } -// val auditTraversal: AuditSteps = auditSrv.initSteps.has("mainAction", true) -// val audits = caseId -// .filterNot(_ == "any") -// .fold(auditTraversal)(cid => auditTraversal.forCase(cid)) -// .has("_createdAt", P.gt(flowFromDate)) -// .visible -// .order(List(By(Key[Date]("_createdAt"), Order.desc))) -// .range(0, count.getOrElse(10).toLong) -// .richAuditWithCustomRenderer(auditRenderer) -// .toIterator -// -// .map { -// case (audit, obj) => -// audit -// .toJson -// .as[JsObject] -// .deepMerge( -// Json.obj("base" -> Json.obj("object" -> obj, "rootId" -> audit.context._id), "summary" -> jsonSummary(auditSrv, audit.requestId)) -// ) -// } -// .toSeq - -// Success(Results.Ok(JsArray(audits))) } } diff --git a/thehive/app/org/thp/thehive/controllers/v0/Router.scala b/thehive/app/org/thp/thehive/controllers/v0/Router.scala index 764b53238f..19fd1923f3 100644 --- a/thehive/app/org/thp/thehive/controllers/v0/Router.scala +++ b/thehive/app/org/thp/thehive/controllers/v0/Router.scala @@ -166,8 +166,8 @@ class Router @Inject() ( case PATCH(p"/dashboard/$dashboardId") => dashboardCtrl.update(dashboardId) // Audit ok case DELETE(p"/dashboard/$dashboardId") => dashboardCtrl.delete(dashboardId) // Audit ok - case GET(p"/audit") => auditCtrl.flow(None, None) - case GET(p"/flow" ? q_o"rootId=$rootId" & q_o"count=${int(count)}") => auditCtrl.flow(rootId, count) + case GET(p"/audit") => auditCtrl.flow(None) + case GET(p"/flow" ? q_o"rootId=$rootId") => auditCtrl.flow(rootId) // GET /audit controllers.AuditCtrl.find // POST /audit/_search controllers.AuditCtrl.find // POST /audit/_stats controllers.AuditCtrl.stats diff --git a/thehive/conf/reference.conf b/thehive/conf/reference.conf index c1570c2c6d..f04317fe73 100644 --- a/thehive/conf/reference.conf +++ b/thehive/conf/reference.conf @@ -37,10 +37,6 @@ stream.longPolling { keepAlive: 5 minutes } -flow { - maxAge = 1 day -} - tags { autocreate: true defaultNamespace: "_autocreate" diff --git a/thehive/test/org/thp/thehive/controllers/v0/AuditCtrlTest.scala b/thehive/test/org/thp/thehive/controllers/v0/AuditCtrlTest.scala index 9f51e1ec58..25cf315e6e 100644 --- a/thehive/test/org/thp/thehive/controllers/v0/AuditCtrlTest.scala +++ b/thehive/test/org/thp/thehive/controllers/v0/AuditCtrlTest.scala @@ -17,7 +17,7 @@ class AuditCtrlTest extends PlaySpecification with TestAppBuilder { def getFlow(caseId: String) = { val request = FakeRequest("GET", "/api/v0/flow") .withHeaders("user" -> "certuser@thehive.local") - val result = app[AuditCtrl].flow(Some(caseId), None)(request) + val result = app[AuditCtrl].flow(Some(caseId))(request) status(result) must equalTo(200).updateMessage(s => s"$s\n${contentAsString(result)}") contentAsJson(result).as[List[JsObject]] }