chore: Set user agent to metadata requests (#10834)

* chore: Set user agent to metadata requests

* Add backend version to User-agent
production-redstone
Victor Baranov 1 month ago committed by GitHub
parent 7d763c0cbc
commit f71a4cc4c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 9
      apps/explorer/lib/explorer/token/metadata_retriever.ex
  2. 2
      apps/explorer/test/explorer/token/metadata_retriever_test.exs
  3. 3
      bin/version_bump.sh

@ -14,6 +14,7 @@ defmodule Explorer.Token.MetadataRetriever do
@no_uri_error "no uri" @no_uri_error "no uri"
@vm_execution_error "VM execution error" @vm_execution_error "VM execution error"
@invalid_base64_data "invalid data:application/json;base64" @invalid_base64_data "invalid data:application/json;base64"
@default_headers [{"User-Agent", "blockscout-6.8.1"}]
# https://eips.ethereum.org/EIPS/eip-1155#metadata # https://eips.ethereum.org/EIPS/eip-1155#metadata
@erc1155_token_id_placeholder "{id}" @erc1155_token_id_placeholder "{id}"
@ -475,12 +476,12 @@ defmodule Explorer.Token.MetadataRetriever do
gateway_url_param_value = ipfs_params[:gateway_url_param_value] gateway_url_param_value = ipfs_params[:gateway_url_param_value]
if gateway_url_param_key && gateway_url_param_value do if gateway_url_param_key && gateway_url_param_value do
[{gateway_url_param_key, gateway_url_param_value}] [{gateway_url_param_key, gateway_url_param_value} | @default_headers]
else else
[] @default_headers
end end
else else
[] @default_headers
end end
end end
@ -670,7 +671,7 @@ defmodule Explorer.Token.MetadataRetriever do
end end
defp fetch_metadata_from_uri_request(uri, hex_token_id, ipfs?) do defp fetch_metadata_from_uri_request(uri, hex_token_id, ipfs?) do
headers = if ipfs?, do: ipfs_headers(), else: [] headers = if ipfs?, do: ipfs_headers(), else: @default_headers
case Application.get_env(:explorer, :http_adapter).get(uri, headers, case Application.get_env(:explorer, :http_adapter).get(uri, headers,
recv_timeout: 30_000, recv_timeout: 30_000,

@ -763,7 +763,7 @@ defmodule Explorer.Token.MetadataRetrieverTest do
Explorer.Mox.HTTPoison Explorer.Mox.HTTPoison
|> expect(:get, fn "https://ipfs.io/ipfs/QmT1Yz43R1PLn2RVovAnEM5dHQEvpTcnwgX8zftvY1FcjP", |> expect(:get, fn "https://ipfs.io/ipfs/QmT1Yz43R1PLn2RVovAnEM5dHQEvpTcnwgX8zftvY1FcjP",
[{"x-apikey", "mykey"}], [{"x-apikey", "mykey"}, {"User-Agent", _}],
_options -> _options ->
{:ok, %HTTPoison.Response{status_code: 200, body: Jason.encode!(result)}} {:ok, %HTTPoison.Response{status_code: 200, body: Jason.encode!(result)}}
end) end)

@ -12,6 +12,7 @@ CONFIG_FILE="$(pwd)/rel/config.exs"
DOCKER_COMPOSE_FILE="$(pwd)/docker-compose/docker-compose.yml" DOCKER_COMPOSE_FILE="$(pwd)/docker-compose/docker-compose.yml"
MAKE_FILE="$(pwd)/docker/Makefile" MAKE_FILE="$(pwd)/docker/Makefile"
WORKFLOW_FILES=($(find "$(pwd)/.github/workflows" -type f \( -name "pre-release-*" -o -name "release-*" -o -name "publish-docker-image-*" \))) WORKFLOW_FILES=($(find "$(pwd)/.github/workflows" -type f \( -name "pre-release-*" -o -name "release-*" -o -name "publish-docker-image-*" \)))
METADATA_RETRIEVER_FILE="$(pwd)/apps/explorer/lib/explorer/token/metadata_retriever.ex"
# Function to bump version # Function to bump version
bump_version() { bump_version() {
@ -69,6 +70,8 @@ bump_version() {
sed -i '' "s/RELEASE_VERSION: $current_version/RELEASE_VERSION: $new_version/" "$WORKFLOW_FILE" sed -i '' "s/RELEASE_VERSION: $current_version/RELEASE_VERSION: $new_version/" "$WORKFLOW_FILE"
done done
sed -i '' "s/\"blockscout-$current_version\"/\"blockscout-$new_version\"/" "$METADATA_RETRIEVER_FILE"
echo "Version bumped from $current_version to $new_version" echo "Version bumped from $current_version to $new_version"
} }

Loading…
Cancel
Save