Skip to content

Commit 0f83fb3

Browse files
committed
#12 normalize audit operation
1 parent 8d1922e commit 0f83fb3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

thehive-backend/app/services/AuditSrv.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ trait AuditedModel { self: BaseModelDef ⇒
2323
.toMap
2424
def selectAuditedAttributes(attrs: JsObject) = JsObject {
2525
attrs.fields.flatMap {
26-
case nv @ (attrName, _) auditedAttributes.get(attrName).map(_ nv)
26+
case (attrName, value)
27+
val attrNames = attrName.split("\\.").toSeq
28+
auditedAttributes.get(attrNames.head).map { _
29+
val reverseNames = attrNames.reverse
30+
reverseNames.drop(1).foldLeft(reverseNames.head value)((jsTuple, name) name JsObject(Seq(jsTuple)))
31+
}
2732
}
2833
}
2934
}

thehive-backend/app/services/StreamSrv.scala

+10-4
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ class StreamActor(
126126
eventSrv.unsubscribe(self)
127127
}
128128

129+
private def normalizeOperation(operation: AuditOperation) = {
130+
operation.entity.model match {
131+
case am: AuditedModel operation.copy(details = am.selectAuditedAttributes(operation.details))
132+
}
133+
}
129134
private def receiveWithState(waitingRequest: Option[WaitingRequest], currentMessages: Map[String, Option[StreamMessageGroup[_]]]): Receive = {
130135
/* End of HTTP request, mark received messages to ready*/
131136
case Commit(requestId)
@@ -149,17 +154,18 @@ class StreamActor(
149154
/* */
150155
case operation: AuditOperation if operation.entity.model.isInstanceOf[AuditedModel]
151156
val requestId = operation.authContext.requestId
152-
logger.debug(s"Receiving audit operation : $operation")
157+
val normalizedOperation = normalizeOperation(operation)
158+
logger.debug(s"Receiving audit operation : $operation => $normalizedOperation")
153159
val updatedOperationGroup = currentMessages.get(requestId) match {
154160
case None
155161
logger.debug("Operation that comes after the end of request, make operation ready to send")
156-
AuditOperationGroup(auxSrv, operation).makeReady // Operation that comes after the end of request
162+
AuditOperationGroup(auxSrv, normalizedOperation).makeReady // Operation that comes after the end of request
157163
case Some(None)
158164
logger.debug("First operation of the request, creating operation group")
159-
AuditOperationGroup(auxSrv, operation) // First operation related to the given request
165+
AuditOperationGroup(auxSrv, normalizedOperation) // First operation related to the given request
160166
case Some(Some(aog: AuditOperationGroup))
161167
logger.debug("Operation included in existing group")
162-
aog :+ operation
168+
aog :+ normalizedOperation
163169
case _
164170
logger.debug("Impossible")
165171
sys.error("")

0 commit comments

Comments
 (0)