Skip to content

Commit

Permalink
fix(prism-agent): agent should read DIDComm port from config (#757)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Voiturier <[email protected]>
  • Loading branch information
bvoiturier authored Oct 13, 2023
1 parent d36533f commit cda908c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 34 deletions.
14 changes: 10 additions & 4 deletions prism-agent/service/server/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
)
Expand Down

0 comments on commit cda908c

Please sign in to comment.