Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
collection,
provider,
fileStagingDir,
forceDownload,
duplicateHandling
);
return download(ingest, downloadBucket, provider, input.granules)
.then((granules) => {
if (ingest.end) ingest.end();
const output = { granules };
if (collection && collection.process) output.process = collection.process;
if (config.pdr) output.pdr = config.pdr;
log.debug(`SyncGranule Complete. Returning output: ${JSON.stringify(output)}`);
async function discoverGranules(event) {
const protocol = event.config.provider.protocol;
const Discoverer = granule.selector('discover', protocol);
const discoverer = new Discoverer(event);
try {
const granules = await discoverer.discover();
log.info(`Discovered ${granules.length} granules.`);
return { granules };
} finally {
if (discoverer.connected) await discoverer.end();
}
}
module.exports.handler = function handler(_event, context, cb) {
try {
const event = Object.assign({}, _event);
const buckets = get(event, 'resources.buckets');
const collection = get(event, 'collection.meta');
const granules = get(event, 'payload.granules');
const provider = get(event, 'provider');
if (!provider) {
const err = new errors.ProviderNotFound('Provider info not provided');
log.error(err);
return cb(err);
}
const IngestClass = granule.selector('ingest', provider.protocol);
const ingest = new IngestClass(event);
return download(ingest, buckets.internal, provider, granules).then((gs) => {
event.payload.granules = gs;
if (collection.process) {
event.meta.process = collection.process;
}
if (ingest.end) {
ingest.end();
}
return cb(null, event);
}).catch(e => {
if (ingest.end) {