From aaed1114c88a85b68f80edfd844effab8f537465 Mon Sep 17 00:00:00 2001 From: To-om Date: Sat, 10 Apr 2021 19:41:57 +0200 Subject: [PATCH] #1946 Apply limitedCount in tag usage --- thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala | 8 +++++++- .../app/org/thp/thehive/controllers/v1/TagRenderer.scala | 9 +++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala index e35ef1545f..5f0fa4698b 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala @@ -6,6 +6,7 @@ import org.thp.scalligraph.EntityIdOrName import org.thp.scalligraph.controllers.{Entrypoint, FieldsParser} import org.thp.scalligraph.models.{Database, Entity} import org.thp.scalligraph.query._ +import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem} import org.thp.scalligraph.traversal.TraversalOps._ import org.thp.scalligraph.traversal.{Converter, IteratorOutput, Traversal} import org.thp.scalligraph.utils.FunctionalCondition.When @@ -24,9 +25,14 @@ class TagCtrl @Inject() ( db: Database, tagSrv: TagSrv, val organisationSrv: OrganisationSrv, - properties: Properties + properties: Properties, + appConfig: ApplicationConfig ) extends QueryableCtrl with TagRenderer { + + val limitedCountThresholdConfig: ConfigItem[Long, Long] = appConfig.item[Long]("query.limitedCountThreshold", "Maximum number returned by a count") + val limitedCountThreshold: Long = limitedCountThresholdConfig.get + override val entityName: String = "Tag" override val publicProperties: PublicProperties = properties.tag override val initialQuery: Query = diff --git a/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala b/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala index 3b665045c3..489887c737 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala @@ -10,15 +10,16 @@ import play.api.libs.json._ import java.util.{Map => JMap} trait TagRenderer extends BaseRenderer[Tag] { + val limitedCountThreshold: Long def usageStats(implicit authContext: AuthContext ): Traversal.V[Tag] => Traversal[JsObject, JMap[String, Any], Converter[JsObject, JMap[String, Any]]] = _.project( - _.by(_.`case`.count) - .by(_.alert.count) - .by(_.observable.count) - .by(_.caseTemplate.count) + _.by(_.`case`.limitedCount(limitedCountThreshold)) + .by(_.alert.limitedCount(limitedCountThreshold)) + .by(_.observable.limitedCount(limitedCountThreshold)) + .by(_.caseTemplate.limitedCount(limitedCountThreshold)) ).domainMap { case (caseCount, alertCount, observableCount, caseTemplateCount) => Json.obj(