From 59b8de2d2ae6d086aa805e0e9645b56342b24fe1 Mon Sep 17 00:00:00 2001 From: Volodymyr Shvets <54721244+vshvets-bc@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:01:23 +0200 Subject: [PATCH] Add indexer auth token support (#4591) * add indexer auth token support * add ANALYTICS_SERVICE_TOKEN to configs * linter fix --------- Co-authored-by: Alexander Pyatakov --- configs/.env..guardian.system | 1 + configs/.env.develop.guardian.system | 1 + configs/.env.template.guardian.system | 2 ++ interfaces/src/type/messages/workers.type.ts | 2 +- worker-service/configs/.env.worker | 2 ++ worker-service/configs/.env.worker.develop | 1 + worker-service/configs/.env.worker.template | 1 + worker-service/src/api/worker.ts | 26 +++++++++++++++++--- 8 files changed, 32 insertions(+), 4 deletions(-) diff --git a/configs/.env..guardian.system b/configs/.env..guardian.system index 81b62c7933..ee0750b8fa 100644 --- a/configs/.env..guardian.system +++ b/configs/.env..guardian.system @@ -71,6 +71,7 @@ IPFS_PUBLIC_GATEWAY='https://ipfs.io/ipfs/${cid}' # use this for public provider #IPFS_PUBLIC_GATEWAY='http://ipfs-node:8080/ipfs/${cid}' # use this for local provider IPFS_NODE_ADDRESS="http://ipfs-node:5001" # only valid for local provider; ignored in other cases ANALYTICS_SERVICE="http://indexer-api-gateway:3021" +#ANALYTICS_SERVICE_TOKEN="" # mandatory to be able to use the MGS indexer #BATCH_NFT_MINT_SIZE=10 # FE/DEMO diff --git a/configs/.env.develop.guardian.system b/configs/.env.develop.guardian.system index 60e81a2038..38fefa9c14 100644 --- a/configs/.env.develop.guardian.system +++ b/configs/.env.develop.guardian.system @@ -72,6 +72,7 @@ IPFS_PUBLIC_GATEWAY='https://ipfs.io/ipfs/${cid}' # use this for public provider #IPFS_PUBLIC_GATEWAY='http://ipfs-node:8080/ipfs/${cid}' # use this for local provider IPFS_NODE_ADDRESS="http://ipfs-node:5001" # only valid for local provider; ignored in other cases ANALYTICS_SERVICE="http://indexer-api-gateway:3021" +#ANALYTICS_SERVICE_TOKEN="" # mandatory to be able to use the MGS indexer #BATCH_NFT_MINT_SIZE=10 # FE/DEMO diff --git a/configs/.env.template.guardian.system b/configs/.env.template.guardian.system index c19a21d792..dcc943b000 100644 --- a/configs/.env.template.guardian.system +++ b/configs/.env.template.guardian.system @@ -88,6 +88,8 @@ IPFS_PUBLIC_GATEWAY='https://ipfs.io/ipfs/${cid}' # use this for public provider #IPFS_PUBLIC_GATEWAY='http://ipfs-node:8080/ipfs/${cid}' # use this for local provider IPFS_NODE_ADDRESS="http://ipfs-node:5001" # only valid for local provider; ignored in other cases ANALYTICS_SERVICE="http://indexer-api-gateway:3021" +#ANALYTICS_SERVICE_TOKEN="" # mandatory to be able to use the MGS indexer + #BATCH_NFT_MINT_SIZE=10 # FE/DEMO diff --git a/interfaces/src/type/messages/workers.type.ts b/interfaces/src/type/messages/workers.type.ts index 68f623c540..e9fd817688 100644 --- a/interfaces/src/type/messages/workers.type.ts +++ b/interfaces/src/type/messages/workers.type.ts @@ -38,7 +38,7 @@ export enum WorkerTaskType { GET_CONTRACT_EVENTS = 'get-contract-events', GET_TRANSACTIONS = 'get-transaction', ANALYTICS_SEARCH_POLICIES = 'analytics-search-policies', - ANALYTICS_GET_INDEXER_AVAILABILITY = "analytics-get-indexer-availability", + ANALYTICS_GET_INDEXER_AVAILABILITY = 'analytics-get-indexer-availability', ANALYTICS_GET_RETIRE_DOCUMENTS = 'analytics-get-retire-documents' } diff --git a/worker-service/configs/.env.worker b/worker-service/configs/.env.worker index 486a3e9623..2a7d7629cc 100644 --- a/worker-service/configs/.env.worker +++ b/worker-service/configs/.env.worker @@ -18,6 +18,7 @@ IPFS_PROVIDER="web3storage" # 'filebase', 'web3storage' or 'local' IPFS_PUBLIC_GATEWAY='https://ipfs.eth.aragon.network/ipfs/${cid}' IPFS_NODE_ADDRESS="http://localhost:5001" ANALYTICS_SERVICE="http://localhost:3021" +#ANALYTICS_SERVICE_TOKEN="" # mandatory to be able to use the MGS indexer IPFS_STORAGE_KEY="..." IPFS_STORAGE_PROOF="..." MAX_HEDERA_TIMEOUT="600" @@ -65,3 +66,4 @@ SEQ_API_KEY="" MIN_POOL_SIZE="1" MAX_POOL_SIZE="5" MAX_IDLE_TIME_MS="30000" + diff --git a/worker-service/configs/.env.worker.develop b/worker-service/configs/.env.worker.develop index 8b4d961286..72623c6a2e 100644 --- a/worker-service/configs/.env.worker.develop +++ b/worker-service/configs/.env.worker.develop @@ -18,6 +18,7 @@ IPFS_PROVIDER="web3storage" # 'filebase', 'web3storage' or 'local' IPFS_PUBLIC_GATEWAY='https://w3s.link/ipfs/${cid}' IPFS_NODE_ADDRESS="http://localhost:5001" ANALYTICS_SERVICE="http://localhost:3021" +#ANALYTICS_SERVICE_TOKEN="" # mandatory to be able to use the MGS indexer IPFS_STORAGE_KEY="..." IPFS_STORAGE_PROOF="..." MAX_HEDERA_TIMEOUT="600" diff --git a/worker-service/configs/.env.worker.template b/worker-service/configs/.env.worker.template index a9f04c172f..3cf1fb6f66 100644 --- a/worker-service/configs/.env.worker.template +++ b/worker-service/configs/.env.worker.template @@ -18,6 +18,7 @@ IPFS_PROVIDER="web3storage" # 'filebase', 'web3storage' or 'local' IPFS_PUBLIC_GATEWAY='https://ipfs.io/ipfs/${cid}' IPFS_NODE_ADDRESS="http://localhost:5001" ANALYTICS_SERVICE="http://localhost:3021" +#ANALYTICS_SERVICE_TOKEN="" # mandatory to be able to use the MGS indexer MAX_HEDERA_TIMEOUT="" MQ_MAX_PAYLOAD="" #LOG_LEVEL="2" diff --git a/worker-service/src/api/worker.ts b/worker-service/src/api/worker.ts index 5230f3f76c..5917d70e8f 100644 --- a/worker-service/src/api/worker.ts +++ b/worker-service/src/api/worker.ts @@ -19,6 +19,16 @@ function rejectTimeout(t: number): Promise { }) } + +function getAnalytycsHeaders() { + const headers: any = {}; + const token = process.env.ANALYTICS_SERVICE_TOKEN; + if (token) { + headers.Authorization = `Bearer ${token}` + } + return headers; +} + /** * Worker class */ @@ -311,10 +321,14 @@ export class Worker extends NatsService { case WorkerTaskType.ANALYTICS_SEARCH_POLICIES: { const { options } = task.data.payload; try { + const headers = getAnalytycsHeaders(); const response = await axios.post( `${this.analyticsService}/analytics/search/policy`, options, - { responseType: 'json' } + { + responseType: 'json', + headers + } ); result.data = response.data; } catch (error) { @@ -330,10 +344,14 @@ export class Worker extends NatsService { case WorkerTaskType.ANALYTICS_GET_RETIRE_DOCUMENTS: { const { options } = task.data.payload; try { + const headers = getAnalytycsHeaders(); const response = await axios.post( `${this.analyticsService}/analytics/search/retire`, options, - { responseType: 'json' } + { + responseType: 'json', + headers + } ); result.data = response.data; @@ -349,8 +367,10 @@ export class Worker extends NatsService { case WorkerTaskType.ANALYTICS_GET_INDEXER_AVAILABILITY: { try { + const headers = getAnalytycsHeaders(); const response = await axios.get( - `${this.analyticsService}/analytics/checkAvailability` + `${this.analyticsService}/analytics/checkAvailability`, + { headers } ); result.data = response.data; } catch (error) {