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 mode: :plug
config :block_scout_web, BlockScoutWeb.ApiRouter, config :block_scout_web, BlockScoutWeb.ApiRouter,
enabled: System.get_env("DISABLE_API") != "true", writing_enabled: System.get_env("DISABLE_WRITE_API") != "true",
enabled_update_endpoints: System.get_env("DISABLE_UPDATE_ENDPOINTS") != "true" reading_enabled: System.get_env("DISABLE_READ_API") != "true"
config :block_scout_web, BlockScoutWeb.WebRouter, enabled: System.get_env("DISABLE_WEBAPP") != "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 defmodule BlockScoutWeb.ApiRouter do
@moduledoc """ @moduledoc """
Router for API Router for API
""" """
use BlockScoutWeb, :router use BlockScoutWeb, :router
alias BlockScoutWeb.API.RPC
pipeline :api do pipeline :api do
plug(:accepts, ["json"]) plug(:accepts, ["json"])
end end
@ -13,12 +21,13 @@ defmodule BlockScoutWeb.ApiRouter do
scope "/v1", as: :api_v1 do scope "/v1", as: :api_v1 do
pipe_through(:api) pipe_through(:api)
scope "/", BlockScoutWeb.API.V1 do scope "/" do
get("/supply", SupplyController, :supply) 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, "block" => RPC.BlockController,
"account" => RPC.AddressController, "account" => RPC.AddressController,
"logs" => RPC.LogsController, "logs" => RPC.LogsController,
@ -31,12 +40,13 @@ defmodule BlockScoutWeb.ApiRouter do
end end
# For backward compatibility. Should be removed # For backward compatibility. Should be removed
scope "/", BlockScoutWeb.API.RPC do scope "/" do
alias BlockScoutWeb.API.RPC
pipe_through(:api) pipe_through(:api)
post("/eth_rpc", EthController, :eth_request) post("/eth_rpc", RPC.EthController, :eth_request)
forward("/", RPCTranslator, %{ forward("/", RPCTranslatorForwarder, %{
"block" => RPC.BlockController, "block" => RPC.BlockController,
"account" => RPC.AddressController, "account" => RPC.AddressController,
"logs" => RPC.LogsController, "logs" => RPC.LogsController,

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

@ -68,7 +68,7 @@
<% end %> <% end %>
</li> </li>
<% end %> <% 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"> <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"> <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"> <span class="nav-link-icon">

Loading…
Cancel
Save