From 65d7ad5b45c142689e9b6b4a09980ec2d7107ea7 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Fri, 17 Feb 2023 10:18:59 +0300 Subject: [PATCH] Support basic auth in JSON RPC endpoint (#6897) * Support basic auth in JSON RPC endpoint * Review comment: Allow blank password in basi auth of JSON RPC endpoint * Reuse basic auth configuration function --------- Co-authored-by: sl1depengwyn --- CHANGELOG.md | 2 ++ apps/explorer/config/dev/arbitrum.exs | 11 ++++------- apps/explorer/config/dev/besu.exs | 11 ++++------- apps/explorer/config/dev/erigon.exs | 11 ++++------- apps/explorer/config/dev/ganache.exs | 11 ++++------- apps/explorer/config/dev/geth.exs | 11 ++++------- apps/explorer/config/dev/nethermind.exs | 11 ++++------- apps/explorer/config/dev/rsk.exs | 11 ++++------- apps/explorer/config/prod/arbitrum.exs | 11 ++++------- apps/explorer/config/prod/besu.exs | 11 ++++------- apps/explorer/config/prod/erigon.exs | 11 ++++------- apps/explorer/config/prod/ganache.exs | 11 ++++------- apps/explorer/config/prod/geth.exs | 11 ++++------- apps/explorer/config/prod/nethermind.exs | 11 ++++------- apps/explorer/config/prod/rsk.exs | 11 ++++------- apps/indexer/config/dev/arbitrum.exs | 8 +++++++- apps/indexer/config/dev/besu.exs | 8 +++++++- apps/indexer/config/dev/erigon.exs | 8 +++++++- apps/indexer/config/dev/ganache.exs | 8 +++++++- apps/indexer/config/dev/geth.exs | 11 ++++------- apps/indexer/config/dev/nethermind.exs | 10 ++++++++-- apps/indexer/config/dev/rsk.exs | 8 +++++++- apps/indexer/config/prod/arbitrum.exs | 8 +++++++- apps/indexer/config/prod/besu.exs | 8 +++++++- apps/indexer/config/prod/erigon.exs | 8 +++++++- apps/indexer/config/prod/ganache.exs | 8 +++++++- apps/indexer/config/prod/geth.exs | 11 ++++------- apps/indexer/config/prod/nethermind.exs | 8 +++++++- apps/indexer/config/prod/rsk.exs | 8 +++++++- config/config_helper.exs | 14 ++++++++++++++ rel/config.exs | 2 +- 31 files changed, 166 insertions(+), 126 deletions(-) create mode 100644 config/config_helper.exs diff --git a/CHANGELOG.md b/CHANGELOG.md index 86aead68ea..71fa5ffe37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Features +- [#6897](https://github.com/blockscout/blockscout/pull/6897) - Support basic auth in JSON RPC endpoint + ### Fixes - [#6912](https://github.com/blockscout/blockscout/pull/6912) - Docker compose fix exposed ports diff --git a/apps/explorer/config/dev/arbitrum.exs b/apps/explorer/config/dev/arbitrum.exs index fa25c557bd..344ee07f45 100644 --- a/apps/explorer/config/dev/arbitrum.exs +++ b/apps/explorer/config/dev/arbitrum.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/dev/besu.exs b/apps/explorer/config/dev/besu.exs index 002a3270da..c2ee585259 100644 --- a/apps/explorer/config/dev/besu.exs +++ b/apps/explorer/config/dev/besu.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/dev/erigon.exs b/apps/explorer/config/dev/erigon.exs index 58b2eca2be..2403634b2e 100644 --- a/apps/explorer/config/dev/erigon.exs +++ b/apps/explorer/config/dev/erigon.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/dev/ganache.exs b/apps/explorer/config/dev/ganache.exs index 37373cafc9..2cd4c9f068 100644 --- a/apps/explorer/config/dev/ganache.exs +++ b/apps/explorer/config/dev/ganache.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/dev/geth.exs b/apps/explorer/config/dev/geth.exs index 6443b3c8f6..131607d629 100644 --- a/apps/explorer/config/dev/geth.exs +++ b/apps/explorer/config/dev/geth.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/dev/nethermind.exs b/apps/explorer/config/dev/nethermind.exs index f032361dd0..42e1194923 100644 --- a/apps/explorer/config/dev/nethermind.exs +++ b/apps/explorer/config/dev/nethermind.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/dev/rsk.exs b/apps/explorer/config/dev/rsk.exs index 008544092a..9faf1f9000 100644 --- a/apps/explorer/config/dev/rsk.exs +++ b/apps/explorer/config/dev/rsk.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/prod/arbitrum.exs b/apps/explorer/config/prod/arbitrum.exs index e267ce4d5f..565b32ecf2 100644 --- a/apps/explorer/config/prod/arbitrum.exs +++ b/apps/explorer/config/prod/arbitrum.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/prod/besu.exs b/apps/explorer/config/prod/besu.exs index d8ea15edc7..367cb86fd0 100644 --- a/apps/explorer/config/prod/besu.exs +++ b/apps/explorer/config/prod/besu.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/prod/erigon.exs b/apps/explorer/config/prod/erigon.exs index 386f6b08bd..a0684166f7 100644 --- a/apps/explorer/config/prod/erigon.exs +++ b/apps/explorer/config/prod/erigon.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/prod/ganache.exs b/apps/explorer/config/prod/ganache.exs index 679af12fdc..da8f69e543 100644 --- a/apps/explorer/config/prod/ganache.exs +++ b/apps/explorer/config/prod/ganache.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/prod/geth.exs b/apps/explorer/config/prod/geth.exs index 1b940345a7..3e7fcc46f7 100644 --- a/apps/explorer/config/prod/geth.exs +++ b/apps/explorer/config/prod/geth.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/prod/nethermind.exs b/apps/explorer/config/prod/nethermind.exs index 5a30263f1a..1eec652552 100644 --- a/apps/explorer/config/prod/nethermind.exs +++ b/apps/explorer/config/prod/nethermind.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/explorer/config/prod/rsk.exs b/apps/explorer/config/prod/rsk.exs index bcbf91863c..173a98579d 100644 --- a/apps/explorer/config/prod/rsk.exs +++ b/apps/explorer/config/prod/rsk.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :explorer, json_rpc_named_arguments: [ diff --git a/apps/indexer/config/dev/arbitrum.exs b/apps/indexer/config/dev/arbitrum.exs index e0f8de63e2..dfd5f3b8cc 100644 --- a/apps/indexer/config/dev/arbitrum.exs +++ b/apps/indexer/config/dev/arbitrum.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ @@ -11,7 +17,7 @@ config :indexer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] ], variant: EthereumJSONRPC.Arbitrum ], diff --git a/apps/indexer/config/dev/besu.exs b/apps/indexer/config/dev/besu.exs index af23f64718..bfa64797c7 100644 --- a/apps/indexer/config/dev/besu.exs +++ b/apps/indexer/config/dev/besu.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ @@ -17,7 +23,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] ], variant: EthereumJSONRPC.Besu ], diff --git a/apps/indexer/config/dev/erigon.exs b/apps/indexer/config/dev/erigon.exs index c359d0684b..5f655cb4a0 100644 --- a/apps/indexer/config/dev/erigon.exs +++ b/apps/indexer/config/dev/erigon.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ @@ -17,7 +23,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] ], variant: EthereumJSONRPC.Erigon ], diff --git a/apps/indexer/config/dev/ganache.exs b/apps/indexer/config/dev/ganache.exs index ee377b5022..c073851411 100644 --- a/apps/indexer/config/dev/ganache.exs +++ b/apps/indexer/config/dev/ganache.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ @@ -11,7 +17,7 @@ config :indexer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] ], variant: EthereumJSONRPC.Ganache ], diff --git a/apps/indexer/config/dev/geth.exs b/apps/indexer/config/dev/geth.exs index ae3a4b61dc..9a712db5f4 100644 --- a/apps/indexer/config/dev/geth.exs +++ b/apps/indexer/config/dev/geth.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :indexer, block_interval: :timer.seconds(5), diff --git a/apps/indexer/config/dev/nethermind.exs b/apps/indexer/config/dev/nethermind.exs index 59b6d96cd0..5ab6ee9ecb 100644 --- a/apps/indexer/config/dev/nethermind.exs +++ b/apps/indexer/config/dev/nethermind.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ @@ -17,7 +23,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] ], variant: EthereumJSONRPC.Nethermind ], @@ -33,7 +39,7 @@ config :indexer, # trace_block: System.get_env("ETHEREUM_JSONRPC_REALTIME_TRACE_URL") || "http://localhost:8545", # trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_REALTIME_TRACE_URL") || "http://localhost:8545" # ], - # http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]] + # http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] # ], # variant: EthereumJSONRPC.Nethermind # ] diff --git a/apps/indexer/config/dev/rsk.exs b/apps/indexer/config/dev/rsk.exs index 8132cb7cd6..6b66565b21 100644 --- a/apps/indexer/config/dev/rsk.exs +++ b/apps/indexer/config/dev/rsk.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), blocks_concurrency: 1, @@ -18,7 +24,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545", trace_replayBlockTransactions: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") || "http://localhost:8545" ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] ], variant: EthereumJSONRPC.RSK ], diff --git a/apps/indexer/config/prod/arbitrum.exs b/apps/indexer/config/prod/arbitrum.exs index b2780524c3..8a4e8b860b 100644 --- a/apps/indexer/config/prod/arbitrum.exs +++ b/apps/indexer/config/prod/arbitrum.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ @@ -11,7 +17,7 @@ config :indexer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:8545", - http_options: [recv_timeout: :timer.minutes(5), timeout: :timer.minutes(5), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(5), timeout: :timer.minutes(5), hackney: hackney_opts] ], variant: EthereumJSONRPC.Arbitrum ], diff --git a/apps/indexer/config/prod/besu.exs b/apps/indexer/config/prod/besu.exs index 70360adc1a..1e665820b3 100644 --- a/apps/indexer/config/prod/besu.exs +++ b/apps/indexer/config/prod/besu.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ @@ -16,7 +22,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] ], variant: EthereumJSONRPC.Besu ], diff --git a/apps/indexer/config/prod/erigon.exs b/apps/indexer/config/prod/erigon.exs index 0ea6127965..aa1c0db2c9 100644 --- a/apps/indexer/config/prod/erigon.exs +++ b/apps/indexer/config/prod/erigon.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ @@ -16,7 +22,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] ], variant: EthereumJSONRPC.Erigon ], diff --git a/apps/indexer/config/prod/ganache.exs b/apps/indexer/config/prod/ganache.exs index ee377b5022..c073851411 100644 --- a/apps/indexer/config/prod/ganache.exs +++ b/apps/indexer/config/prod/ganache.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ @@ -11,7 +17,7 @@ config :indexer, transport_options: [ http: EthereumJSONRPC.HTTP.HTTPoison, url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", - http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: hackney_opts] ], variant: EthereumJSONRPC.Ganache ], diff --git a/apps/indexer/config/prod/geth.exs b/apps/indexer/config/prod/geth.exs index 076abdcb52..00c35fde33 100644 --- a/apps/indexer/config/prod/geth.exs +++ b/apps/indexer/config/prod/geth.exs @@ -1,13 +1,10 @@ import Config -hackney_opts_base = [pool: :ethereum_jsonrpc] +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() -hackney_opts = - if System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true" do - [:insecure] ++ hackney_opts_base - else - hackney_opts_base - end +hackney_opts = ConfigHelper.hackney_options() config :indexer, block_interval: :timer.seconds(5), diff --git a/apps/indexer/config/prod/nethermind.exs b/apps/indexer/config/prod/nethermind.exs index bb44f66d5d..2f4b8f1d08 100644 --- a/apps/indexer/config/prod/nethermind.exs +++ b/apps/indexer/config/prod/nethermind.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), json_rpc_named_arguments: [ @@ -16,7 +22,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] ], variant: EthereumJSONRPC.Nethermind ], diff --git a/apps/indexer/config/prod/rsk.exs b/apps/indexer/config/prod/rsk.exs index daa5f22454..3b4bb8bee7 100644 --- a/apps/indexer/config/prod/rsk.exs +++ b/apps/indexer/config/prod/rsk.exs @@ -1,5 +1,11 @@ import Config +~w(config config_helper.exs) +|> Path.join() +|> Code.eval_file() + +hackney_opts = ConfigHelper.hackney_options() + config :indexer, block_interval: :timer.seconds(5), blocks_concurrency: 1, @@ -18,7 +24,7 @@ config :indexer, trace_block: System.get_env("ETHEREUM_JSONRPC_TRACE_URL"), trace_replayTransaction: System.get_env("ETHEREUM_JSONRPC_TRACE_URL") ], - http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]] + http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: hackney_opts] ], variant: EthereumJSONRPC.RSK ], diff --git a/config/config_helper.exs b/config/config_helper.exs new file mode 100644 index 0000000000..1c42c64dc0 --- /dev/null +++ b/config/config_helper.exs @@ -0,0 +1,14 @@ +defmodule ConfigHelper do + def hackney_options() do + basic_auth_user = System.get_env("ETHEREUM_JSONRPC_USER", "") + basic_auth_pass = System.get_env("ETHEREUM_JSONRPC_PASSWORD", nil) + + hackney_opts = + [pool: :ethereum_jsonrpc] + |> (&if(System.get_env("ETHEREUM_JSONRPC_HTTP_INSECURE", "") == "true", do: [:insecure] ++ &1, else: &1)).() + |> (&if(basic_auth_user != "" && !is_nil(basic_auth_pass), + do: [basic_auth: {basic_auth_user, basic_auth_pass}] ++ &1, + else: &1 + )).() + end +end diff --git a/rel/config.exs b/rel/config.exs index eaaa52e36b..905f841f0a 100644 --- a/rel/config.exs +++ b/rel/config.exs @@ -71,7 +71,7 @@ end # will be used by default release :blockscout do - set version: "1.2.0-beta" + set version: "5.1.0-beta" set applications: [ :runtime_tools, block_scout_web: :permanent,