Skip to content

Commit

Permalink
#1454 Invalidate describe cache when a customfield is added, removed …
Browse files Browse the repository at this point in the history
…and updated
  • Loading branch information
To-om committed Mar 4, 2021
1 parent 97211e3 commit 2797ad0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DescribeCtrl @Inject() (
).toOption

def entityDescriptions: Seq[EntityDescription] =
cacheApi.getOrElseUpdate(s"describe.v0", cacheExpire) {
cacheApi.getOrElseUpdate("describe.v0", cacheExpire) {
Seq(
EntityDescription("case", "/case", caseCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case", _))),
EntityDescription("case_task", "/case/task", taskCtrl.publicData.publicProperties.list.flatMap(propertyToJson("case_task", _))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class DescribeCtrl @Inject() (
).toOption

def entityDescriptions: Seq[EntityDescription] =
cacheApi.getOrElseUpdate(s"describe.v1", cacheExpire) {
cacheApi.getOrElseUpdate("describe.v1", cacheExpire) {
Seq(
EntityDescription("alert", "listAlert", alertCtrl.publicProperties.list.flatMap(propertyToJson("alert", _))),
EntityDescription("audit", "listAudit", auditCtrl.publicProperties.list.flatMap(propertyToJson("audit", _))),
Expand Down
19 changes: 16 additions & 3 deletions thehive/app/org/thp/thehive/services/CustomFieldSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ import org.thp.scalligraph.{EntityIdOrName, RichSeq}
import org.thp.thehive.controllers.v1.Conversion._
import org.thp.thehive.models._
import org.thp.thehive.services.CustomFieldOps._
import play.api.cache.SyncCacheApi
import play.api.libs.json.{JsObject, JsValue}

import java.util.{Map => JMap}
import javax.inject.{Inject, Named, Singleton}
import scala.util.{Success, Try}

@Singleton
class CustomFieldSrv @Inject() (auditSrv: AuditSrv, organisationSrv: OrganisationSrv, @Named("integrity-check-actor") integrityCheckActor: ActorRef)
extends VertexSrv[CustomField] {
class CustomFieldSrv @Inject() (
auditSrv: AuditSrv,
organisationSrv: OrganisationSrv,
@Named("integrity-check-actor") integrityCheckActor: ActorRef,
cacheApi: SyncCacheApi
) extends VertexSrv[CustomField] {

override def createEntity(e: CustomField)(implicit graph: Graph, authContext: AuthContext): Try[CustomField with Entity] = {
integrityCheckActor ! EntityAdded("CustomField")
cacheApi.remove("describe.v0")
cacheApi.remove("describe.v1")
super.createEntity(e)
}

Expand All @@ -37,6 +44,8 @@ class CustomFieldSrv @Inject() (auditSrv: AuditSrv, organisationSrv: Organisatio

def delete(c: CustomField with Entity, force: Boolean)(implicit graph: Graph, authContext: AuthContext): Try[Unit] = {
get(c).remove() // TODO use force
cacheApi.remove("describe.v0")
cacheApi.remove("describe.v1")
organisationSrv.getOrFail(authContext.organisation).flatMap { organisation =>
auditSrv.customField.delete(c, organisation)
}
Expand All @@ -58,7 +67,11 @@ class CustomFieldSrv @Inject() (auditSrv: AuditSrv, organisationSrv: Organisatio
customFieldSteps
.clone()
.getOrFail("CustomFields")
.flatMap(auditSrv.customField.update(_, updatedFields))
.flatMap { cf =>
cacheApi.remove("describe.v0")
cacheApi.remove("describe.v1")
auditSrv.customField.update(cf, updatedFields)
}
}

override def getByName(name: String)(implicit graph: Graph): Traversal.V[CustomField] =
Expand Down

0 comments on commit 2797ad0

Please sign in to comment.