From 503dd3929ed6728938ac425c5095992265e34dd3 Mon Sep 17 00:00:00 2001 From: Benjamin Voiturier Date: Fri, 13 Oct 2023 11:37:26 +0200 Subject: [PATCH 1/3] fix(prism-agent): use internal DIDComm service port defined in agent config Signed-off-by: Benjamin Voiturier --- .../server/src/main/resources/application.conf | 10 ++++++++-- .../atala/agent/server/DidCommHttpServer.scala | 9 ++++++--- .../scala/io/iohk/atala/agent/server/Main.scala | 15 +-------------- .../iohk/atala/agent/server/PrismAgentApp.scala | 15 +++++---------- .../atala/agent/server/config/AppConfig.scala | 4 +++- .../controller/ConnectionControllerImpl.scala | 4 ++-- 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/prism-agent/service/server/src/main/resources/application.conf b/prism-agent/service/server/src/main/resources/application.conf index 2e3ab0a30f..d235251b2e 100644 --- a/prism-agent/service/server/src/main/resources/application.conf +++ b/prism-agent/service/server/src/main/resources/application.conf @@ -86,6 +86,14 @@ agent { port =${?AGENT_HTTP_PORT} } } + didCommEndpoint { + http { + port = 8090 + port =${?AGENT_DIDCOMM_PORT} + } + publicEndpointUrl = "http://localhost:8090" + publicEndpointUrl = ${?DIDCOMM_SERVICE_URL} + } authentication { admin { token = "admin" @@ -114,8 +122,6 @@ agent { autoProvisioning = ${?API_KEY_AUTO_PROVISIONING} } } - didCommServiceEndpointUrl = "http://localhost:8090" - didCommServiceEndpointUrl = ${?DIDCOMM_SERVICE_URL} restServiceUrl = "https://host.docker.internal:8080/prism-agent" restServiceUrl = ${?REST_SERVICE_URL} database { diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/DidCommHttpServer.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/DidCommHttpServer.scala index d384b59e48..a4c3b2c620 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/DidCommHttpServer.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/DidCommHttpServer.scala @@ -23,20 +23,23 @@ import io.iohk.atala.resolvers.DIDResolver import io.iohk.atala.shared.models.WalletAccessContext import zio.* import zio.http.* + import java.util.UUID object DidCommHttpServer { - def run(didCommServicePort: Int) = { - val server = { + def run = { + def server(didCommServicePort: Int) = { val config = Server.Config.default.copy(address = new java.net.InetSocketAddress(didCommServicePort)) ZLayer.succeed(config) >>> Server.live } for { + appConfig <- ZIO.service[AppConfig] + didCommServicePort = appConfig.agent.didCommEndpoint.http.port _ <- ZIO.logInfo(s"Server Started on port $didCommServicePort") _ <- Server .serve(didCommServiceEndpoint) - .provideSomeLayer(server) + .provideSomeLayer(server(didCommServicePort)) .debug *> ZIO .logWarning(s"Server STOP (on port $didCommServicePort)") .tapDefect(error => ZIO.logErrorCause("Defect processing incoming DIDComm message", Cause.fail(error))) diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Main.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Main.scala index b6890c9e1e..74f633da18 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Main.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/Main.scala @@ -105,23 +105,10 @@ object MainApp extends ZIOAppDefault { |""".stripMargin) .ignore - didCommServiceUrl <- System.env("DIDCOMM_SERVICE_URL").map { - case Some(s) => s - case _ => "http://localhost:8090" - } - _ <- ZIO.logInfo(s"DIDComm Service URL => $didCommServiceUrl") - - didCommServicePort <- System.env("DIDCOMM_SERVICE_PORT").map { - case Some(s) if s.toIntOption.isDefined => s.toInt - case _ => 8090 - } - _ <- ZIO.logInfo(s"DIDComm Service port => $didCommServicePort") - _ <- preMigrations _ <- migrations - app <- PrismAgentApp - .run(didCommServicePort) + app <- PrismAgentApp.run .provide( DidCommX.liveLayer, // infra diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/PrismAgentApp.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/PrismAgentApp.scala index 269edb1c5b..01f807ac40 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/PrismAgentApp.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/PrismAgentApp.scala @@ -3,14 +3,10 @@ package io.iohk.atala.agent.server import io.iohk.atala.agent.notification.WebhookPublisher import io.iohk.atala.agent.server.config.AppConfig import io.iohk.atala.agent.server.http.{ZHttp4sBlazeServer, ZHttpEndpoints} -import io.iohk.atala.agent.server.jobs.{ - IssueBackgroundJobs, - ConnectBackgroundJobs, - DIDStateSyncBackgroundJobs, - PresentBackgroundJobs -} +import io.iohk.atala.agent.server.jobs.{ConnectBackgroundJobs, DIDStateSyncBackgroundJobs, IssueBackgroundJobs, PresentBackgroundJobs} import io.iohk.atala.agent.walletapi.model.{Entity, Wallet, WalletSeed} import io.iohk.atala.agent.walletapi.service.{EntityService, ManagedDIDService, WalletManagementService} +import io.iohk.atala.agent.walletapi.storage.DIDNonSecretStorage import io.iohk.atala.castor.controller.{DIDRegistrarServerEndpoints, DIDServerEndpoints} import io.iohk.atala.castor.core.service.DIDService import io.iohk.atala.connect.controller.ConnectionServerEndpoints @@ -29,22 +25,21 @@ import io.iohk.atala.pollux.vc.jwt.DidResolver as JwtDidResolver import io.iohk.atala.presentproof.controller.PresentProofServerEndpoints import io.iohk.atala.resolvers.DIDResolver import io.iohk.atala.shared.models.{HexString, WalletAccessContext, WalletId} +import io.iohk.atala.shared.utils.DurationOps.toMetricsSeconds import io.iohk.atala.system.controller.SystemServerEndpoints import zio.* import zio.metrics.* -import io.iohk.atala.shared.utils.DurationOps.toMetricsSeconds -import io.iohk.atala.agent.walletapi.storage.DIDNonSecretStorage object PrismAgentApp { - def run(didCommServicePort: Int) = for { + def run = for { _ <- AgentInitialization.run _ <- issueCredentialDidCommExchangesJob.debug.fork _ <- presentProofExchangeJob.debug.fork _ <- connectDidCommExchangesJob.debug.fork _ <- syncDIDPublicationStateFromDltJob.fork _ <- AgentHttpServer.run.fork - fiber <- DidCommHttpServer.run(didCommServicePort).fork + fiber <- DidCommHttpServer.run.fork _ <- WebhookPublisher.layer.build.map(_.get[WebhookPublisher]).flatMap(_.run.debug.fork) _ <- fiber.join *> ZIO.log(s"Server End") _ <- ZIO.never diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/config/AppConfig.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/config/AppConfig.scala index a57b591136..13b2725920 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/config/AppConfig.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/config/AppConfig.scala @@ -124,8 +124,8 @@ final case class DefaultWalletConfig( final case class AgentConfig( httpEndpoint: HttpEndpointConfig, + didCommEndpoint: DidCommEndpointConfig, authentication: AuthenticationConfig, - didCommServiceEndpointUrl: String, restServiceUrl: String, database: DatabaseConfig, verification: VerificationConfig, @@ -143,6 +143,8 @@ final case class AgentConfig( final case class HttpEndpointConfig(http: HttpConfig) +final case class DidCommEndpointConfig(http: HttpConfig, publicEndpointUrl: String) + final case class HttpConfig(port: Int) final case class SecretStorageConfig( diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/connect/controller/ConnectionControllerImpl.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/connect/controller/ConnectionControllerImpl.scala index 8e35e2bdac..ae58774e4a 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/connect/controller/ConnectionControllerImpl.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/connect/controller/ConnectionControllerImpl.scala @@ -28,7 +28,7 @@ class ConnectionControllerImpl( rc: RequestContext ): ZIO[WalletAccessContext, ErrorResponse, Connection] = { val result = for { - pairwiseDid <- managedDIDService.createAndStorePeerDID(appConfig.agent.didCommServiceEndpointUrl) + pairwiseDid <- managedDIDService.createAndStorePeerDID(appConfig.agent.didCommEndpoint.publicEndpointUrl) connection <- service.createConnectionInvitation(request.label, pairwiseDid.did) } yield Connection.fromDomain(connection) @@ -66,7 +66,7 @@ class ConnectionControllerImpl( )(implicit rc: RequestContext): ZIO[WalletAccessContext, ErrorResponse, Connection] = { val result = for { record <- service.receiveConnectionInvitation(request.invitation) - pairwiseDid <- managedDIDService.createAndStorePeerDID(appConfig.agent.didCommServiceEndpointUrl) + pairwiseDid <- managedDIDService.createAndStorePeerDID(appConfig.agent.didCommEndpoint.publicEndpointUrl) connection <- service.acceptConnectionInvitation(record.id, pairwiseDid.did) } yield Connection.fromDomain(connection) From 2975641d379aa727f2681445f9d3d955b5ab65f5 Mon Sep 17 00:00:00 2001 From: Benjamin Voiturier Date: Fri, 13 Oct 2023 11:44:56 +0200 Subject: [PATCH 2/3] chore(prism-agent): move public 'restServiceUrl' config param under http endpoint config Signed-off-by: Benjamin Voiturier --- .../service/server/src/main/resources/application.conf | 4 ++-- .../scala/io/iohk/atala/agent/server/config/AppConfig.scala | 3 +-- .../io/iohk/atala/issue/controller/IssueControllerImpl.scala | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/prism-agent/service/server/src/main/resources/application.conf b/prism-agent/service/server/src/main/resources/application.conf index d235251b2e..51d74a26a0 100644 --- a/prism-agent/service/server/src/main/resources/application.conf +++ b/prism-agent/service/server/src/main/resources/application.conf @@ -85,6 +85,8 @@ agent { port = 8085 port =${?AGENT_HTTP_PORT} } + publicEndpointUrl = "https://host.docker.internal:8080/prism-agent" + publicEndpointUrl = ${?REST_SERVICE_URL} } didCommEndpoint { http { @@ -122,8 +124,6 @@ agent { autoProvisioning = ${?API_KEY_AUTO_PROVISIONING} } } - restServiceUrl = "https://host.docker.internal:8080/prism-agent" - restServiceUrl = ${?REST_SERVICE_URL} database { host = "localhost" host = ${?AGENT_DB_HOST} diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/config/AppConfig.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/config/AppConfig.scala index 13b2725920..4b92900a80 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/config/AppConfig.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/config/AppConfig.scala @@ -126,7 +126,6 @@ final case class AgentConfig( httpEndpoint: HttpEndpointConfig, didCommEndpoint: DidCommEndpointConfig, authentication: AuthenticationConfig, - restServiceUrl: String, database: DatabaseConfig, verification: VerificationConfig, secretStorage: SecretStorageConfig, @@ -141,7 +140,7 @@ final case class AgentConfig( } } -final case class HttpEndpointConfig(http: HttpConfig) +final case class HttpEndpointConfig(http: HttpConfig, publicEndpointUrl: String) final case class DidCommEndpointConfig(http: HttpConfig, publicEndpointUrl: String) diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/issue/controller/IssueControllerImpl.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/issue/controller/IssueControllerImpl.scala index 32572456ff..fb270df4ff 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/issue/controller/IssueControllerImpl.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/issue/controller/IssueControllerImpl.scala @@ -85,11 +85,10 @@ class IssueControllerImpl( claims = jsonClaims, validityPeriod = request.validityPeriod, automaticIssuance = request.automaticIssuance.orElse(Some(true)), { + val publicEndpointUrl = appConfig.agent.httpEndpoint.publicEndpointUrl val urlSuffix = s"credential-definition-registry/definitions/${credentialDefinitionGUID.toString}/definition" - val urlPrefix = - if (appConfig.agent.restServiceUrl.endsWith("/")) appConfig.agent.restServiceUrl - else appConfig.agent.restServiceUrl + "/" + val urlPrefix = if (publicEndpointUrl.endsWith("/")) publicEndpointUrl else publicEndpointUrl + "/" s"$urlPrefix$urlSuffix" } ) From 7fe209255c37b3b20e80522b2cdbc024013f65fd Mon Sep 17 00:00:00 2001 From: Benjamin Voiturier Date: Fri, 13 Oct 2023 13:47:00 +0200 Subject: [PATCH 3/3] chore(prism-agent): scalafmtAll Signed-off-by: Benjamin Voiturier --- .../scala/io/iohk/atala/agent/server/PrismAgentApp.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/PrismAgentApp.scala b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/PrismAgentApp.scala index 01f807ac40..a7442310ae 100644 --- a/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/PrismAgentApp.scala +++ b/prism-agent/service/server/src/main/scala/io/iohk/atala/agent/server/PrismAgentApp.scala @@ -3,7 +3,12 @@ package io.iohk.atala.agent.server import io.iohk.atala.agent.notification.WebhookPublisher import io.iohk.atala.agent.server.config.AppConfig import io.iohk.atala.agent.server.http.{ZHttp4sBlazeServer, ZHttpEndpoints} -import io.iohk.atala.agent.server.jobs.{ConnectBackgroundJobs, DIDStateSyncBackgroundJobs, IssueBackgroundJobs, PresentBackgroundJobs} +import io.iohk.atala.agent.server.jobs.{ + ConnectBackgroundJobs, + DIDStateSyncBackgroundJobs, + IssueBackgroundJobs, + PresentBackgroundJobs +} import io.iohk.atala.agent.walletapi.model.{Entity, Wallet, WalletSeed} import io.iohk.atala.agent.walletapi.service.{EntityService, ManagedDIDService, WalletManagementService} import io.iohk.atala.agent.walletapi.storage.DIDNonSecretStorage