The Chain 138 RPC access product catalog (core-rpc / alltra-rpc /
thirdweb-rpc, each with VMID + HTTP/WS URL + tier + billing model + use
cases + management features) used to be a hardcoded 50-line Go literal
in api/rest/auth.go. The review flagged this as the biggest source of
'magic constants in source' in the backend: changing a partner URL, a
VMID, or a billing model required a Go recompile, and the internal
192.168.11.x CIDR endpoints were baked into the binary.
This PR moves the catalog to backend/config/rpc_products.yaml and adds
a lazy loader so every call site reads from the YAML on first use.
New files:
backend/config/rpc_products.yaml source of truth
backend/api/rest/rpc_products_config.go loader + fallback defaults
backend/api/rest/rpc_products_config_test.go unit tests
Loader path-resolution order (first hit wins):
1. $RPC_PRODUCTS_PATH (absolute or cwd-relative)
2. $EXPLORER_BACKEND_DIR/config/rpc_products.yaml
3. <cwd>/backend/config/rpc_products.yaml
4. <cwd>/config/rpc_products.yaml
5. compiled-in defaultRPCAccessProducts fallback (logs a WARNING)
Validation on load:
- every product must have a non-empty slug,
- every product must have a non-empty http_url,
- slugs must be unique across the catalog.
A malformed YAML causes a WARNING + fallback to defaults, never a
silent empty product list.
Call-site changes in auth.go:
- 'var rpcAccessProducts []accessProduct' (literal) -> func
rpcAccessProducts() []accessProduct (forwards to the lazy loader).
- Both existing consumers (/api/v1/access/products handler at line
~369 and findAccessProduct() at line ~627) now call the function.
Zero other behavioural changes; the JSON shape of the response is
byte-identical.
Tests added:
- TestLoadRPCAccessProductsFromRepoDefault: confirms the shipped
YAML loads, produces >=3 products, and contains the 3 expected
slugs with non-empty http_url.
- TestLoadRPCAccessProductsRejectsDuplicateSlug.
- TestLoadRPCAccessProductsRejectsMissingHTTPURL.
Verification:
go build ./... clean
go vet ./... clean
go test ./api/rest/ PASS (new + existing)
go mod tidy pulled yaml.v3 from indirect to direct
Advances completion criterion 7 (no magic constants): 'Chain 138
access products / VMIDs / provider URLs live in a YAML that operators
can change without a rebuild; internal CIDRs are no longer required
to be present in source.'
57 lines
2.3 KiB
Modula-2
57 lines
2.3 KiB
Modula-2
module github.com/explorer/backend
|
|
|
|
go 1.23.0
|
|
|
|
toolchain go1.24.11
|
|
|
|
require (
|
|
github.com/elastic/go-elasticsearch/v8 v8.11.0
|
|
github.com/ethereum/go-ethereum v1.13.5
|
|
github.com/golang-jwt/jwt/v4 v4.5.2
|
|
github.com/gorilla/websocket v1.5.1
|
|
github.com/jackc/pgx/v5 v5.5.1
|
|
github.com/redis/go-redis/v9 v9.17.2
|
|
github.com/stretchr/testify v1.11.1
|
|
golang.org/x/crypto v0.36.0
|
|
gopkg.in/yaml.v3 v3.0.1
|
|
)
|
|
|
|
require (
|
|
github.com/Microsoft/go-winio v0.6.1 // indirect
|
|
github.com/StackExchange/wmi v1.2.1 // indirect
|
|
github.com/bits-and-blooms/bitset v1.7.0 // indirect
|
|
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
|
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
|
github.com/consensys/bavard v0.1.13 // indirect
|
|
github.com/consensys/gnark-crypto v0.12.1 // indirect
|
|
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
|
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
|
|
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
|
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
|
github.com/elastic/elastic-transport-go/v8 v8.3.0 // indirect
|
|
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
|
|
github.com/go-ole/go-ole v1.2.5 // indirect
|
|
github.com/go-stack/stack v1.8.1 // indirect
|
|
github.com/holiman/uint256 v1.2.3 // indirect
|
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
|
github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect
|
|
github.com/jackc/puddle/v2 v2.2.1 // indirect
|
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
|
github.com/mmcloughlin/addchain v0.4.0 // indirect
|
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
|
|
github.com/supranational/blst v0.3.11 // indirect
|
|
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
|
github.com/tklauser/numcpus v0.6.1 // indirect
|
|
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
|
golang.org/x/mod v0.17.0 // indirect
|
|
golang.org/x/net v0.38.0 // indirect
|
|
golang.org/x/sync v0.12.0 // indirect
|
|
golang.org/x/sys v0.31.0 // indirect
|
|
golang.org/x/text v0.23.0 // indirect
|
|
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
|
|
google.golang.org/protobuf v1.33.0 // indirect
|
|
rsc.io/tmplfunc v0.0.3 // indirect
|
|
)
|