Skip to content

Commit

Permalink
Support basic auth in JSON RPC endpoint (blockscout#6897)
Browse files Browse the repository at this point in the history
* 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 <max.pengwyn@gmail.com>
  • Loading branch information
vbaranov and sl1depengwyn committed Feb 17, 2023
1 parent 7a704d8 commit 65d7ad5
Show file tree
Hide file tree
Showing 31 changed files with 166 additions and 126 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
11 changes: 4 additions & 7 deletions 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: [
Expand Down
8 changes: 7 additions & 1 deletion 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: [
Expand All @@ -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
],
Expand Down
8 changes: 7 additions & 1 deletion 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: [
Expand All @@ -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
],
Expand Down
8 changes: 7 additions & 1 deletion 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: [
Expand All @@ -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
],
Expand Down
8 changes: 7 additions & 1 deletion 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: [
Expand All @@ -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
],
Expand Down
11 changes: 4 additions & 7 deletions 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),
Expand Down
10 changes: 8 additions & 2 deletions 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: [
Expand All @@ -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
],
Expand All @@ -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
# ]
Expand Down

0 comments on commit 65d7ad5

Please sign in to comment.