From e74600dbfbc9046352877eb78dd5fe2ffa27515b Mon Sep 17 00:00:00 2001 From: FabioPinheiro Date: Tue, 21 Nov 2023 17:44:24 +0000 Subject: [PATCH] losing sanity with ZIO-config --- README.md | 2 +- docker-compose.yml | 2 +- infrastructure/charts/mediator/templates/deployment.yaml | 4 ++-- mediator/src/main/resources/application.conf | 4 ++-- .../io/iohk/atala/mediator/MediatorStandalone.scala | 9 +++++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9328f82d..64eeaadb 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ To set up the mediator identity: - `KEY_AGREEMENT_X` - is the key agreement public key (MUST be a X25519 OKP key type). - `KEY_AUTHENTICATION_D` - is the key authentication private key (MUST be an Ed25519 OKP key type). - `KEY_AUTHENTICATION_X` - is the key authentication public key (MUST be an Ed25519 OKP key type). -- `SERVICE_ENDPOINT` - is the endpoint of the mediator. Where the mediator will be listening to incoming DID Comm messages. +- `SERVICE_ENDPOINTS` - is the list of endpoints of the mediator split by ';'. Where the mediator will be listening to incoming DID Comm messages. #### mediator-storage To set up the mediator storage (MongoDB): diff --git a/docker-compose.yml b/docker-compose.yml index 95b6b93d..7e816d4c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,7 +23,7 @@ services: - KEY_AGREEMENT_X=Sr4SkIskjN_VdKTn0zkjYbhGTWArdUNE4j_DmUpnQGw - KEY_AUTHENTICATION_D=INXCnxFEl0atLIIQYruHzGd5sUivMRyQOzu87qVerug - KEY_AUTHENTICATION_X=MBjnXZxkMcoQVVL21hahWAw43RuAG-i64ipbeKKqwoA - - SERVICE_ENDPOINT=["http://localhost:8080", "ws://localhost:8080/ws"] + - SERVICE_ENDPOINTS=http://localhost:8080 - MONGODB_USER=admin - MONGODB_PASSWORD=admin - MONGODB_PROTOCOL=mongodb diff --git a/infrastructure/charts/mediator/templates/deployment.yaml b/infrastructure/charts/mediator/templates/deployment.yaml index f9e4e59c..72718338 100644 --- a/infrastructure/charts/mediator/templates/deployment.yaml +++ b/infrastructure/charts/mediator/templates/deployment.yaml @@ -39,5 +39,5 @@ spec: value: "27017" - name: MONGODB_DB_NAME value: "mediator" - - name: SERVICE_ENDPOINT - value: "https://{{ index .Values.ingress.applicationUrls 0 }}" + - name: SERVICE_ENDPOINTS + value: "https://{{ index .Values.ingress.applicationUrls 0 }};https://{{ index .Values.ingress.applicationUrls 0 }}/ws" diff --git a/mediator/src/main/resources/application.conf b/mediator/src/main/resources/application.conf index 3b03519d..e57326e8 100644 --- a/mediator/src/main/resources/application.conf +++ b/mediator/src/main/resources/application.conf @@ -16,8 +16,8 @@ mediator = { x = "MBjnXZxkMcoQVVL21hahWAw43RuAG-i64ipbeKKqwoA" x = ${?KEY_AUTHENTICATION_X} } - endpoint = ["http://localhost:8080", "ws://localhost:8080/ws"] #, "http://localhost:8080/http"] - endpoint = ${?SERVICE_ENDPOINT} + endpoints = "http://localhost:8080;ws://localhost:8080/ws" #, "http://localhost:8080/http"] + endpoints = ${?SERVICE_ENDPOINTS} } server.http.port = 8080 server.http.port = ${?PORT} diff --git a/mediator/src/main/scala/io/iohk/atala/mediator/MediatorStandalone.scala b/mediator/src/main/scala/io/iohk/atala/mediator/MediatorStandalone.scala index 5e90895d..2e59d326 100644 --- a/mediator/src/main/scala/io/iohk/atala/mediator/MediatorStandalone.scala +++ b/mediator/src/main/scala/io/iohk/atala/mediator/MediatorStandalone.scala @@ -22,10 +22,10 @@ import zio.stream.* import java.time.format.DateTimeFormatter import scala.io.Source import fmgp.did.framework.TransportFactoryImp -case class MediatorConfig(endpoint: Seq[java.net.URI], keyAgreement: OKPPrivateKey, keyAuthentication: OKPPrivateKey) { +case class MediatorConfig(endpoints: String, keyAgreement: OKPPrivateKey, keyAuthentication: OKPPrivateKey) { val did = DIDPeer2.makeAgent( Seq(keyAgreement, keyAuthentication), - endpoint.map(e => DIDPeerServiceEncoded(s = e.toString)) + endpoints.split(";").toSeq.map(e => DIDPeerServiceEncoded(s = e.toString)) ) val agentLayer: ZLayer[Any, Nothing, MediatorAgent] = ZLayer(MediatorAgent.make(id = did.id, keyStore = did.keyStore)) @@ -67,6 +67,7 @@ object MediatorStandalone extends ZIOAppDefault { ) configs = ConfigProvider.fromResourcePath() mediatorConfig <- configs.nested("identity").nested("mediator").load(deriveConfig[MediatorConfig]) + agentLayer = mediatorConfig.agentLayer _ <- ZIO.log(s"Mediator APP. See https://github.com/input-output-hk/atala-prism-mediator") _ <- ZIO.log(s"MediatorConfig: $mediatorConfig") _ <- ZIO.log(s"DID: ${mediatorConfig.did.id.string}") @@ -94,8 +95,8 @@ object MediatorStandalone extends ZIOAppDefault { myServer <- Server .serve((MediatorAgent.didCommApp ++ DIDCommRoutes.app) @@ (Middleware.cors)) .provideSomeLayer(DidPeerResolver.layerDidPeerResolver) - .provideSomeLayer(mediatorConfig.agentLayer) - .provideSomeLayer((mediatorConfig.agentLayer ++ transportFactory ++ repos) >>> OperatorImp.layer) + .provideSomeLayer(agentLayer) + .provideSomeLayer((agentLayer ++ transportFactory ++ repos) >>> OperatorImp.layer) .provideSomeLayer( AsyncDriverResource.layer >>> ReactiveMongoApi.layer(mediatorDbConfig.connectionString)