From a5b583f445b7efd31987cf9ca017bc544a877986 Mon Sep 17 00:00:00 2001 From: davidpoltorak-io <109518299+davidpoltorak-io@users.noreply.github.com> Date: Tue, 8 Nov 2022 20:05:49 +0400 Subject: [PATCH] feat(shared): Add environmnet configuration for Iris DB and bump scala version in other components to enable build (#96) --- iris/service/build.sbt | 2 +- iris/service/project/Dependencies.scala | 6 ++- .../src/main/resources/application.conf | 14 +++++++ .../io/iohk/atala/iris/server/Modules.scala | 38 ++++++++++++++----- .../atala/iris/server/config/AppConfig.scala | 16 ++++++++ pollux/vc-jwt/build.sbt | 2 +- prism-agent/service/build.sbt | 2 +- 7 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 iris/service/server/src/main/resources/application.conf create mode 100644 iris/service/server/src/main/scala/io/iohk/atala/iris/server/config/AppConfig.scala diff --git a/iris/service/build.sbt b/iris/service/build.sbt index a297060f6d..df9a62ae6a 100644 --- a/iris/service/build.sbt +++ b/iris/service/build.sbt @@ -10,7 +10,7 @@ def commonProject(project: Project): Project = project.settings( version := "0.1.0-SNAPSHOT", organization := "io.iohk.atala", - scalaVersion := "3.1.3", + scalaVersion := "3.2.0", githubTokenSource := TokenSource.Environment("ATALA_GITHUB_TOKEN"), resolvers += Resolver .githubPackages("input-output-hk", "atala-prism-sdk"), diff --git a/iris/service/project/Dependencies.scala b/iris/service/project/Dependencies.scala index 1afd2e7a30..72e2ffee9d 100644 --- a/iris/service/project/Dependencies.scala +++ b/iris/service/project/Dependencies.scala @@ -3,6 +3,7 @@ import sbt._ object Dependencies { object Versions { val zio = "2.0.2" + val zioConfig = "3.0.2" val circe = "0.14.1" val circeOptics = "0.14.1" val akka = "2.6.19" @@ -15,6 +16,9 @@ object Dependencies { } private lazy val zio = "dev.zio" %% "zio" % Versions.zio + private lazy val zioConfig = "dev.zio" %% "zio-config" % Versions.zioConfig + private lazy val zioConfigMagnolia = "dev.zio" %% "zio-config-magnolia" % Versions.zioConfig + private lazy val zioConfigTypesafe = "dev.zio" %% "zio-config-typesafe" % Versions.zioConfig private lazy val zioStream = "dev.zio" %% "zio-streams" % Versions.zio private lazy val zioCatsInterop = "dev.zio" %% "zio-interop-cats" % Versions.zioCatsInterop // We have to exclude bouncycastle since for some reason bitcoinj depends on bouncycastle jdk15to18 @@ -48,7 +52,7 @@ object Dependencies { private lazy val zioTestMagnolia = "dev.zio" %% "zio-test-magnolia" % "2.0.2" % Test // Dependency Modules - private lazy val baseDependencies: Seq[ModuleID] = Seq(zio, zioStream, prismCrypto, shared, enumeratum) + private lazy val baseDependencies: Seq[ModuleID] = Seq(zio, zioConfig, zioConfigMagnolia, zioConfigTypesafe, zioStream, prismCrypto, shared, enumeratum) private lazy val grpcDependencies: Seq[ModuleID] = Seq(grpcNetty, grpcServices, scalaPbProto, scalaPbGrpc) private lazy val doobieDependencies: Seq[ModuleID] = Seq(doobiePostgres, doobieHikari) private lazy val circeDependencies: Seq[ModuleID] = diff --git a/iris/service/server/src/main/resources/application.conf b/iris/service/server/src/main/resources/application.conf new file mode 100644 index 0000000000..0ee97184d8 --- /dev/null +++ b/iris/service/server/src/main/resources/application.conf @@ -0,0 +1,14 @@ +iris { + database { + host = "localhost" + host = ${?IRIS_DB_HOST} + port = 5432 + port = ${?IRIS_DB_PORT} + databaseName = "iris" + databaseName = ${?IRIS_DB_NAME} + username = "postgres" + username = ${?IRIS_DB_USER} + password = "postgres" + password = ${?IRIS_DB_PASSWORD} + } +} \ No newline at end of file diff --git a/iris/service/server/src/main/scala/io/iohk/atala/iris/server/Modules.scala b/iris/service/server/src/main/scala/io/iohk/atala/iris/server/Modules.scala index 0e95d82225..164d314275 100644 --- a/iris/service/server/src/main/scala/io/iohk/atala/iris/server/Modules.scala +++ b/iris/service/server/src/main/scala/io/iohk/atala/iris/server/Modules.scala @@ -13,6 +13,10 @@ import io.iohk.atala.iris.sql.repository.* import zio.* import zio.interop.catz.* import zio.stream.ZStream +import com.typesafe.config.ConfigFactory +import io.iohk.atala.iris.server.config.AppConfig +import zio.config.typesafe.TypesafeConfigSource +import zio.config.{ReadError, read} object Modules { val app: Task[Unit] = { @@ -29,6 +33,16 @@ object Modules { object AppModule { val publishingServiceLayer: ULayer[PublishingService] = MockPublishingService.layer val publishingSchedulerLayer: ULayer[PublishingScheduler] = MockPublishingScheduler.layer + + val configLayer: Layer[ReadError[String], AppConfig] = ZLayer.fromZIO { + read( + AppConfig.descriptor.from( + TypesafeConfigSource.fromTypesafeConfig( + ZIO.attempt(ConfigFactory.load()) + ) + ) + ) + } } object GrpcModule { @@ -58,19 +72,23 @@ object BlockchainModule { } object RepoModule { - val transactorLayer: TaskLayer[Transactor[Task]] = - ZLayer.fromZIO { - Dispatcher[Task].allocated.map { case (dispatcher, _) => - given Dispatcher[Task] = dispatcher - TransactorLayer.hikari[Task]( - TransactorLayer.DbConfig( - username = "postgres", - password = "postgres", - jdbcUrl = "jdbc:postgresql://localhost:5432/iris" + val transactorLayer: TaskLayer[Transactor[Task]] = { + val layerWithConfig = ZLayer.fromZIO { + ZIO.service[AppConfig].map(_.iris.database).flatMap { config => + Dispatcher[Task].allocated.map { case (dispatcher, _) => + given Dispatcher[Task] = dispatcher + TransactorLayer.hikari[Task]( + TransactorLayer.DbConfig( + username = config.username, + password = config.password, + jdbcUrl = s"jdbc:postgresql://${config.host}:${config.port}/${config.databaseName}" + ) ) - ) + } } }.flatten + AppModule.configLayer >>> layerWithConfig + } val dbRepositoryTransactor: TaskLayer[JdbcDbRepositoryTransactorIO] = transactorLayer >>> JdbcDbRepositoryTransactorIO.layer diff --git a/iris/service/server/src/main/scala/io/iohk/atala/iris/server/config/AppConfig.scala b/iris/service/server/src/main/scala/io/iohk/atala/iris/server/config/AppConfig.scala new file mode 100644 index 0000000000..555a221c97 --- /dev/null +++ b/iris/service/server/src/main/scala/io/iohk/atala/iris/server/config/AppConfig.scala @@ -0,0 +1,16 @@ +package io.iohk.atala.iris.server.config + +import zio.config.* +import zio.config.magnolia.Descriptor + +final case class AppConfig( + iris: IrisConfig +) + +object AppConfig { + val descriptor: ConfigDescriptor[AppConfig] = Descriptor[AppConfig] +} + +final case class IrisConfig(database: DatabaseConfig) + +final case class DatabaseConfig(host: String, port: Int, databaseName: String, username: String, password: String) diff --git a/pollux/vc-jwt/build.sbt b/pollux/vc-jwt/build.sbt index 71e6f4b135..0b19d0064f 100644 --- a/pollux/vc-jwt/build.sbt +++ b/pollux/vc-jwt/build.sbt @@ -1,7 +1,7 @@ import Dependencies._ ThisBuild / version := "0.1.0-SNAPSHOT" -ThisBuild / scalaVersion := "3.1.3" +ThisBuild / scalaVersion := "3.2.0" ThisBuild / organization := "io.iohk.atala" lazy val root = project diff --git a/prism-agent/service/build.sbt b/prism-agent/service/build.sbt index 77a2dff967..609010670f 100644 --- a/prism-agent/service/build.sbt +++ b/prism-agent/service/build.sbt @@ -2,7 +2,7 @@ import Dependencies._ import sbtghpackages.GitHubPackagesPlugin.autoImport._ ThisBuild / version := "0.1.0-SNAPSHOT" -ThisBuild / scalaVersion := "3.1.3" +ThisBuild / scalaVersion := "3.2.0" ThisBuild / organization := "io.iohk.atala" // Custom keys