Skip to content

Commit

Permalink
#1946 Apply limitedCount in tag usage
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Apr 10, 2021
1 parent ac538fe commit aaed111
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 7 additions & 1 deletion thehive/app/org/thp/thehive/controllers/v1/TagCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =
Expand Down
9 changes: 5 additions & 4 deletions thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit aaed111

Please sign in to comment.