Skip to content

Commit

Permalink
#1731 Fix dependence injection
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jan 23, 2021
1 parent 0748719 commit 62050db
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 34 deletions.
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ libraryDependencies in ThisBuild ++= {
dependencyOverrides in ThisBuild ++= Seq(
// "org.locationtech.spatial4j" % "spatial4j" % "0.6",
// "org.elasticsearch.client" % "elasticsearch-rest-client" % "6.7.2"
akkaActor
)
PlayKeys.includeDocumentationInBinary := false
milestoneFilter := ((milestone: Milestone) => milestone.title.startsWith("4"))
Expand Down Expand Up @@ -343,8 +344,6 @@ lazy val thehiveMigration = (project in file("migration"))
scopt,
specs % Test
),
dependencyOverrides += akkaActor,
fork := true,
normalizedName := "migrate"
)

Expand Down
4 changes: 2 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v1/PatternCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import play.api.libs.json.{JsArray, Json}
import play.api.mvc.{Action, AnyContent, Results}

import java.io.FileInputStream
import javax.inject.{Inject, Named, Singleton}
import javax.inject.{Inject, Singleton}
import scala.util.{Failure, Success, Try}

@Singleton
class PatternCtrl @Inject() (
entrypoint: Entrypoint,
properties: Properties,
patternSrv: PatternSrv,
@Named("with-thehive-schema") implicit val db: Database
db: Database
) extends QueryableCtrl {
override val entityName: String = "pattern"
override val publicProperties: PublicProperties = properties.pattern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import org.thp.thehive.services.ProcedureOps._
import org.thp.thehive.services.ProcedureSrv
import play.api.mvc.{Action, AnyContent, Results}

import javax.inject.{Inject, Named, Singleton}
import javax.inject.{Inject, Singleton}

@Singleton
class ProcedureCtrl @Inject() (
entrypoint: Entrypoint,
properties: Properties,
procedureSrv: ProcedureSrv,
@Named("with-thehive-schema") implicit val db: Database
db: Database
) extends QueryableCtrl {
override val entityName: String = "procedure"
override val publicProperties: PublicProperties = properties.procedure
Expand Down
4 changes: 2 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v1/ShareCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.thp.thehive.services.TaskOps._
import org.thp.thehive.services._
import play.api.mvc.{Action, AnyContent, Results}

import javax.inject.{Inject, Named}
import javax.inject.Inject
import scala.util.{Failure, Success, Try}

class ShareCtrl @Inject() (
Expand All @@ -30,7 +30,7 @@ class ShareCtrl @Inject() (
taskSrv: TaskSrv,
observableSrv: ObservableSrv,
profileSrv: ProfileSrv,
@Named("with-thehive-schema") implicit val db: Database
db: Database
) extends QueryableCtrl {
override val entityName: String = "share"
override val publicProperties: PublicProperties = properties.share
Expand Down
4 changes: 2 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v1/TaxonomyCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.thp.thehive.services.{TagSrv, TaxonomySrv}
import play.api.libs.json.{JsArray, Json}
import play.api.mvc.{Action, AnyContent, Results}

import javax.inject.{Inject, Named}
import javax.inject.Inject
import scala.collection.JavaConverters._
import scala.util.{Failure, Success, Try}

Expand All @@ -26,7 +26,7 @@ class TaxonomyCtrl @Inject() (
properties: Properties,
taxonomySrv: TaxonomySrv,
tagSrv: TagSrv,
@Named("with-thehive-schema") implicit val db: Database
db: Database
) extends QueryableCtrl
with TaxonomyRenderer {

Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/AlertSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ object AlertOps {
implicit class AlertCustomFieldsOpsDefs(traversal: Traversal.E[AlertCustomField]) extends CustomFieldValueOpsDefs(traversal)
}

class AlertIntegrityCheckOps @Inject() (@Named("with-thehive-schema") val db: Database, val service: AlertSrv) extends IntegrityCheckOps[Alert] {
class AlertIntegrityCheckOps @Inject() (val db: Database, val service: AlertSrv) extends IntegrityCheckOps[Alert] {
override def check(): Unit = {
db.tryTransaction { implicit graph =>
service
Expand Down
6 changes: 3 additions & 3 deletions thehive/app/org/thp/thehive/services/OrganisationSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ import play.api.cache.SyncCacheApi
import play.api.libs.json.JsObject

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

@Singleton
class OrganisationSrv @Inject() (
taxonomySrvProvider: Provider[TaxonomySrv],
// taxonomySrvProvider: Provider[TaxonomySrv],
roleSrv: RoleSrv,
profileSrv: ProfileSrv,
auditSrv: AuditSrv,
userSrv: UserSrv,
@Named("integrity-check-actor") integrityCheckActor: ActorRef,
cache: SyncCacheApi
) extends VertexSrv[Organisation] {
lazy val taxonomySrv: TaxonomySrv = taxonomySrvProvider.get
lazy val taxonomySrv: TaxonomySrv = ??? //taxonomySrvProvider.get
val organisationOrganisationSrv = new EdgeSrv[OrganisationOrganisation, Organisation, Organisation]
val organisationShareSrv = new EdgeSrv[OrganisationShare, Organisation, Share]
val organisationTaxonomySrv = new EdgeSrv[OrganisationTaxonomy, Organisation, Taxonomy]
Expand Down
6 changes: 2 additions & 4 deletions thehive/app/org/thp/thehive/services/PatternSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.thp.thehive.services

import org.thp.scalligraph.EntityIdOrName
import org.thp.scalligraph.auth.AuthContext
import org.thp.scalligraph.models.{Database, Entity}
import org.thp.scalligraph.models.Entity
import org.thp.scalligraph.services._
import org.thp.scalligraph.traversal.TraversalOps._
import org.thp.scalligraph.traversal.{Converter, Graph, Traversal}
Expand All @@ -12,16 +12,14 @@ import org.thp.thehive.services.PatternOps._
import org.thp.thehive.services.ProcedureOps._

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

@Singleton
class PatternSrv @Inject() (
auditSrv: AuditSrv,
caseSrv: CaseSrv,
organisationSrv: OrganisationSrv
)(implicit
@Named("with-thehive-schema") db: Database
) extends VertexSrv[Pattern] {
val patternPatternSrv = new EdgeSrv[PatternPattern, Pattern, Pattern]

Expand Down
7 changes: 2 additions & 5 deletions thehive/app/org/thp/thehive/services/ProcedureSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.thp.thehive.services

import org.thp.scalligraph.EntityIdOrName
import org.thp.scalligraph.auth.AuthContext
import org.thp.scalligraph.models.{Database, Entity}
import org.thp.scalligraph.models.Entity
import org.thp.scalligraph.services._
import org.thp.scalligraph.traversal.TraversalOps.TraversalOpsDefs
import org.thp.scalligraph.traversal.{Converter, Graph, StepLabel, Traversal}
Expand All @@ -11,17 +11,14 @@ import org.thp.thehive.models._
import org.thp.thehive.services.ProcedureOps._

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

@Singleton
class ProcedureSrv @Inject() (
auditSrv: AuditSrv,
caseSrv: CaseSrv,
organisationSrv: OrganisationSrv,
patternSrv: PatternSrv
)(implicit
@Named("with-thehive-schema") db: Database
) extends VertexSrv[Procedure] {
val caseProcedureSrv = new EdgeSrv[CaseProcedure, Case, Procedure]
val procedurePatternSrv = new EdgeSrv[ProcedurePattern, Procedure, Pattern]
Expand Down
2 changes: 1 addition & 1 deletion thehive/app/org/thp/thehive/services/RoleSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import javax.inject.{Inject, Singleton}
import scala.util.Try

@Singleton
class RoleSrv @Inject() (implicit val db: Database) extends VertexSrv[Role] {
class RoleSrv @Inject() extends VertexSrv[Role] {

val roleOrganisationSrv = new EdgeSrv[RoleOrganisation, Role, Organisation]
val userRoleSrv = new EdgeSrv[UserRole, User, Role]
Expand Down
14 changes: 6 additions & 8 deletions thehive/app/org/thp/thehive/services/TaxonomySrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.thp.thehive.services

import org.apache.tinkerpop.gremlin.process.traversal.TextP
import org.thp.scalligraph.auth.AuthContext
import org.thp.scalligraph.models.{Database, Entity}
import org.thp.scalligraph.models.Entity
import org.thp.scalligraph.services.{EdgeSrv, VertexSrv}
import org.thp.scalligraph.traversal.Converter.Identity
import org.thp.scalligraph.traversal.TraversalOps.TraversalOpsDefs
Expand All @@ -13,17 +13,15 @@ import org.thp.thehive.services.OrganisationOps._
import org.thp.thehive.services.TaxonomyOps._

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

@Singleton
class TaxonomySrv @Inject() (
organisationSrv: OrganisationSrv
)(implicit @Named("with-thehive-schema") db: Database)
extends VertexSrv[Taxonomy] {
class TaxonomySrv @Inject() (organisationSrvProvider: Provider[OrganisationSrv]) extends VertexSrv[Taxonomy] {

val taxonomyTagSrv = new EdgeSrv[TaxonomyTag, Taxonomy, Tag]
val organisationTaxonomySrv = new EdgeSrv[OrganisationTaxonomy, Organisation, Taxonomy]
lazy val organisationSrv: OrganisationSrv = organisationSrvProvider.get
val taxonomyTagSrv = new EdgeSrv[TaxonomyTag, Taxonomy, Tag]
val organisationTaxonomySrv = new EdgeSrv[OrganisationTaxonomy, Organisation, Taxonomy]

def create(taxo: Taxonomy, tags: Seq[Tag with Entity])(implicit graph: Graph, authContext: AuthContext): Try[RichTaxonomy] =
for {
Expand Down
3 changes: 1 addition & 2 deletions thehive/app/org/thp/thehive/services/UserSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class UserSrv @Inject() (
roleSrv: RoleSrv,
auditSrv: AuditSrv,
attachmentSrv: AttachmentSrv,
@Named("integrity-check-actor") integrityCheckActor: ActorRef,
implicit val db: Database
@Named("integrity-check-actor") integrityCheckActor: ActorRef
) extends VertexSrv[User] {
val defaultUserDomain: Option[String] = configuration.getOptional[String]("auth.defaultUserDomain")
val fullUserNameRegex: Pattern = "[\\p{Graph}&&[^@.]](?:[\\p{Graph}&&[^@]]*)*@\\p{Alnum}+(?:[\\p{Alnum}-.])*".r.pattern
Expand Down

0 comments on commit 62050db

Please sign in to comment.