Skip to content

Commit

Permalink
wip - migrate to play 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinovega committed Nov 8, 2023
1 parent 22c09c4 commit 1f344bc
Show file tree
Hide file tree
Showing 35 changed files with 340 additions and 279 deletions.
26 changes: 13 additions & 13 deletions daikoku/app/audit/audit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import akka.http.scaladsl.util.FastFuture
import akka.http.scaladsl.util.FastFuture._
import akka.kafka.ProducerSettings
import akka.stream.scaladsl.{Keep, Sink, Source}
import akka.stream.{OverflowStrategy, QueueOfferResult}
import akka.stream.{Materializer, OverflowStrategy, QueueOfferResult}
import cats.data.EitherT
import controllers.AppError
import fr.maif.otoroshi.daikoku.audit.config.{ElasticAnalyticsConfig, Webhook}
Expand Down Expand Up @@ -231,10 +231,10 @@ object AuditActor {

class AuditActor(implicit env: Env, messagesApi: MessagesApi, translator: Translator) extends Actor {

implicit lazy val ec = env.defaultExecutionContext
implicit lazy val ec: ExecutionContext = env.defaultExecutionContext

lazy val logger = Logger("audit-actor")
lazy val console = Logger("audit-console")
lazy val logger: Logger = Logger("audit-actor")
lazy val console: Logger = Logger("audit-console")

lazy val kafkaWrapperAudit =
new KafkaWrapper(env.defaultActorSystem, env, _.auditTopic)
Expand Down Expand Up @@ -434,7 +434,7 @@ case class KafkaConfig(servers: Seq[String],
)

object KafkaConfig {
implicit val format = Json.format[KafkaConfig]
implicit val format: OFormat[KafkaConfig] = Json.format[KafkaConfig]
}

object KafkaSettings {
Expand Down Expand Up @@ -497,12 +497,12 @@ class KafkaWrapper(actorSystem: ActorSystem,
class KafkaWrapperActor(env: Env, topicFunction: KafkaConfig => String)
extends Actor {

implicit val ec = env.defaultExecutionContext
implicit val ec: ExecutionContext = env.defaultExecutionContext

var config: Option[KafkaConfig] = None
var eventProducer: Option[KafkaEventProducer] = None

lazy val logger = play.api.Logger("kafka-wrapper")
lazy val logger: Logger = play.api.Logger("kafka-wrapper")

override def receive: Receive = {
case event: KafkaWrapperEvent
Expand Down Expand Up @@ -546,9 +546,9 @@ class KafkaEventProducer(_env: Env,
config: KafkaConfig,
topicFunction: KafkaConfig => String) {

implicit val ec = _env.defaultExecutionContext
implicit val ec: ExecutionContext = _env.defaultExecutionContext

lazy val logger = play.api.Logger("kafka-connector")
lazy val logger: Logger = play.api.Logger("kafka-connector")

lazy val topic = topicFunction(config)

Expand All @@ -557,10 +557,10 @@ class KafkaEventProducer(_env: Env,
private lazy val producerSettings =
KafkaSettings.producerSettings(_env, config)
private lazy val producer: Producer[Array[Byte], String] =
producerSettings.createKafkaProducer
producerSettings.createKafkaProducer()

def publish(event: JsValue): Future[Done] = {
val promise = Promise[RecordMetadata]
val promise = Promise[RecordMetadata]()
try {
val message = Json.stringify(event)
producer.send(new ProducerRecord[Array[Byte], String](topic, message),
Expand Down Expand Up @@ -664,7 +664,7 @@ class ElasticWritesAnalytics(config: ElasticAnalyticsConfig, env: Env) {
private val index: String = config.index.getOrElse("otoroshi-events")
private val `type`: String = config.`type`.getOrElse("event")
private val searchUri = urlFromPath(s"/$index*/_search")
private implicit val mat = env.defaultMaterializer
private implicit val mat: Materializer = env.defaultMaterializer

private def url(url: String): WSRequest = {
val builder = env.wsClient.url(url)
Expand Down Expand Up @@ -815,7 +815,7 @@ class ElasticReadsAnalytics(config: ElasticAnalyticsConfig, env: Env) {
private val index: String = config.index.getOrElse("otoroshi-events")
private val `type`: String = config.`type`.getOrElse("event")
private val searchUri = urlFromPath(s"/$index*/_search")
private implicit val mat = env.defaultMaterializer
private implicit val mat: Materializer = env.defaultMaterializer

private def url(url: String): WSRequest = {
val builder = env.wsClient.url(url)
Expand Down
4 changes: 2 additions & 2 deletions daikoku/app/audit/config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ case class ElasticAnalyticsConfig(
}

object ElasticAnalyticsConfig {
val format = new Format[ElasticAnalyticsConfig] {
val format: Format[ElasticAnalyticsConfig] = new Format[ElasticAnalyticsConfig] {
override def writes(o: ElasticAnalyticsConfig) = {
Json.obj(
"clusterUri" -> o.clusterUri,
Expand Down Expand Up @@ -57,5 +57,5 @@ case class Webhook(url: String,
}

object Webhook {
implicit val format = Json.format[Webhook]
implicit val format: OFormat[Webhook] = Json.format[Webhook]
}
23 changes: 13 additions & 10 deletions daikoku/app/controllers/AdminApiController.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package fr.maif.otoroshi.daikoku.ctrls

import akka.http.scaladsl.util.FastFuture
import akka.stream.Materializer
import akka.stream.scaladsl.Source
import akka.util.ByteString
import cats.implicits._
import fr.maif.otoroshi.daikoku.actions.{DaikokuAction, DaikokuActionContext}
Expand All @@ -20,6 +22,7 @@ import play.api.mvc._
import storage.drivers.postgres.PostgresDataStore
import storage.{DataStore, Repo}

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

class StateController(DaikokuAction: DaikokuAction,
Expand All @@ -29,11 +32,11 @@ class StateController(DaikokuAction: DaikokuAction,
pgPool: PgPool)
extends AbstractController(cc) {

implicit val ec = env.defaultExecutionContext
implicit val mat = env.defaultMaterializer
implicit val ev = env
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val mat: Materializer = env.defaultMaterializer
implicit val ev: Env = env

val bodyParser = BodyParser("Import parser") { _ =>
val bodyParser: BodyParser[Source[ByteString, _]] = BodyParser("Import parser") { _ =>
Accumulator.source[ByteString].map(Right.apply)
}

Expand Down Expand Up @@ -184,11 +187,11 @@ class StateAdminApiController(
cc: ControllerComponents)
extends AbstractController(cc) {

implicit val ec = env.defaultExecutionContext
implicit val mat = env.defaultMaterializer
implicit val ev = env
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val mat: Materializer = env.defaultMaterializer
implicit val ev: Env = env

val bodyParser = BodyParser("Import parser") { _ =>
val bodyParser: BodyParser[Source[ByteString, _]] = BodyParser("Import parser") { _ =>
Accumulator.source[ByteString].map(Right.apply)
}

Expand Down Expand Up @@ -405,8 +408,8 @@ class CredentialsAdminApiController(DaikokuApiAction: DaikokuApiAction,
env: Env,
cc: ControllerComponents)
extends AbstractController(cc) {
implicit val ec = env.defaultExecutionContext
implicit val ev = env
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val ev: Env = env

def getCredentials(token: String) = DaikokuApiAction.async { ctx =>
env.dataStore.apiSubscriptionRepo
Expand Down
12 changes: 6 additions & 6 deletions daikoku/app/controllers/ApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import play.api.libs.json._
import play.api.libs.streams.Accumulator
import play.api.mvc._

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

class ApiController(
Expand All @@ -51,11 +51,11 @@ class ApiController(
) extends AbstractController(cc)
with I18nSupport {

implicit val ec = env.defaultExecutionContext
implicit val ev = env
implicit val tr = translator
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val ev: Env = env
implicit val tr: Translator = translator

val logger = Logger("ApiController")
val logger: Logger = Logger("ApiController")

def me() =
DaikokuAction.async { ctx =>
Expand Down Expand Up @@ -210,7 +210,7 @@ class ApiController(
ctx.setCtxValue("team.name", team.name)
ctx.setCtxValue("team.id", team.id)

FastFuture.successful(Right(Ok(team.toUiPayload)))
FastFuture.successful(Right(Ok(team.toUiPayload())))
}
}

Expand Down
6 changes: 4 additions & 2 deletions daikoku/app/controllers/AuditTrailController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import org.joda.time.DateTime
import play.api.libs.json.{JsArray, Json}
import play.api.mvc.{AbstractController, ControllerComponents}

import scala.concurrent.ExecutionContext

class AuditTrailController(DaikokuAction: DaikokuAction,
env: Env,
otoroshiClient: OtoroshiClient,
cc: ControllerComponents)
extends AbstractController(cc) {

implicit val ec = env.defaultExecutionContext
implicit val ev = env
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val ev: Env = env

def auditTrail() = DaikokuAction.async { ctx =>
val from = ctx.request
Expand Down
6 changes: 4 additions & 2 deletions daikoku/app/controllers/EntitiesController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import org.mindrot.jbcrypt.BCrypt
import play.api.libs.json.Json
import play.api.mvc._

import scala.concurrent.ExecutionContext

class EntitiesController(DaikokuAction: DaikokuAction,
env: Env,
cc: ControllerComponents)
extends AbstractController(cc) {

implicit val ec = env.defaultExecutionContext
implicit val ev = env
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val ev: Env = env

def newTenant() = DaikokuAction.async { ctx =>
PublicUserAccess(
Expand Down
8 changes: 4 additions & 4 deletions daikoku/app/controllers/GraphQLController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import sangria.renderer.SchemaRenderer
import storage.DataStore

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

Expand All @@ -31,12 +31,12 @@ class GraphQLController(
extends AbstractController(cc)
with I18nSupport {

implicit val ec = env.defaultExecutionContext
implicit val ev = env
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val ev: Env = env

lazy val (schema, resolver) = SchemaDefinition.getSchema(env)

val logger = Logger("GraphQLController")
val logger: Logger = Logger("GraphQLController")

def adminApiSearch() = DaikokuApiAction.async(parse.json) { ctx =>
val query = (ctx.request.body \ "query").as[String]
Expand Down
12 changes: 6 additions & 6 deletions daikoku/app/controllers/HomeController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import fr.maif.otoroshi.daikoku.domain.json.CmsPageFormat
import fr.maif.otoroshi.daikoku.env.Env
import fr.maif.otoroshi.daikoku.utils.{Errors, IdGenerator, diff_match_patch}
import org.joda.time.DateTime
import play.api.i18n.I18nSupport
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.libs.json._
import play.api.mvc._

import java.io.{ByteArrayOutputStream, File, FileInputStream, FileOutputStream}
import java.util
import java.util.concurrent.TimeUnit
import java.util.zip.{ZipEntry, ZipInputStream, ZipOutputStream}
import scala.concurrent.Future
import scala.concurrent.{ExecutionContext, Future}
import scala.concurrent.duration.DurationInt

class HomeController(
Expand All @@ -32,9 +32,9 @@ class HomeController(
extends AbstractController(cc)
with I18nSupport {

implicit val ec = env.defaultExecutionContext
implicit val e = env
implicit val m = messagesApi
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val e: Env = env
implicit val m: MessagesApi = messagesApi

case class CmsPageCache(contentType: String, content: String)

Expand Down Expand Up @@ -288,7 +288,7 @@ class HomeController(
val cacheId =
s"${ctx.user.map(_.id.value).getOrElse("")}-${r.path.getOrElse("")}"

cache.policy
cache.policy()
.expireAfterWrite()
.ifPresent(eviction => {
val ttl: Long = ctx.tenant.style
Expand Down
15 changes: 4 additions & 11 deletions daikoku/app/controllers/IntegrationApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,22 @@ import controllers.AppError
import fr.maif.otoroshi.daikoku.actions._
import fr.maif.otoroshi.daikoku.audit.AuditTrailEvent
import fr.maif.otoroshi.daikoku.ctrls.authorizations.async.TenantAdminAccessTenant
import fr.maif.otoroshi.daikoku.domain.{
Api,
ApiState,
ApiVisibility,
Team,
UsagePlan,
json
}
import fr.maif.otoroshi.daikoku.domain.{Api, ApiState, ApiVisibility, Team, UsagePlan, json}
import fr.maif.otoroshi.daikoku.env.Env
import fr.maif.otoroshi.daikoku.utils.StringImplicits._
import fr.maif.otoroshi.daikoku.utils.future._
import play.api.libs.json.{JsArray, JsObject, Json}
import play.api.mvc.{AbstractController, ControllerComponents, Result}

import scala.concurrent.Future
import scala.concurrent.{ExecutionContext, Future}

class IntegrationApiController(DaikokuAction: DaikokuAction,
env: Env,
cc: ControllerComponents)
extends AbstractController(cc) {

implicit val ec = env.defaultExecutionContext
implicit val ev = env
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val ev: Env = env

def findById(ctx: DaikokuActionContext[_],
teamId: String,
Expand Down
6 changes: 4 additions & 2 deletions daikoku/app/controllers/JobsController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import jobs.{ApiKeyStatsJob, AuditTrailPurgeJob, OtoroshiVerifierJob}
import play.api.libs.json.Json
import play.api.mvc.{AbstractController, ControllerComponents}

import scala.concurrent.ExecutionContext

class JobsController(otoroshiVerifierJob: OtoroshiVerifierJob,
apiKeyStatsJob: ApiKeyStatsJob,
auditTrailPurgeJob: AuditTrailPurgeJob,
Expand All @@ -15,8 +17,8 @@ class JobsController(otoroshiVerifierJob: OtoroshiVerifierJob,
otoroshiClient: OtoroshiClient)
extends AbstractController(cc) {

implicit val ec = env.defaultExecutionContext
implicit val ev = env
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val ev: Env = env

def otoroshiSyncJob() = Action.async { req =>
if (env.config.otoroshiSyncByCron) {
Expand Down
4 changes: 2 additions & 2 deletions daikoku/app/controllers/LoginController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LoginController(DaikokuAction: DaikokuAction,
extends AbstractController(cc) {
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val ev: Env = env
implicit val tr = translator
implicit val tr: Translator = translator

def loginPage(provider: String) = DaikokuTenantAction.async { ctx =>
AuthProvider(provider) match {
Expand Down Expand Up @@ -706,7 +706,7 @@ class LoginController(DaikokuAction: DaikokuAction,
else
FastFuture.successful(
BadRequest(Json.obj("error" -> "Invalid code")))
case None =>
case _ =>
FastFuture.successful(
BadRequest(Json.obj("error" -> "Invalid token")))
}
Expand Down
7 changes: 4 additions & 3 deletions daikoku/app/controllers/MessageController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import play.api.libs.json._
import play.api.mvc.{AbstractController, ControllerComponents}

import java.util.UUID.randomUUID
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

class MessageController(DaikokuAction: DaikokuAction,
Expand All @@ -32,10 +33,10 @@ class MessageController(DaikokuAction: DaikokuAction,
extends AbstractController(cc)
with I18nSupport {

implicit val ec = env.defaultExecutionContext
implicit val ev = env
implicit val ec: ExecutionContext = env.defaultExecutionContext
implicit val ev: Env = env
implicit val timeout: Timeout = Timeout(5.seconds)
implicit val tr = translator
implicit val tr: Translator = translator

val messageActor: ActorRef =
env.defaultActorSystem.actorOf(Props(new MessageActor()), "messages")
Expand Down
Loading

0 comments on commit 1f344bc

Please sign in to comment.