From 37891cbc97e0e3225ee124877d344024d77114f3 Mon Sep 17 00:00:00 2001 From: mineme0110 Date: Mon, 3 Jun 2024 16:29:20 +0100 Subject: [PATCH 1/2] configurable scheme parameter for cardano wallet api Signed-off-by: mineme0110 --- prism-backend/node/src/main/resources/application.conf | 2 ++ .../src/main/scala/io/iohk/atala/prism/node/NodeConfig.scala | 1 + .../iohk/atala/prism/node/cardano/wallet/api/ApiClient.scala | 4 ++-- .../cardano/wallet/testing/FakeCardanoWalletApiClient.scala | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/prism-backend/node/src/main/resources/application.conf b/prism-backend/node/src/main/resources/application.conf index f42ee06fea..b9fa70903d 100644 --- a/prism-backend/node/src/main/resources/application.conf +++ b/prism-backend/node/src/main/resources/application.conf @@ -115,7 +115,9 @@ cardano { wallet { host = "localhost" port = 8090 + scheme = http + scheme = ${?NODE_CARDANO_WALLET_API_HTTP_SCHEME} host = ${?NODE_CARDANO_WALLET_API_HOST} port = ${?NODE_CARDANO_WALLET_API_PORT} diff --git a/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/NodeConfig.scala b/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/NodeConfig.scala index 8323acec8d..7d38e2e950 100644 --- a/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/NodeConfig.scala +++ b/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/NodeConfig.scala @@ -40,6 +40,7 @@ object NodeConfig { } def cardanoWalletConfig(config: Config): CardanoWalletApiClient.Config = { + val scheme = config.getString("scheme") val host = config.getString("host") val port = config.getInt("port") val routingHeaderName = Try("routingHeaderName").map(config.getString).toOption diff --git a/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/cardano/wallet/api/ApiClient.scala b/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/cardano/wallet/api/ApiClient.scala index 810ea66724..40477e1bad 100644 --- a/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/cardano/wallet/api/ApiClient.scala +++ b/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/cardano/wallet/api/ApiClient.scala @@ -80,7 +80,7 @@ private[wallet] class ApiClient[F[_]: Functor]( .headers(config.routingHeader.toList: _*) .method( method.httpMethod, - Uri.apply(config.host, config.port).withWholePath(method.path) + Uri.apply(config.scheme, config.host, config.port).withWholePath(method.path) ) .body(method.requestBody.map(_.noSpaces).getOrElse("")) .send(backend) @@ -97,7 +97,7 @@ private[wallet] class ApiClient[F[_]: Functor]( private[wallet] object ApiClient { - case class Config(host: String, port: Int, routingHeader: Option[Header]) + case class Config(scheme: String, host: String, port: Int, routingHeader: Option[Header]) private[wallet] def defaultBackend[F[_]: Async]: Resource[F, SttpBackend[F, Any]] = AsyncHttpClientCatsBackend.resource[F]() diff --git a/prism-backend/node/src/test/scala/io/iohk/atala/prism/node/cardano/wallet/testing/FakeCardanoWalletApiClient.scala b/prism-backend/node/src/test/scala/io/iohk/atala/prism/node/cardano/wallet/testing/FakeCardanoWalletApiClient.scala index c191a1b538..50a4377b89 100644 --- a/prism-backend/node/src/test/scala/io/iohk/atala/prism/node/cardano/wallet/testing/FakeCardanoWalletApiClient.scala +++ b/prism-backend/node/src/test/scala/io/iohk/atala/prism/node/cardano/wallet/testing/FakeCardanoWalletApiClient.scala @@ -53,7 +53,7 @@ object FakeCardanoWalletApiClient { */ object NotFound { def apply[F[_]: Async](): CardanoWalletApiClient[F] = { - val config = ApiClient.Config("localhost", 8090, Option.empty) + val config = ApiClient.Config("http", "localhost", 8090, Option.empty) val backend = AsyncHttpClientCatsBackend.stub new ApiClient(config, backend) } @@ -66,7 +66,7 @@ object FakeCardanoWalletApiClient { responseBody: String, maybeRoutingHeader: Option[Header] ): CardanoWalletApiClient[F] = { - val config = ApiClient.Config("localhost", 8090, maybeRoutingHeader) + val config = ApiClient.Config("http", "localhost", 8090, maybeRoutingHeader) val backend = AsyncHttpClientCatsBackend.stub .whenRequestMatches(request => request.uri.host.contains(config.host) From 7d8fe5e6fbfdc218bb1d4c904dbad9a279753873 Mon Sep 17 00:00:00 2001 From: mineme0110 Date: Mon, 3 Jun 2024 17:49:56 +0100 Subject: [PATCH 2/2] add schme Signed-off-by: mineme0110 --- .../src/main/scala/io/iohk/atala/prism/node/NodeConfig.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/NodeConfig.scala b/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/NodeConfig.scala index 7d38e2e950..5a83d38a6c 100644 --- a/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/NodeConfig.scala +++ b/prism-backend/node/src/main/scala/io/iohk/atala/prism/node/NodeConfig.scala @@ -47,6 +47,6 @@ object NodeConfig { val routingHeaderValue = Try("routingHeaderValue").map(config.getString).toOption val routingHeader = Applicative[Option] .map2(routingHeaderName, routingHeaderValue)((headerName, headerValue) => Header(headerName, headerValue)) - CardanoWalletApiClient.Config(host, port, routingHeader) + CardanoWalletApiClient.Config(scheme, host, port, routingHeader) } }