Skip to content

Instantly share code, notes, and snippets.

@vijayakumar-psg587
Last active April 21, 2020 10:46
Show Gist options
  • Save vijayakumar-psg587/cb7895b8d3272472410fe8696190400c to your computer and use it in GitHub Desktop.
Save vijayakumar-psg587/cb7895b8d3272472410fe8696190400c to your computer and use it in GitHub Desktop.
export async function downloadEnvFiles(env_name): Promise<any> {
const LOGGER: pino.Logger = PinoLoggerServiceInstance.getLogger(__filename);
return new Promise(async (res, rej) => {
// Get the storage
const str = GcloudAuthenticationInstance.createGcloudAuthenticationBucket();
try {
// get the file list from the storage and the bucket
const [files] = await str.bucket(GCLOUD_ENV_STR_BUCKET_NAME).getFiles();
// filter the req file
const filteredFile =
ENV_NAME_DEV === env_name
? _.find(files, (file) => {
return file.name.includes(GCLOUD_STORED_FILE_NAME_DEV);
})
: _.find(files, (file) => {
return file.name.includes(GCLOUD_STORED_FILE_NAME_PROD);
});
// send it as a stream
res({
status: 'Success',
code: 200,
error: null,
stream: str
.bucket(GCLOUD_ENV_STR_BUCKET_NAME)
.file(filteredFile.name)
.createReadStream(),
});
} catch (err) {
LOGGER.error('Error in retrieving files from gcloud', err);
rej({ status: 'Error', error: err, code: 500 });
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment