Skip to content

Commit

Permalink
select api key from env var first
Browse files Browse the repository at this point in the history
  • Loading branch information
haseebrabbani committed Oct 19, 2023
1 parent a659e25 commit 594ab2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 5 additions & 4 deletions python-sdk/src/forta_agent/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ def get_forta_api_url():
def get_forta_api_headers():
headers = {"content-type": "application/json"}

config = get_forta_config()
if "fortaApiKey" in config:
headers["Authorization"] = f'Bearer {config.get("fortaApiKey")}'
elif 'FORTA_API_KEY' in os.environ:
if 'FORTA_API_KEY' in os.environ:
headers["Authorization"] = f'Bearer {os.environ["FORTA_API_KEY"]}'
else:
config = get_forta_config()
if "fortaApiKey" in config:
headers["Authorization"] = f'Bearer {config.get("fortaApiKey")}'

return headers

Expand Down
13 changes: 8 additions & 5 deletions sdk/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,15 @@ export const getFortaApiURL = () => {
export const getFortaApiHeaders = () => {
const headers: any = { "content-type": "application/json" };

// use the api key from forta config if available (only for local development)
let { fortaApiKey } = getFortaConfig();
if (fortaApiKey) {
headers["Authorization"] = `Bearer ${fortaApiKey}`;
} else if (process.env.FORTA_API_KEY) {
// try the api key specified in env vars first
if (process.env.FORTA_API_KEY) {
headers["Authorization"] = `Bearer ${process.env.FORTA_API_KEY}`;
} else {
// use the api key from forta config if available (only for local development)
let { fortaApiKey } = getFortaConfig();
if (fortaApiKey) {
headers["Authorization"] = `Bearer ${fortaApiKey}`;
}
}

return {
Expand Down

0 comments on commit 594ab2e

Please sign in to comment.