Skip to content

Commit e7eef99

Browse files
committed
Merge branch 'release/3.0.0-RC2'
2 parents ebd80c4 + e232896 commit e7eef99

7 files changed

Lines changed: 31 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
# Change Log
22

3-
## [3.0.0-RC1](https://github.com/TheHive-Project/Cortex/tree/3.0.0-RC1) (2019-04-05)
3+
## [3.0.0-RC2](https://github.com/TheHive-Project/Cortex/tree/3.0.0-RC2) (2019-05-03)
4+
5+
[Full Changelog](https://github.com/TheHive-Project/Cortex/compare/3.0.0-RC1...3.0.0-RC2)
6+
7+
**Fixed bugs:**
8+
9+
- Unable to load Analyzers with 3.0.0 [\#185](https://github.com/TheHive-Project/Cortex/issues/185)
10+
- Cortex will fail to run analyzers [\#182](https://github.com/TheHive-Project/Cortex/issues/182)
11+
- Docker container exposes tcp/9000 instead of tcp/9001 [\#166](https://github.com/TheHive-Project/Cortex/issues/166)
412

13+
## [3.0.0-RC1](https://github.com/TheHive-Project/Cortex/tree/3.0.0-RC1) (2019-04-05)
514
[Full Changelog](https://github.com/TheHive-Project/Cortex/compare/2.1.3...3.0.0-RC1)
615

716
**Implemented enhancements:**

app/org/thp/cortex/models/Job.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ trait JobAttributes {
3636
val fromCache = optionalAttribute("fromCache", F.booleanFmt, "Indicates if cache is used", O.form)
3737
val tpe = attribute("type", F.enumFmt(WorkerType), "", O.readonly)
3838
val lbel = optionalAttribute("label", F.stringFmt, "Label of the job")
39+
val cacheTag = optionalAttribute("cacheTag", F.stringFmt, "hash of job discriminant, used for cache", O.readonly)
3940
}
4041

4142
@Singleton

app/org/thp/cortex/services/JobSrv.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.thp.cortex.models._
2020
import org.elastic4play._
2121
import org.elastic4play.controllers._
2222
import org.elastic4play.services._
23+
import org.elastic4play.utils.Hasher
2324

2425
@Singleton
2526
class JobSrv(
@@ -243,11 +244,10 @@ class JobSrv(
243244
parameters: JsObject,
244245
label: Option[String],
245246
force: Boolean)(implicit authContext: AuthContext): Future[Job] = {
246-
val previousJob = if (force) Future.successful(None)
247-
else findSimilarJob(worker, dataType, dataAttachment, tlp, parameters)
247+
val previousJob = findSimilarJob(worker, dataType, dataAttachment, tlp, parameters, force)
248248
previousJob.flatMap {
249-
case Some(job) Future.successful(job)
250-
case None isUnderRateLimit(worker).flatMap {
249+
case Right(job) Future.successful(job)
250+
case Left(cacheTag) isUnderRateLimit(worker).flatMap {
251251
case true
252252
val fields = Fields(Json.obj(
253253
"workerDefinitionId" worker.workerDefinitionId(),
@@ -260,7 +260,8 @@ class JobSrv(
260260
"pap" pap,
261261
"message" message,
262262
"parameters" parameters.toString,
263-
"type" worker.tpe()))
263+
"type" worker.tpe(),
264+
"cacheTag" cacheTag))
264265
.set("label", label.map(JsString.apply))
265266
val fieldWithData = dataAttachment match {
266267
case Left(data) fields.set("data", data)
@@ -298,28 +299,27 @@ class JobSrv(
298299
.getOrElse(Future.successful(true))
299300
}
300301

301-
def findSimilarJob(worker: Worker, dataType: String, dataAttachment: Either[String, Attachment], tlp: Long, parameters: JsObject): Future[Option[Job]] = {
302-
val cache = worker.jobCache().fold(jobCache)(_.minutes)
303-
if (cache.length == 0 || worker.tpe() == WorkerType.responder) {
302+
def findSimilarJob(worker: Worker, dataType: String, dataAttachment: Either[String, Attachment], tlp: Long, parameters: JsObject, force: Boolean): Future[Either[String, Job]] = {
303+
val cacheTag = Hasher("MD5").fromString(s"${worker.id}|$dataType|$tlp|${dataAttachment.fold(data data, attachment attachment.id)}|$parameters").head.toString()
304+
lazy val cache = worker.jobCache().fold(jobCache)(_.minutes)
305+
if (force || cache.length == 0 || worker.tpe() == WorkerType.responder) {
304306
logger.info("Job cache is disabled")
305-
Future.successful(None)
307+
Future.successful(Left(cacheTag))
306308
}
307309
else {
308310
import org.elastic4play.services.QueryDSL._
309311
logger.info(s"Looking for similar job in the last ${cache.toMinutes} minutes (worker=${worker.id}, dataType=$dataType, data=$dataAttachment, tlp=$tlp, parameters=$parameters)")
312+
310313
val now = new Date().getTime
311314
find(and(
312-
"workerId" ~= worker.id,
315+
"cacheTag" ~= cacheTag,
313316
"status" ~!= JobStatus.Failure,
314317
"status" ~!= JobStatus.Deleted,
315-
"startDate" ~>= (now - cache.toMillis),
316-
"dataType" ~= dataType,
317-
"tlp" ~= tlp,
318-
dataAttachment.fold(data "data" ~= data, attachment "attachment.id" ~= attachment.id),
319-
"parameters" ~= parameters.toString), Some("0-1"), Seq("-createdAt"))
318+
"startDate" ~>= (now - cache.toMillis)), Some("0-1"), Seq("-createdAt"))
320319
._1
321320
.map(j new Job(jobModel, j.attributes + ("fromCache" JsBoolean(true))))
322321
.runWith(Sink.headOption)
322+
.map(_.toRight(cacheTag))
323323
}
324324
}
325325

app/org/thp/cortex/services/WorkerSrv.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class WorkerSrv @Inject() (
160160
def readDirectory(path: Path, workerType: WorkerType.Type): Seq[WorkerDefinition] = {
161161
for {
162162
workerDir Files.newDirectoryStream(path).asScala.toSeq
163+
if Files.isDirectory(workerDir)
163164
infoFile Files.newDirectoryStream(workerDir, "*.json").asScala
164165
workerDefinition readFile(infoFile, workerType)
165166
} yield workerDefinition

docker.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ version in Docker := {
1111
}
1212
defaultLinuxInstallLocation in Docker := "/opt/cortex"
1313
dockerRepository := Some("thehiveproject")
14-
dockerUpdateLatest := !version.value.toUpperCase.contains("RC")
14+
dockerUpdateLatest := !version.value.toUpperCase.contains("RC") && !version.value.contains("SNAPSHOT")
1515
dockerEntrypoint := Seq("/opt/cortex/entrypoint")
16-
dockerExposedPorts := Seq(9000)
16+
dockerExposedPorts := Seq(9001)
1717
mappings in Docker ++= Seq(
1818
file("package/docker/entrypoint") -> "/opt/cortex/entrypoint",
1919
file("package/logback.xml") -> "/etc/cortex/logback.xml",

version.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "3.0.0-RC1"
1+
version in ThisBuild := "3.0.0-RC2"

www/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cortex",
3-
"version": "3.0.0-RC1",
3+
"version": "3.0.0-RC2",
44
"description": "A powerfull observable analysis engine",
55
"license": "AGPL-v3",
66
"homepage": "https://github.com/TheHive-Project/Cortex",

0 commit comments

Comments
 (0)