Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.syncGranule = function syncGranule(event) {
const config = event.config;
const input = event.input;
const stack = config.stack;
const buckets = config.buckets;
const provider = config.provider;
const collection = config.collection;
const forceDownload = config.forceDownload || false;
const downloadBucket = config.downloadBucket;
const duplicateHandling = duplicateHandlingType(event);
// use stack and collection names to suffix fileStagingDir
const fileStagingDir = path.join(
(config.fileStagingDir || 'file-staging'),
stack
);
if (!provider) {
const err = new errors.ProviderNotFound('Provider info not provided');
log.error(err);
return Promise.reject(err);
}
const IngestClass = granuleSelector('ingest', provider.protocol);
const ingest = new IngestClass(
buckets,
async function moveGranules(event) {
// we have to post the meta-xml file of all output granules
// first we check if there is an output file
const config = event.config;
const bucketsConfig = new BucketsConfig(config.buckets);
const moveStagedFiles = get(config, 'moveStagedFiles', true);
const cmrGranuleUrlType = get(config, 'cmrGranuleUrlType', 'distribution');
const duplicateHandling = duplicateHandlingType(event);
const granulesInput = event.input.granules;
const cmrFiles = granulesToCmrFileObjects(granulesInput);
const granulesByGranuleId = keyBy(granulesInput, 'granuleId');
let movedGranules;
if (cmrGranuleUrlType === 'distribution' && !config.distribution_endpoint) {
throw new Error('cmrGranuleUrlType is distribution, but no distribution endpoint is configured.');
}
// allows us to disable moving the files
if (moveStagedFiles) {
// update allGranules with aspirational metadata (where the file should end up after moving.)
const granulesToMove = await updateGranuleMetadata(
granulesByGranuleId, config.collection, cmrFiles, bucketsConfig