diff --git a/prism-agent/service/server/src/main/resources/application.conf b/prism-agent/service/server/src/main/resources/application.conf index 2e3ab0a30f..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,16 @@ agent { port = 8085 port =${?AGENT_HTTP_PORT} } + publicEndpointUrl = "https://host.docker.internal:8080/prism-agent" + publicEndpointUrl = ${?REST_SERVICE_URL} + } + didCommEndpoint { + http { + port = 8090 + port =${?AGENT_DIDCOMM_PORT} + } + publicEndpointUrl = "http://localhost:8090" + publicEndpointUrl = ${?DIDCOMM_SERVICE_URL} } authentication { admin { @@ -114,10 +124,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 { host = "localhost" host = ${?AGENT_DB_HOST} 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..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 @@ -4,13 +4,14 @@ 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, + 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 +30,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..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 @@ -124,9 +124,8 @@ final case class DefaultWalletConfig( final case class AgentConfig( httpEndpoint: HttpEndpointConfig, + didCommEndpoint: DidCommEndpointConfig, authentication: AuthenticationConfig, - didCommServiceEndpointUrl: String, - restServiceUrl: String, database: DatabaseConfig, verification: VerificationConfig, secretStorage: SecretStorageConfig, @@ -141,7 +140,9 @@ 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) final case class HttpConfig(port: Int) 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) 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" } )