near / near-cli

General purpose command line tools for interacting with NEAR Protocol
https://docs.near.org
MIT License
193 stars 91 forks source link

x-api-key is not added to the request headers if the nodeUrl is passed as option #1051

Closed xilosada closed 1 year ago

xilosada commented 1 year ago

Describe the bug Near CLI allows to set up an api key for an specific node using near set-api-key. However this is ignored when we execute a command passing nodeUrl or node_url options.

To Reproduce If we set the api key to the desired nodeUrl the request doesn't have the api key in the headers

$ near set-api-key https://api.calimero.network/api/v1/shards/demos-calimero-testnet/neard-rpc/ <api-key>
$ near create-account new_account.demos.calimero.testnet --masterAccount demos.calimero.testnet --networkId demos-calimero-testnet --nodeUrl https://api.calimero.network/api/v1/shards/demos-calimero-testnet/neard-rpc
An error occured
UnauthorizedError: No auth token

To trick this behaviour it has to be set to the RPC used in the config

$ near set-api-key https://rpc.testnet.near.org  86dd252bf0cc3971e0175af6284fe4f7cf8bf2fb5beed558c0a1aec55fd01821 --networkId demos-calimero-testnet
$ near create-account new_account.demos.calimero.testnet --masterAccount demos.calimero.testnet --networkId demos-calimero-testnet --nodeUrl https://api.calimero.network/api/v1/shards/demos-calimero-testnet/neard-rpc
Account new_account.demos.calimero.testnet for network "demos-calimero-testnet" was created.

Expected behavior x-api-key should be added based on the nodeUrl option passed to the command instead of the nodeUrl in base config.