Skip to content

Commit

Permalink
#1415 Add age limit to flow
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jun 28, 2020
1 parent 80d245e commit 83d226e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion thehive/app/org/thp/thehive/controllers/v0/AuditCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package org.thp.thehive.controllers.v0

import java.util.Date

import gremlin.scala.{By, Key}
import gremlin.scala.{By, Key, P}
import javax.inject.{Inject, Named, Singleton}
import org.apache.tinkerpop.gremlin.process.traversal.Order
import org.thp.scalligraph.controllers.{Entrypoint, FieldsParser}
import org.thp.scalligraph.models.Database
import org.thp.scalligraph.query.{ParamQuery, Query}
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 @@ -16,20 +17,27 @@ import org.thp.thehive.services._
import play.api.libs.json.{JsArray, JsObject, Json}
import play.api.mvc.{Action, AnyContent, Results}

import scala.concurrent.duration.Duration
import scala.util.Success
import org.thp.scalligraph.services.config.ApplicationConfig.durationFormat

@Singleton
class AuditCtrl @Inject() (
entryPoint: Entrypoint,
properties: Properties,
auditSrv: AuditSrv,
appConfig: ApplicationConfig,
val caseSrv: CaseSrv,
val taskSrv: TaskSrv,
val userSrv: UserSrv,
@Named("with-thehive-schema") implicit val db: Database
) 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)

override val getQuery: ParamQuery[IdOrName] = Query.initWithParam[IdOrName, AuditSteps](
"getAudit",
FieldsParser[IdOrName],
Expand Down Expand Up @@ -57,6 +65,7 @@ class AuditCtrl @Inject() (
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)
Expand Down
4 changes: 4 additions & 0 deletions thehive/conf/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ stream.longPolling {
keepAlive: 5 minutes
}

flow {
maxAge = 1 day
}

tags {
autocreate: true
defaultNamespace: "_autocreate"
Expand Down

0 comments on commit 83d226e

Please sign in to comment.