Skip to content

Commit

Permalink
#279 Add support of ES7
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Aug 12, 2020
1 parent 8cd3e45 commit 276f79b
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 202 deletions.
4 changes: 1 addition & 3 deletions app/org/thp/cortex/controllers/StatusCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ import play.api.libs.json.Json.toJsFieldJsValueWrapper
import play.api.libs.json.{JsBoolean, JsString, Json}
import play.api.mvc.{AbstractController, Action, AnyContent, ControllerComponents}

import com.sksamuel.elastic4s.http.ElasticDsl
import com.sksamuel.elastic4s.ElasticDsl
import javax.inject.{Inject, Singleton}
import org.elasticsearch.client.Node
import org.thp.cortex.models.Worker

import org.elastic4play.database.DBIndex
import org.elastic4play.services.AuthSrv
import org.elastic4play.services.auth.MultiAuthSrv

@Singleton
class StatusCtrl @Inject()(
configuration: Configuration,
authSrv: AuthSrv,
dbIndex: DBIndex,
components: ControllerComponents,
implicit val ec: ExecutionContext
) extends AbstractController(components)
Expand Down
6 changes: 2 additions & 4 deletions app/org/thp/cortex/models/Migration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import org.thp.cortex.services.{OrganizationSrv, UserSrv, WorkerSrv}

import org.elastic4play.controllers.Fields
import org.elastic4play.services.Operation._
import org.elastic4play.services.{DatabaseState, IndexType, MigrationOperations, Operation}
import org.elastic4play.services.{DatabaseState, MigrationOperations, Operation}
import org.elastic4play.utils.Hasher

