Skip to content

Commit

Permalink
Expirable consents
Browse files Browse the repository at this point in the history
  • Loading branch information
larousso committed Oct 11, 2024
1 parent 2234afa commit a12fcb8
Show file tree
Hide file tree
Showing 87 changed files with 703 additions and 573 deletions.
13 changes: 11 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import ReleaseTransformations._
import Dependencies._scalaVersion
import ReleaseTransformations.*

name := """nio"""
organization := "fr.maif"
scalaVersion := "2.13.11"
scalaVersion := _scalaVersion

lazy val root = (project in file("."))
.aggregate(
Expand All @@ -13,6 +14,14 @@ lazy val root = (project in file("."))
lazy val `nio-server` = project
lazy val `nio-provider` = project

inThisBuild(
List(
scalaVersion := _scalaVersion,
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision
)
)

releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies, // : ReleaseStep
inquireVersions, // : ReleaseStep
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
- 27017:27017

zookeeper:
image: confluentinc/cp-zookeeper:3.2.1
image: confluentinc/cp-zookeeper:5.2.3
ports:
- 32182:32181
expose:
Expand All @@ -16,7 +16,7 @@ services:
- ZOOKEEPER_TICK_TIME=2000

kafka:
image: confluentinc/cp-kafka:3.2.1
image: confluentinc/cp-kafka:5.2.3
ports:
- 29092:29092
expose:
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
ports:
- 27017:27017
zookeeper:
image: confluentinc/cp-zookeeper:3.2.1
image: confluentinc/cp-zookeeper:5.2.3
ports:
- 32182:32181
environment:
Expand All @@ -15,7 +15,7 @@ services:
- "moby:127.0.0.1"
- "localhost: 127.0.0.1"
kafka:
image: confluentinc/cp-kafka:3.2.1
image: confluentinc/cp-kafka:5.2.3
ports:
- 29092:29092
depends_on:
Expand Down
2 changes: 1 addition & 1 deletion manual/build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := """nio-manual"""
organization := "fr.maif"
version := "2.0.4"
scalaVersion := "2.12.4"
scalaVersion := _scalaVersion

lazy val docs = (project in file("."))
.enablePlugins(ParadoxPlugin)
Expand Down
5 changes: 2 additions & 3 deletions nio-provider/app/actor/EventActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import play.api.libs.json.Json
import utils.NioLogger

object EventActor {
def props(out: ActorRef) = Props(new EventActor(out))
def props(out: ActorRef): Props = Props(new EventActor(out))
}

class EventActor(out: ActorRef) extends Actor {

override def preStart =
context.system.eventStream.subscribe(self, classOf[NioEvent])
override def preStart(): Unit = context.system.eventStream.subscribe(self, classOf[NioEvent])

override def receive: Receive = { case e: NioEvent =>
NioLogger.info(s"Event actor received a message : ${e.tYpe}")
Expand Down
2 changes: 1 addition & 1 deletion nio-provider/app/configuration/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import scala.concurrent.duration.FiniteDuration

object NioConfiguration {
import pureconfig.generic.auto._
implicit def hint[T] =
implicit def hint[T]: ProductHint[T] =
ProductHint[T](ConfigFieldMapping(CamelCase, CamelCase))

def apply(config: Configuration): NioConfiguration =
Expand Down
10 changes: 5 additions & 5 deletions nio-provider/app/controllers/UserDataController.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package controllers

import java.io.FileInputStream

import actor.EventActor
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.stream.Materializer
import org.apache.pekko.stream.scaladsl.{Source, StreamConverters}
import org.apache.pekko.util.ByteString
import auth.AuthActionWithEmail
import configuration.Env
import play.api.libs.Files
import play.api.libs.streams.ActorFlow
import play.api.mvc.{AbstractController, ControllerComponents, WebSocket}
import play.api.mvc.{AbstractController, Action, ControllerComponents, MultipartFormData, WebSocket}
import service.NioService
import utils.NioLogger

Expand All @@ -24,15 +24,15 @@ class UserDataController(
implicit val actorSystem: ActorSystem,
implicit val ec: ExecutionContext
) extends AbstractController(cc) {
implicit val mat = Materializer(actorSystem)
implicit val mat: Materializer = Materializer(actorSystem)

def listen() = WebSocket.accept[String, String] { request =>
def listen(): WebSocket = WebSocket.accept[String, String] { request =>
ActorFlow.actorRef { out =>
EventActor.props(out)
}
}

def uploadFile(tenant: String, orgKey: String, userId: String, name: String) =
def uploadFile(tenant: String, orgKey: String, userId: String, name: String): Action[MultipartFormData[Files.TemporaryFile]] =
AuthAction.async(parse.multipartFormData) { implicit req =>
NioLogger.info(s"upload file $name")
val src: Source[ByteString, _] =
Expand Down
18 changes: 9 additions & 9 deletions nio-provider/app/utils/Results.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Result {
import cats.instances.all._
import cats.syntax.semigroup._

implicit val format = Json.format[AppErrors]
implicit val format: OFormat[AppErrors] = Json.format[AppErrors]

def fromJsError(jsError: Seq[(JsPath, Seq[JsonValidationError])]): AppErrors = {
val fieldErrors = jsError.map { case (k, v) =>
Expand All @@ -63,9 +63,9 @@ object Result {
}

implicit val monoid: Monoid[AppErrors] = new Monoid[AppErrors] {
override def empty = AppErrors()
override def empty: AppErrors = AppErrors()

override def combine(x: AppErrors, y: AppErrors) = {
override def combine(x: AppErrors, y: AppErrors): AppErrors = {
val errors = x.errors ++ y.errors
val fieldErrors = mergeMap(x.fieldErrors, y.fieldErrors)
AppErrors(errors, fieldErrors)
Expand Down Expand Up @@ -96,7 +96,7 @@ object Result {
}

case class ImportResult(success: Int = 0, errors: AppErrors = AppErrors()) {
def isError = !errors.isEmpty
def isError: Boolean = !errors.isEmpty

def toJson: JsValue = ImportResult.format.writes(this)
}
Expand All @@ -105,18 +105,18 @@ object ImportResult {

import cats.syntax.semigroup._

implicit val format = Json.format[ImportResult]
implicit val format: OFormat[ImportResult] = Json.format[ImportResult]

implicit val monoid = new Monoid[ImportResult] {
override def empty = ImportResult()
implicit val monoid: Monoid[ImportResult] = new Monoid[ImportResult] {
override def empty: ImportResult = ImportResult()

override def combine(x: ImportResult, y: ImportResult) = (x, y) match {
override def combine(x: ImportResult, y: ImportResult): ImportResult = (x, y) match {
case (ImportResult(s1, e1), ImportResult(s2, e2)) =>
ImportResult(s1 + s2, e1 |+| e2)
}
}

def error(e: ErrorMessage) = ImportResult(errors = AppErrors(errors = Seq(e)))
def error(e: ErrorMessage): ImportResult = ImportResult(errors = AppErrors(errors = Seq(e)))

def fromResult[T](r: Result[T]): ImportResult = r match {
case Right(_) => ImportResult(success = 1)
Expand Down
24 changes: 12 additions & 12 deletions nio-provider/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lazy val `nio-provider` = (project in file("."))
.enablePlugins(NoPublish)
.disablePlugins(BintrayPlugin)

scalaVersion := "2.13.14"
scalaVersion := _scalaVersion

resolvers ++= Seq(
Resolver.jcenterRepo,
Expand Down Expand Up @@ -42,11 +42,11 @@ scalacOptions ++= Seq(

/// ASSEMBLY CONFIG

mainClass in assembly := Some("play.core.server.ProdServerStart")
test in assembly := {}
assemblyJarName in assembly := "nio-provider.jar"
fullClasspath in assembly += Attributed.blank(PlayKeys.playPackageAssets.value)
assemblyMergeStrategy in assembly := {
assembly / mainClass := Some("play.core.server.ProdServerStart")
assembly / test := {}
assembly / assemblyJarName := "nio-provider.jar"
assembly / fullClasspath += Attributed.blank(PlayKeys.playPackageAssets.value)
assembly / assemblyMergeStrategy := {
case PathList("javax", xs @ _*) => MergeStrategy.first
case PathList("META-INF", "native", xs @ _*) => MergeStrategy.first
case PathList("org", "apache", "commons", "logging", xs @ _*) => MergeStrategy.discard
Expand All @@ -59,24 +59,24 @@ assemblyMergeStrategy in assembly := {
case PathList(ps @ _*) if ps.contains("buildinfo") => MergeStrategy.discard
case PathList(ps @ _*) if ps.last endsWith "reflection-config.json" => MergeStrategy.first
case o =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(o)
}

lazy val packageAll = taskKey[Unit]("PackageAll")
packageAll := {
(dist in Compile).value
(assembly in Compile).value
(Compile / dist).value
(Compile / assembly).value
}

/// DOCKER CONFIG

dockerExposedPorts := Seq(
9000
)
packageName in Docker := "nio-provider"
Docker / packageName := "nio-provider"

maintainer in Docker := "MAIF Team <maif@maif.fr>"
Docker / maintainer := "MAIF Team <maif@maif.fr>"

dockerBaseImage := "openjdk:8"

Expand Down Expand Up @@ -109,4 +109,4 @@ dockerEntrypoint ++= Seq(

dockerUpdateLatest := true

packageName in Universal := s"nio-provider"
Universal / packageName := s"nio-provider"
3 changes: 1 addition & 2 deletions nio-server/app/configuration/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import scala.concurrent.duration.FiniteDuration

object NioConfiguration {

implicit def hint[T] =
ProductHint[T](ConfigFieldMapping(CamelCase, CamelCase))
implicit def hint[T]: ProductHint[T] = ProductHint[T](ConfigFieldMapping(CamelCase, CamelCase))

def apply(config: Configuration): NioConfiguration =
ConfigSource.fromConfig(config.underlying).at("nio").loadOrThrow[NioConfiguration]
Expand Down
26 changes: 12 additions & 14 deletions nio-server/app/controllers/AccountController.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package controllers

import auth.{AuthAction, SecuredAction, SecuredAuthContext}
import auth.SecuredAuthContext
import controllers.ErrorManager.ErrorManagerResult
import db.AccountMongoDataStore
import libs.xmlorjson.XmlOrJson
import messaging.KafkaMessageBroker
import models._
import utils.NioLogger
import play.api.mvc.{ActionBuilder, AnyContent, ControllerComponents}
import play.api.mvc.{Action, ActionBuilder, AnyContent, ControllerComponents}

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

class AccountController(
val AuthAction: ActionBuilder[SecuredAuthContext, AnyContent],
Expand All @@ -21,24 +21,22 @@ class AccountController(

implicit val readable: ReadableEntity[Account] = Account

def find(tenant: String, accountId: String) = AuthAction.async { implicit req =>
def find(tenant: String, accountId: String): Action[AnyContent] = AuthAction.async { implicit req =>
accountStore
.findByAccountId(tenant, accountId)
.map {
case Some(account) =>
renderMethod(account)
case None =>
"error.unknown.account".notFound()
case Some(account) => renderMethod(account)
case None => "error.unknown.account".notFound()
}
}

def findAll(tenant: String, page: Int, pageSize: Int) = AuthAction.async { implicit req =>
def findAll(tenant: String, page: Int, pageSize: Int): Action[AnyContent] = AuthAction.async { implicit req =>
accountStore
.findAll(tenant, page, pageSize)
.map(accounts => renderMethod(Accounts(accounts)))
}

def create(tenant: String) = AuthAction(bodyParser).async { implicit req =>
def create(tenant: String): Action[XmlOrJson] = AuthAction(bodyParser).async { implicit req =>
req.body.read[Account] match {
case Left(error) =>
NioLogger.error(s"Invalid account format $error")
Expand All @@ -60,7 +58,7 @@ class AccountController(
}
}

def update(tenant: String, accountId: String) =
def update(tenant: String, accountId: String): Action[XmlOrJson] =
AuthAction(bodyParser).async { implicit req =>
req.body.read[Account] match {
case Left(error) =>
Expand All @@ -82,16 +80,16 @@ class AccountController(
)
renderMethod(account)
}
case None =>
case None =>
Future.successful("error.account.not.found".notFound())
}

case Right(account) if accountId != account.accountId =>
case Right(_) =>
Future.successful("error.accountId.is.immutable".badRequest())
}
}

def delete(tenant: String, accountId: String) = AuthAction.async { implicit req =>
def delete(tenant: String, accountId: String): Action[AnyContent] = AuthAction.async { implicit req =>
accountStore.findByAccountId(tenant, accountId).flatMap {
case Some(account) =>
accountStore
Expand Down
Loading

0 comments on commit a12fcb8

Please sign in to comment.