razor-network/oracle-node

Fetch api keys, secrets etc from env and apply it to jobs

SkandaBhat opened this issue · 2 comments

Analysis: some URLs may require authentication or API keys.

Possible solution: Consider reading the keys from env and substituting it while fetching a job.

API keys can be passed in two ways:

1) Sending API key directly In URL

  • If we are passing API keys directly in url then we need to follow a certain regex while creating jobs for all the jobs which requires api key.

  • e.g. if this is the required format for this API
    /v1/exchangerate/BTC?apikey=73034021746739393292922SAMPLE-KEY

  • Than we can create a job following this,
    /v1/exchangerate/BTC?apikey={API_KEY_REGEX}

2) Sending API key via authorization headers

  • Here the problem is how would node know when to follow this and there would be different formats followed for different APIs as each API have different documentation.

As suggested

// API key should be directly fetched from os environment 
// Use os.Getenv() as used here https://gobyexample.com/environment-variables instead of depending on godotenv library.
// Followed format {API_KEY_KEYWORD} as regex in urls to search for keyword and respective value from os env variables. 

Implemented the same in #1097

While defining the job which requires a API key, staker needs to follow regex defined in constants.go , which is set to e.g ${API_KEY_KEYWORD}.

e.g. if this is the required format for this API

https://api.gemini.com/v1/pubticker/v1/exchangerate/BTC?apikey=73034021746739393292922

Than a job with url can be created as shown below,

https://api.gemini.com/v1/pubticker/v1/exchangerate/BTC?apikey=${COINAPI_API_KEY}

Now staker needs to use the same keyword defined inside ${...} as a environment variable using export command and assigning it a value as users API key as shown below.

export COINAPI_API_KEY="73034021746739393292922"

Oracle node will directly look for the same in os environment variables and pick the respective value.
@ashish10677 @SkandaBhat