Add vars to disable writing or reading API's methods

pull/2376/head
saneery 5 years ago
parent bb03a4a39b
commit e5c5cda9e9
  1. 4
      apps/block_scout_web/config/config.exs
  2. 28
      apps/block_scout_web/lib/block_scout_web/api_router.ex
  3. 16
      apps/block_scout_web/lib/block_scout_web/router.ex
  4. 2
      apps/block_scout_web/lib/block_scout_web/templates/layout/_topnav.html.eex

@ -89,8 +89,8 @@ config :wobserver,
mode: :plug
config :block_scout_web, BlockScoutWeb.ApiRouter,
enabled: System.get_env("DISABLE_API") != "true",
enabled_update_endpoints: System.get_env("DISABLE_UPDATE_ENDPOINTS") != "true"
writing_enabled: System.get_env("DISABLE_WRITE_API") != "true",
reading_enabled: System.get_env("DISABLE_READ_API") != "true"
config :block_scout_web, BlockScoutWeb.WebRouter, enabled: System.get_env("DISABLE_WEBAPP") != "true"

@ -1,11 +1,19 @@
defmodule RPCTranslatorForwarder do
@moduledoc """
Phoenix router limits forwarding,
so this module is to forward old paths for backward compatibility
"""
alias BlockScoutWeb.API.RPC.RPCTranslator
defdelegate init(opts), to: RPCTranslator
defdelegate call(conn, opts), to: RPCTranslator
end
defmodule BlockScoutWeb.ApiRouter do
@moduledoc """
Router for API
"""
use BlockScoutWeb, :router
alias BlockScoutWeb.API.RPC
pipeline :api do
plug(:accepts, ["json"])
end
@ -13,12 +21,13 @@ defmodule BlockScoutWeb.ApiRouter do
scope "/v1", as: :api_v1 do
pipe_through(:api)
scope "/", BlockScoutWeb.API.V1 do
get("/supply", SupplyController, :supply)
scope "/" do
alias BlockScoutWeb.API.{RPC, V1}
get("/supply", V1.SupplyController, :supply)
post("/eth_rpc", EthController, :eth_request)
post("/eth_rpc", RPC.EthController, :eth_request)
forward("/", RPCTranslator, %{
forward("/", RPC.RPCTranslator, %{
"block" => RPC.BlockController,
"account" => RPC.AddressController,
"logs" => RPC.LogsController,
@ -31,12 +40,13 @@ defmodule BlockScoutWeb.ApiRouter do
end
# For backward compatibility. Should be removed
scope "/", BlockScoutWeb.API.RPC do
scope "/" do
alias BlockScoutWeb.API.RPC
pipe_through(:api)
post("/eth_rpc", EthController, :eth_request)
post("/eth_rpc", RPC.EthController, :eth_request)
forward("/", RPCTranslator, %{
forward("/", RPCTranslatorForwarder, %{
"block" => RPC.BlockController,
"account" => RPC.AddressController,
"logs" => RPC.LogsController,

@ -23,19 +23,13 @@ defmodule BlockScoutWeb.Router do
pipe_through(:api)
get("/health", HealthController, :health)
if Application.get_env(:block_scout_web, ApiRouter)[:enabled_update_endpoints] do
if Application.get_env(:block_scout_web, ApiRouter)[:writing_enabled] do
post("/decompiled_smart_contract", DecompiledSmartContractController, :create)
post("/verified_smart_contracts", VerifiedSmartContractController, :create)
end
end
scope "/verify_smart_contract" do
pipe_through(:api)
post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create)
end
if Application.get_env(:block_scout_web, ApiRouter)[:enabled] do
if Application.get_env(:block_scout_web, ApiRouter)[:reading_enabled] do
forward("/api", ApiRouter)
# Needs to be 200 to support the schema introspection for graphiql
@ -70,6 +64,12 @@ defmodule BlockScoutWeb.Router do
get("/eth_rpc_api_docs", APIDocsController, :eth_rpc)
end
scope "/verify_smart_contract" do
pipe_through(:api)
post("/contract_verifications", BlockScoutWeb.AddressContractVerificationController, :create)
end
if Application.get_env(:block_scout_web, WebRouter)[:enabled] do
forward("/", BlockScoutWeb.WebRouter)
else

@ -68,7 +68,7 @@
<% end %>
</li>
<% end %>
<%= if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:enabled] or Application.get_env(:block_scout_web, :api_url) do %>
<%= if Application.get_env(:block_scout_web, BlockScoutWeb.ApiRouter)[:reading_enabled] || Application.get_env(:block_scout_web, :api_url) do %>
<li class="nav-item dropdown">
<a href="#" role="button" id="navbarAPIsDropdown" class="nav-link topnav-nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="nav-link-icon">

Loading…
Cancel
Save