Skip to content

Commit

Permalink
#1415 Remove flow max age
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jul 7, 2020
1 parent e4d0b34 commit 6937494
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 41 deletions.
37 changes: 3 additions & 34 deletions thehive/app/org/thp/thehive/controllers/v0/AuditCtrl.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package org.thp.thehive.controllers.v0

import java.util.Date

import akka.actor.ActorRef
import akka.pattern.ask
import akka.util.Timeout
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._
Expand All @@ -21,15 +17,14 @@ 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() (
entryPoint: Entrypoint,
properties: Properties,
auditSrv: AuditSrv,
@Named("flow-actor") flowActor: ActorRef,
appConfig: ApplicationConfig,
val caseSrv: CaseSrv,
val taskSrv: TaskSrv,
val userSrv: UserSrv,
Expand All @@ -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",
Expand All @@ -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 {
Expand All @@ -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)))
}
}
4 changes: 2 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v0/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions thehive/conf/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ stream.longPolling {
keepAlive: 5 minutes
}

flow {
maxAge = 1 day
}

tags {
autocreate: true
defaultNamespace: "_autocreate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AuditCtrlTest extends PlaySpecification with TestAppBuilder {
def getFlow(caseId: String) = {
val request = FakeRequest("GET", "/api/v0/flow")
.withHeaders("user" -> "[email protected]")
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]]
}
Expand Down

0 comments on commit 6937494

Please sign in to comment.