@Singleton
class Migration @Inject()(userSrv: UserSrv, organizationSrv: OrganizationSrv, workerSrv: WorkerSrv, implicit val ec: ExecutionContext)
extends MigrationOperations {

lazy val logger = Logger(getClass)
lazy val logger: Logger = Logger(getClass)
def beginMigration(version: Int): Future[Unit] = Future.successful(())

def endMigration(version: Int): Future[Unit] =
Expand All @@ -28,8 +28,6 @@ class Migration @Inject()(userSrv: UserSrv, organizationSrv: OrganizationSrv, wo
.transform(_ Success(())) // ignore errors (already exist)
}

override def indexType(version: Int): IndexType.Value = if (version > 3) IndexType.indexWithoutMappingTypes else IndexType.indexWithMappingTypes

val operations: PartialFunction[DatabaseState, Seq[Operation]] = {
case DatabaseState(1)
val hasher = Hasher("MD5")
Expand Down
4 changes: 2 additions & 2 deletions app/org/thp/cortex/models/Roles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package org.thp.cortex.models

import play.api.libs.json.{JsString, JsValue}

import com.sksamuel.elastic4s.http.ElasticDsl.keywordField
import com.sksamuel.elastic4s.mappings.KeywordField
import com.sksamuel.elastic4s.ElasticDsl.keywordField
import com.sksamuel.elastic4s.requests.mappings.KeywordField
import org.scalactic.{Every, Good, One, Or}

import org.elastic4play.{AttributeError, InvalidFormatAttributeError}
Expand Down
5 changes: 1 addition & 4 deletions app/org/thp/cortex/services/JobRunnerSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ class JobRunnerSrv @Inject()(
attachmentSrv
.source(attachment.id)
.runWith(FileIO.toPath(attachmentFile))
.flatMap {
case ioresult if ioresult.status.isSuccess Future.successful(Some(attachmentFile))
case ioresult Future.failed(ioresult.getError)
}
.map(_ => Some(attachmentFile))
}
.getOrElse(Future.successful(None))
.map {
Expand Down
2 changes: 1 addition & 1 deletion app/org/thp/cortex/services/JobSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class JobSrv(

private def withUserFilter[A](userId: String)(x: String (Source[A, NotUsed], Future[Long])): (Source[A, NotUsed], Future[Long]) = {
val a = userSrv.getOrganizationId(userId).map(x)
val aSource = Source.fromFutureSource(a.map(_._1)).mapMaterializedValue(_ NotUsed)
val aSource = Source.futureSource(a.map(_._1)).mapMaterializedValue(_ NotUsed)
val aTotal = a.flatMap(_._2)
aSource aTotal
}
Expand Down
2 changes: 1 addition & 1 deletion app/org/thp/cortex/services/UserSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class UserSrv(
} yield findForOrganization(organizationId, queryDef, range, sortBy))
.recover { case NotFoundError("user init not found") Source.empty Future.successful(0L) }

val userSource = Source.fromFutureSource(users.map(_._1)).mapMaterializedValue(_ NotUsed)
val userSource = Source.futureSource(users.map(_._1)).mapMaterializedValue(_ NotUsed)
val userTotal = users.flatMap(_._2)
userSource userTotal
}
Expand Down
2 changes: 1 addition & 1 deletion app/org/thp/cortex/services/WorkerConfigSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ trait WorkerConfigSrv {
val configs = userSrv
.getOrganizationId(userId)
.map(organizationId findForOrganization(organizationId, queryDef, range, sortBy))
val configSource = Source.fromFutureSource(configs.map(_._1)).mapMaterializedValue(_ NotUsed)
val configSource = Source.futureSource(configs.map(_._1)).mapMaterializedValue(_ NotUsed)
val configTotal = configs.flatMap(_._2)
configSource configTotal
}
Expand Down
4 changes: 2 additions & 2 deletions app/org/thp/cortex/services/WorkerSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class WorkerSrv @Inject()(
user userSrv.get(userId)
organizationId = user.organization()
} yield findForOrganization(organizationId, and(queryDef, "type" ~= WorkerType.analyzer), range, sortBy)
val analyserSource = Source.fromFutureSource(analyzers.map(_._1)).mapMaterializedValue(_ NotUsed)
val analyserSource = Source.futureSource(analyzers.map(_._1)).mapMaterializedValue(_ NotUsed)
val analyserTotal = analyzers.flatMap(_._2)
analyserSource analyserTotal
}
Expand All @@ -110,7 +110,7 @@ class WorkerSrv @Inject()(
user userSrv.get(userId)
organizationId = user.organization()
} yield findForOrganization(organizationId, and(queryDef, "type" ~= WorkerType.responder), range, sortBy)
val analyserSource = Source.fromFutureSource(responders.map(_._1)).mapMaterializedValue(_ NotUsed)
val analyserSource = Source.futureSource(responders.map(_._1)).mapMaterializedValue(_ NotUsed)
val analyserTotal = responders.flatMap(_._2)
analyserSource analyserTotal
}
Expand Down
14 changes: 1 addition & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Common._

lazy val cortex = (project in file("."))
.enablePlugins(PlayScala)
.enablePlugins(Bintray)
.settings(projectSettings)

libraryDependencies ++= Seq(
Expand Down Expand Up @@ -33,15 +32,4 @@ packageBin := {
(packageBin in Debian).value
(packageBin in Rpm).value
(packageBin in Universal).value
}

// Bintray //
bintrayOrganization := Some("thehive-project")
bintrayRepository := "cortex"
publish := {
(publish in Docker).value
publishRelease.value
publishLatest.value
publishRpm.value
publishDebian.value
}
}
167 changes: 0 additions & 167 deletions project/Bintray.scala

This file was deleted.

2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Dependencies {

val reflections = "org.reflections" % "reflections" % "0.9.11"
val zip4j = "net.lingala.zip4j" % "zip4j" % "1.3.2"
val elastic4play = "org.thehive-project" %% "elastic4play" % "1.11.5"
val elastic4play = "org.thehive-project" %% "elastic4play" % "1.12.0-SNAPSHOT"
val dockerClient = "com.spotify" % "docker-client" % "8.14.4"
val akkaCluster = "com.typesafe.akka" %% "akka-cluster" % "2.5.21"
}
Expand Down
5 changes: 2 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
logLevel := Level.Info

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.23")
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.1")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")

0 comments on commit 276f79b

Please sign in to comment.