Skip to content

Commit

Permalink
Add indexer auth token support (#4591)
Browse files Browse the repository at this point in the history
* add indexer auth token support
* add ANALYTICS_SERVICE_TOKEN to configs
* linter fix
---------
Co-authored-by: Alexander Pyatakov <[email protected]>
  • Loading branch information
vshvets-bc authored Jan 30, 2025
1 parent a22531a commit 59b8de2
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions configs/.env..guardian.system
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions configs/.env.develop.guardian.system
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions configs/.env.template.guardian.system
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion interfaces/src/type/messages/workers.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
2 changes: 2 additions & 0 deletions worker-service/configs/.env.worker
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -65,3 +66,4 @@ SEQ_API_KEY=""
MIN_POOL_SIZE="1"
MAX_POOL_SIZE="5"
MAX_IDLE_TIME_MS="30000"

1 change: 1 addition & 0 deletions worker-service/configs/.env.worker.develop
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions worker-service/configs/.env.worker.template
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 23 additions & 3 deletions worker-service/src/api/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ function rejectTimeout(t: number): Promise<void> {
})
}


function getAnalytycsHeaders() {
const headers: any = {};
const token = process.env.ANALYTICS_SERVICE_TOKEN;
if (token) {
headers.Authorization = `Bearer ${token}`
}
return headers;
}

/**
* Worker class
*/
Expand Down Expand Up @@ -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) {
Expand All @@ -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;

Expand All @@ -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) {
Expand Down

0 comments on commit 59b8de2

Please sign in to comment.