Skip to content

Commit

Permalink
Reorganise imports and reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Jun 25, 2020
1 parent 67b0344 commit 825eb58
Show file tree
Hide file tree
Showing 100 changed files with 348 additions and 420 deletions.
3 changes: 1 addition & 2 deletions app/org/thp/thehive/CustomServer.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.thp.thehive

import play.core.server.{AkkaHttpServer, ServerProvider}

import akka.http.scaladsl.model.HttpMethod
import akka.http.scaladsl.settings.ParserSettings
import play.core.server.{AkkaHttpServer, ServerProvider}

/** A custom Akka HTTP server with advanced configuration. */
class CustomAkkaHttpServer(context: AkkaHttpServer.Context) extends AkkaHttpServer(context) {
Expand Down
6 changes: 3 additions & 3 deletions client-common/src/main/scala/org/thp/client/BaseClient.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.thp.client

import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

import play.api.Logger
import play.api.http.Status
import play.api.libs.json._
import play.api.libs.ws.{WSClient, WSResponse}

import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

case class ApplicationError(status: Int, body: JsValue) extends Exception(s"ApplicationError($status):\n${Json.prettyPrint(body)}")

object ApplicationError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.thp.thehive.client

import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

import org.thp.client.{ApplicationError, Authentication, BaseClient}
import org.thp.thehive.dto.v1._
import play.api.Logger
import play.api.http.Status
import play.api.libs.json.{JsObject, JsValue, Json}
import play.api.libs.ws.WSClient

import org.thp.client.{ApplicationError, Authentication, BaseClient}
import org.thp.thehive.dto.v1._
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

class TheHiveClient(baseUrl: String)(implicit ws: WSClient) {
lazy val logger: Logger = Logger(getClass)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package org.thp.cortex.client

import scala.concurrent.duration.Duration
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

import akka.stream.Materializer
import akka.stream.scaladsl.Source
import akka.util.ByteString
import org.thp.client._
import org.thp.cortex.dto.v0.{Attachment, _}
import play.api.Logger
import play.api.http.Status
import play.api.libs.json.{Format, JsObject, JsString, Json}
import play.api.libs.ws.WSClient
import play.api.libs.ws.ahc.AhcWSClientConfig
import play.api.mvc.MultipartFormData.{DataPart, FilePart}

import akka.stream.Materializer
import akka.stream.scaladsl.Source
import akka.util.ByteString
import org.thp.client._
import org.thp.cortex.dto.v0.{Attachment, _}
import scala.concurrent.duration.Duration
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

case class CortexClientConfig(
name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ package org.thp.cortex.client
import java.net.URLEncoder
import java.nio.file.{Path, Paths}

import scala.concurrent.ExecutionContext
import scala.io.Source
import scala.util.matching.Regex

import play.api.http.{FileMimeTypes, HttpEntity}
import play.api.libs.json.{JsValue, Json}
import play.api.mvc._
import play.api.test.Helpers._

import akka.stream.scaladsl._
import javax.inject.{Inject, Provider}
import mockws.MockWS
import org.thp.client.NoAuthentication
import org.thp.cortex.dto.v0.{OutputJob, OutputWorker}
import play.api.http.{FileMimeTypes, HttpEntity}
import play.api.libs.json.{JsValue, Json}
import play.api.mvc._
import play.api.test.Helpers._

import scala.concurrent.ExecutionContext
import scala.io.Source
import scala.util.matching.Regex

class TestCortexClientProvider @Inject() (Action: DefaultActionBuilder, implicit val fileMimeTypes: FileMimeTypes, implicit val ec: ExecutionContext)
extends Provider[CortexClient] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.thp.thehive.connector.cortex

import play.api.Logger
import play.api.routing.Router

import javax.inject.{Inject, Provider, Singleton}
import org.thp.thehive.connector.cortex.controllers.v0
import play.api.Logger
import play.api.routing.Router

@Singleton
class CortexRouter @Inject() (routerV0: v0.Router) extends Provider[Router] {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package org.thp.thehive.connector.cortex.controllers.v0

import scala.concurrent.ExecutionContext

import play.api.mvc.{Action, AnyContent, Results}

import akka.actor.ActorSystem
import javax.inject.{Inject, Singleton}
import org.thp.scalligraph.controllers.{Entrypoint, FieldsParser}
import org.thp.thehive.connector.cortex.controllers.v0.Conversion._
import org.thp.thehive.connector.cortex.services.AnalyzerSrv
import org.thp.thehive.controllers.v0.Conversion._
import play.api.mvc.{Action, AnyContent, Results}

import scala.concurrent.ExecutionContext

@Singleton
class AnalyzerCtrl @Inject() (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.scalaland.chimney.dsl._
import org.thp.cortex.dto.v0.{OutputWorker => CortexWorker}
import org.thp.scalligraph.controllers.Renderer
import org.thp.scalligraph.models.Entity
import org.thp.thehive.connector.cortex.dto.v0.{InputAnalyzerTemplate, OutputAction, OutputAnalyzerTemplate, OutputJob, OutputWorker}
import org.thp.thehive.connector.cortex.dto.v0._
import org.thp.thehive.connector.cortex.models._
import play.api.libs.json.{JsArray, JsFalse, Json}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.thp.thehive.connector.cortex.controllers.v0

import javax.inject.{Inject, Singleton}
import play.api.routing.Router.Routes
import play.api.routing.SimpleRouter
import play.api.routing.sird._

import javax.inject.{Inject, Singleton}

@Singleton
class Router @Inject() (
jobCtrl: JobCtrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package org.thp.thehive.connector.cortex.models

import java.util.Date

import play.api.libs.json.JsObject

import gremlin.scala.{Edge, Graph, Vertex}
import org.thp.scalligraph.VertexEntity
import org.thp.scalligraph.models._
import play.api.libs.json.JsObject

@VertexEntity
case class Action(
Expand Down Expand Up @@ -67,6 +66,7 @@ object ActionContext extends HasEdgeModel[ActionContext, Action, Product] {
override def _createdAt: Date = entity._createdAt
override def _updatedAt: Option[Date] = entity._updatedAt
}
override def create(e: ActionContext, from: Vertex, to: Vertex)(implicit db: Database, graph: Graph): Edge = from.addEdge(label, to)
override def create(e: ActionContext, from: Vertex, to: Vertex)(implicit db: Database, graph: Graph): Edge =
from.addEdge(label, to)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package org.thp.thehive.connector.cortex.services

import java.util.Date

import scala.util.{Failure, Success, Try}

import play.api.Logger

import gremlin.scala.Graph
import javax.inject.Inject
import org.thp.scalligraph.InternalError
Expand All @@ -17,6 +13,9 @@ import org.thp.thehive.controllers.v0.Conversion._
import org.thp.thehive.dto.v0.InputTask
import org.thp.thehive.models._
import org.thp.thehive.services._
import play.api.Logger

import scala.util.{Failure, Success, Try}

class ActionOperationSrv @Inject() (
caseSrv: CaseSrv,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.thp.thehive.connector.cortex.services

import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

import play.api.Logger

import javax.inject.{Inject, Singleton}
import org.thp.cortex.dto.v0.{OutputWorker => CortexWorker}
import org.thp.scalligraph.NotFoundError
import org.thp.scalligraph.auth.AuthContext
import play.api.Logger

import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

@Singleton
class AnalyzerSrv @Inject() (connector: Connector, serviceHelper: ServiceHelper, implicit val ec: ExecutionContext) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package org.thp.thehive.connector.cortex.services

import scala.concurrent.duration.FiniteDuration
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

import play.api.libs.json.{JsObject, Json}

import akka.actor.ActorSystem
import akka.stream.Materializer
import javax.inject.{Inject, Singleton}
Expand All @@ -14,6 +8,11 @@ import org.thp.scalligraph.services.config.ApplicationConfig.finiteDurationForma
import org.thp.scalligraph.services.config.{ApplicationConfig, ConfigItem}
import org.thp.thehive.models.HealthStatus
import org.thp.thehive.services.{Connector => TheHiveConnector}
import play.api.libs.json.{JsObject, Json}

import scala.concurrent.duration.FiniteDuration
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}

@Singleton
class Connector @Inject() (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.thp.thehive.connector.cortex.services

import io.scalaland.chimney.dsl._
import org.thp.cortex.dto.v0.{OutputMinireport, OutputArtifact, JobStatus => CortexJobStatus}
import org.thp.cortex.dto.v0.{OutputArtifact, OutputMinireport, JobStatus => CortexJobStatus}
import org.thp.thehive.connector.cortex.models.JobStatus
import org.thp.thehive.models.{Observable, ReportTag, ReportTagLevel}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.thp.thehive.connector.cortex.services

import scala.util.{Failure, Try}

import play.api.Logger

import gremlin.scala.Graph
import javax.inject.{Inject, Singleton}
import org.thp.scalligraph.BadRequestError
Expand All @@ -12,6 +8,9 @@ import org.thp.scalligraph.models.Entity
import org.thp.scalligraph.steps.StepsOps._
import org.thp.thehive.models._
import org.thp.thehive.services._
import play.api.Logger

import scala.util.{Failure, Try}

@Singleton
class EntityHelper @Inject() (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package org.thp.thehive.connector.cortex

import org.thp.scalligraph.models.Database
import org.thp.scalligraph.steps.StepsOps._
import org.thp.thehive.connector.cortex.models.ObservableJob
import org.thp.thehive.services.ObservableSteps

package object services {
implicit class RichObservableSteps(observableSteps: ObservableSteps) {
def jobs: JobSteps = new JobSteps(observableSteps.outTo[ObservableJob].raw)(observableSteps.db, observableSteps.graph)
def jobs: JobSteps =
new JobSteps(observableSteps.outTo[ObservableJob].raw)(observableSteps.db.asInstanceOf[Database], observableSteps.graph)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.thp.thehive.connector.cortex.services

import play.api.test.PlaySpecification

import org.thp.scalligraph.auth.AuthContext
import org.thp.scalligraph.models.{Database, DummyUserSrv}
import org.thp.scalligraph.steps.StepsOps._
import org.thp.thehive.TestAppBuilder
import org.thp.thehive.models.Permissions
import org.thp.thehive.services.{AlertSrv, ObservableSrv, TaskSrv}
import play.api.test.PlaySpecification

class EntityHelperTest extends PlaySpecification with TestAppBuilder {
implicit val authContext: AuthContext =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.thp.thehive.connector.cortex.services

import scala.concurrent.ExecutionContext

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 scala.concurrent.ExecutionContext

@Singleton
class TestConnector @Inject()(client: CortexClient, appConfig: ApplicationConfig, mat: Materializer, system: ActorSystem, ec: ExecutionContext)
class TestConnector @Inject() (client: CortexClient, appConfig: ApplicationConfig, mat: Materializer, system: ActorSystem, ec: ExecutionContext)
extends Connector(appConfig, mat, system, ec) {
override def clients: Seq[CortexClient] = Seq(client)

Expand Down
3 changes: 1 addition & 2 deletions dto/src/main/scala/org/thp/thehive/dto/v0/Alert.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0

import java.util.Date

import play.api.libs.json._

import org.thp.scalligraph.controllers.WithParser
import play.api.libs.json._

case class InputAlert(
`type`: String,
Expand Down
3 changes: 1 addition & 2 deletions dto/src/main/scala/org/thp/thehive/dto/v0/Audit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0

import java.util.Date

import play.api.libs.json._

import org.thp.scalligraph.models.Entity
import play.api.libs.json._

case class OutputEntity(_type: String, _id: String, _createdAt: Date, _createdBy: String, _updatedAt: Option[Date], _updatedBy: Option[String])

Expand Down
3 changes: 1 addition & 2 deletions dto/src/main/scala/org/thp/thehive/dto/v0/Case.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0

import java.util.Date

import play.api.libs.json._

import org.thp.scalligraph.controllers.WithParser
import play.api.libs.json._

case class InputCase(
title: String,
Expand Down
3 changes: 1 addition & 2 deletions dto/src/main/scala/org/thp/thehive/dto/v0/CaseTemplate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0

import java.util.Date

import play.api.libs.json.{JsObject, Json, OFormat, OWrites}

import org.thp.scalligraph.controllers.WithParser
import play.api.libs.json.{JsObject, Json, OFormat, OWrites}

case class InputCaseTemplate(
name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package org.thp.thehive.dto.v0

import java.util.Date

import play.api.libs.json._

import org.scalactic.Accumulation._
import org.scalactic.{Bad, Every, Good, One, Or}
import org.thp.scalligraph.{AttributeError, InvalidFormatAttributeError}
import org.scalactic._
import org.thp.scalligraph.controllers.{FNull, _}
import org.thp.scalligraph.{AttributeError, InvalidFormatAttributeError}
import play.api.libs.json._

case class OutputCustomField(
id: String,
Expand Down
3 changes: 1 addition & 2 deletions dto/src/main/scala/org/thp/thehive/dto/v0/Log.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package org.thp.thehive.dto.v0

import java.util.Date

import play.api.libs.json.{Json, OFormat}

import org.thp.scalligraph.controllers.FFile
import play.api.libs.json.{Json, OFormat}

case class InputLog(message: String, startDate: Option[Date] = None, attachment: Option[FFile] = None)

Expand Down
Loading

0 comments on commit 825eb58

Please sign in to comment.