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

Function fetchFiles

packages/airnode-deployer/src/infrastructure/index.ts:796–840  ·  view source on GitHub ↗
(deploymentId: string, outputDir: string, versionId?: string)

Source from the content-addressed store, hash-verified

794}
795
796export async function fetchFiles(deploymentId: string, outputDir: string, versionId?: string) {
797 const cloudProviderType = deploymentId.slice(0, 3) as CloudProvider['type'];
798 if (!availableCloudProviders.includes(cloudProviderType)) {
799 throw new Error(`Invalid deployment ID '${deploymentId}'`);
800 }
801
802 const spinner = logger.getSpinner();
803
804 spinner.start(`Fetching files for deployment '${deploymentId}'${versionId ? ` and version '${versionId}'` : ''}'`);
805 if (logger.inDebugMode()) {
806 spinner.info();
807 }
808
809 const goFetchDeployment = await go(() => fetchDeployment(cloudProviderType, deploymentId, versionId));
810 if (!goFetchDeployment.success) {
811 spinner.stop();
812 throw goFetchDeployment.error;
813 }
814 const { deployment, version } = goFetchDeployment.data;
815
816 const goDownloadDeploymentFiles = await go(() => downloadDeploymentFiles(cloudProviderType, deployment, version));
817 if (!goDownloadDeploymentFiles.success) {
818 spinner.stop();
819 throw goDownloadDeploymentFiles.error;
820 }
821 const { configContent, secretsContent } = goDownloadDeploymentFiles.data;
822
823 const goOutputWritable = goSync(() => fs.accessSync(outputDir, fs.constants.W_OK));
824 if (!goOutputWritable.success) {
825 spinner.stop();
826 throw new Error(`Can't write into an output directory '${outputDir}': ${goOutputWritable.error}`);
827 }
828
829 const zip = new AdmZip();
830 zip.addFile('config.json', Buffer.from(configContent, 'utf8'));
831 zip.addFile('secrets.env', Buffer.from(secretsContent, 'utf8'));
832 const outputFile = path.join(outputDir, `${deploymentId}-${version.id}.zip`);
833 const goWriteZip = await go(() => zip.writeZipPromise(outputFile));
834 if (!goWriteZip.success) {
835 spinner.stop();
836 throw new Error(`Can't create a zip file '${outputFile}': ${goWriteZip.error}`);
837 }
838
839 spinner.succeed(`Files successfully downloaded as '${outputFile}'`);
840}
841
842export async function saveDeploymentFiles(
843 deploymentId: string,

Callers 1

index.tsFile · 0.90

Calls 6

fetchDeploymentFunction · 0.85
downloadDeploymentFilesFunction · 0.85
startMethod · 0.80
infoMethod · 0.80
stopMethod · 0.80
succeedMethod · 0.80

Tested by

no test coverage detected