Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function postToCMR(event) {
// get cmr files and metadata
const cmrFiles = granulesToCmrFileObjects(event.input.granules);
log.debug(`Found ${cmrFiles.length} CMR files.`);
const updatedCMRFiles = await addMetadataObjects(cmrFiles);
log.info(`Publishing ${updatedCMRFiles.length} CMR files.`);
// post all meta files to CMR
const results = await Promise.all(
updatedCMRFiles.map(
(cmrFile) =>
publish2CMR(cmrFile, event.config.cmr, event.config.bucket, event.config.stack)
)
);
return {
process: event.config.process,
granules: buildOutput(
results,
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
);
// move files from staging location to final location