MCPcopy Create free account
hub / github.com/api3dao/airnode / fetchDeployments

Function fetchDeployments

packages/airnode-deployer/src/infrastructure/index.ts:480–587  ·  view source on GitHub ↗
(cloudProviderType: CloudProvider['type'], deploymentId?: string)

Source from the content-addressed store, hash-verified

478
479// If deploymentId is provided it tries to fetch only that one deployment and returns early when found
480async function fetchDeployments(cloudProviderType: CloudProvider['type'], deploymentId?: string) {
481 const deployments: Deployment[] = [];
482
483 const bucket = await cloudProviderLib[cloudProviderType].getAirnodeBucket();
484 if (!bucket) {
485 logger.debug(`No deployments available on ${cloudProviderType.toUpperCase()}`);
486 return deployments;
487 }
488
489 const directoryStructure = await cloudProviderLib[cloudProviderType].getBucketDirectoryStructure(bucket);
490 const bucketMissingFiles = getMissingBucketFiles(directoryStructure);
491
492 for (const [airnodeAddress, addressDirectory] of Object.entries(directoryStructure)) {
493 if (addressDirectory.type !== FileSystemType.Directory) {
494 logger.warn(
495 `Invalid item in bucket '${bucket.name}' (${cloudProviderType.toUpperCase()}) with key '${
496 addressDirectory.bucketKey
497 }'. Skipping.`
498 );
499 continue;
500 }
501
502 for (const [stage, stageDirectory] of Object.entries(addressDirectory.children)) {
503 if (stageDirectory.type !== FileSystemType.Directory) {
504 logger.warn(
505 `Invalid item in bucket '${bucket.name}' (${cloudProviderType.toUpperCase()}) with key '${
506 stageDirectory.bucketKey
507 }'. Skipping.`
508 );
509 continue;
510 }
511
512 const latestDeployment = Object.keys(stageDirectory.children).sort().reverse()[0];
513
514 if (
515 bucketMissingFiles[airnodeAddress] &&
516 bucketMissingFiles[airnodeAddress][stage] &&
517 bucketMissingFiles[airnodeAddress][stage].length !== 0
518 ) {
519 continue;
520 }
521
522 const bucketLatestDeploymentPath = `${airnodeAddress}/${stage}/${latestDeployment}`;
523
524 const bucketConfigPath = `${bucketLatestDeploymentPath}/config.json`;
525 logger.debug(`Fetching configuration file '${bucketConfigPath}'`);
526 const goGetConfigFileFromBucket = await go(() =>
527 cloudProviderLib[cloudProviderType].getFileFromBucket(bucket, bucketConfigPath)
528 );
529 if (!goGetConfigFileFromBucket.success) {
530 logger.warn(`Failed to fetch configuration file. Error: ${goGetConfigFileFromBucket.error.message} Skipping.`);
531 continue;
532 }
533 const goConfig = goSync(() => JSON.parse(goGetConfigFileFromBucket.data));
534 if (!goConfig.success) {
535 logger.warn(`Failed to parse configuration file. Error: ${goConfig.error.message} Skipping.`);
536 continue;
537 }

Callers 2

fetchDeploymentFunction · 0.85
listAirnodesFunction · 0.85

Calls 5

getMissingBucketFilesFunction · 0.90
deriveDeploymentIdFunction · 0.90
warnMethod · 0.80

Tested by

no test coverage detected