Skip to content
This repository has been archived by the owner on Feb 12, 2025. It is now read-only.

Commit

Permalink
TheHive-Project#1782 Simplify update status
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Feb 10, 2021
1 parent fefc923 commit fabe574
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package org.thp.thehive.connector.cortex.services

import akka.actor.ActorSystem
import akka.stream.Materializer

import javax.inject.{Inject, Singleton}
import org.thp.cortex.client.{CortexClient, CortexClientConfig}
import org.thp.scalligraph.models.SchemaStatus
import org.thp.scalligraph.services.config.ApplicationConfig.finiteDurationFormat
import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem}
import org.thp.thehive.connector.cortex.models.CortexSchemaDefinition
import org.thp.thehive.models.HealthStatus
import org.thp.thehive.services.{Connector => TheHiveConnector}
import play.api.libs.json.{JsObject, Json}
Expand All @@ -21,7 +17,6 @@ import scala.util.{Failure, Success}
@Singleton
class Connector @Inject() (
appConfig: ApplicationConfig,
schemaDefinition: CortexSchemaDefinition,
mat: Materializer,
implicit val system: ActorSystem,
implicit val ec: ExecutionContext
Expand Down Expand Up @@ -89,6 +84,4 @@ class Connector @Inject() (
system.scheduler.scheduleOnce(statusCheckInterval)(updateStatus())
}
updateStatus()

override def schemaStatus: Option[SchemaStatus] = schemaDefinition.schemaStatus
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ package org.thp.thehive.connector.cortex.services

import akka.actor.ActorSystem
import akka.stream.Materializer

import javax.inject.{Inject, Singleton}
import org.thp.cortex.client.CortexClient
import org.thp.scalligraph.services.config.ApplicationConfig
import org.thp.thehive.connector.cortex.models.CortexSchemaDefinition

import javax.inject.{Inject, Singleton}
import scala.concurrent.ExecutionContext
Expand All @@ -15,11 +12,10 @@ import scala.concurrent.ExecutionContext
class TestConnector @Inject() (
client: CortexClient,
appConfig: ApplicationConfig,
schemaDefinition: CortexSchemaDefinition,
mat: Materializer,
system: ActorSystem,
ec: ExecutionContext
) extends Connector(appConfig, schemaDefinition, mat, system, ec) {
) extends Connector(appConfig, mat, system, ec) {
override def clients: Seq[CortexClient] = Seq(client)

override protected def updateHealth(): Unit = ()
Expand Down
8 changes: 4 additions & 4 deletions thehive/app/org/thp/thehive/controllers/v0/StatusCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package org.thp.thehive.controllers.v0

import org.thp.scalligraph.auth.{AuthCapability, AuthSrv, MultiAuthSrv}
import org.thp.scalligraph.controllers.Entrypoint
import org.thp.scalligraph.models.Database
import org.thp.scalligraph.models.{Database, UpdatableSchema}
import org.thp.scalligraph.services.config.ApplicationConfig.finiteDurationFormat
import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem}
import org.thp.scalligraph.{EntityName, ScalligraphApplicationLoader}
import org.thp.thehive.TheHiveModule
import org.thp.thehive.models.{HealthStatus, TheHiveSchemaDefinition, User}
import org.thp.thehive.models.{HealthStatus, User}
import org.thp.thehive.services.{Connector, UserSrv}
import play.api.libs.json.{JsObject, JsString, Json}
import play.api.mvc.{AbstractController, Action, AnyContent, Results}
Expand All @@ -24,7 +24,7 @@ class StatusCtrl @Inject() (
authSrv: AuthSrv,
userSrv: UserSrv,
connectors: immutable.Set[Connector],
theHiveSchemaDefinition: TheHiveSchemaDefinition,
schemas: immutable.Set[UpdatableSchema],
db: Database
) {

Expand Down Expand Up @@ -57,7 +57,7 @@ class StatusCtrl @Inject() (
"ssoAutoLogin" -> authSrv.capabilities.contains(AuthCapability.sso),
"pollingDuration" -> streamPollingDuration.toMillis
),
"schemaStatus" -> (connectors.flatMap(_.schemaStatus) ++ theHiveSchemaDefinition.schemaStatus).map { schemaStatus =>
"schemaStatus" -> schemas.flatMap(_.schemaStatus).map { schemaStatus =>
Json.obj(
"name" -> schemaStatus.name,
"currentVersion" -> schemaStatus.currentVersion,
Expand Down
8 changes: 3 additions & 5 deletions thehive/app/org/thp/thehive/controllers/v1/StatusCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import akka.cluster.{Cluster, Member}
import org.thp.scalligraph.ScalligraphApplicationLoader
import org.thp.scalligraph.auth.{AuthCapability, AuthSrv, MultiAuthSrv}
import org.thp.scalligraph.controllers.Entrypoint
import org.thp.scalligraph.models.UpdatableSchema
import org.thp.scalligraph.services.config.ApplicationConfig.finiteDurationFormat
import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem}
import org.thp.thehive.TheHiveModule
import org.thp.thehive.models.TheHiveSchemaDefinition
import org.thp.thehive.services.Connector
import play.api.libs.json.{JsObject, JsString, Json, Writes}
import play.api.mvc.{AbstractController, Action, AnyContent, Results}

Expand All @@ -24,8 +23,7 @@ class StatusCtrl @Inject() (
entrypoint: Entrypoint,
appConfig: ApplicationConfig,
authSrv: AuthSrv,
connectors: immutable.Set[Connector],
theHiveSchemaDefinition: TheHiveSchemaDefinition,
schemas: immutable.Set[UpdatableSchema],
system: ActorSystem
) {

Expand Down Expand Up @@ -78,7 +76,7 @@ class StatusCtrl @Inject() (
"pollingDuration" -> streamPollingDuration.toMillis
),
"cluster" -> cluster.state,
"schemaStatus" -> (connectors.flatMap(_.schemaStatus) ++ theHiveSchemaDefinition.schemaStatus).map { schemaStatus =>
"schemaStatus" -> schemas.flatMap(_.schemaStatus).map { schemaStatus =>
Json.obj(
"name" -> schemaStatus.name,
"currentVersion" -> schemaStatus.currentVersion,
Expand Down
6 changes: 2 additions & 4 deletions thehive/app/org/thp/thehive/services/Connector.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.thp.thehive.services

import org.thp.scalligraph.models.SchemaStatus
import org.thp.thehive.models.HealthStatus
import play.api.libs.json.{JsObject, Json}

trait Connector {
val name: String
def status: JsObject = Json.obj("enabled" -> true)
def health: HealthStatus.Value = HealthStatus.Ok
def schemaStatus: Option[SchemaStatus] = None
def status: JsObject = Json.obj("enabled" -> true)
def health: HealthStatus.Value = HealthStatus.Ok
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.thp.thehive.controllers.v0

import org.thp.scalligraph.models.SchemaStatus
import org.thp.scalligraph.{AppBuilder, ScalligraphApplicationLoader}
import org.thp.thehive.models.HealthStatus
import org.thp.thehive.services.Connector
Expand Down Expand Up @@ -29,8 +28,6 @@ class StatusCtrlTest extends PlaySpecification with TestAppBuilder {
)

override def health: HealthStatus.Value = HealthStatus.Warning

override def schemaStatus: Option[SchemaStatus] = None
}

override def appConfigure: AppBuilder = super.appConfigure.multiBindInstance[Connector](fakeCortexConnector)
Expand Down

0 comments on commit fabe574

Please sign in to comment.