Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return sourceFiles.map((file) => {
const fileName = file.name || file.fileName;
const destination = destinations.find((dest) => fileName.match(dest.regex));
// if there's no match, we skip the file
if (!destination) return { source: null, target: null, file };
let source;
if (file.bucket && file.key) {
source = {
Bucket: file.bucket,
Key: file.key
};
} else if (file.filename) {
source = aws.parseS3Uri(file.filename);
} else {
throw new Error(`Unable to determine location of file: ${JSON.stringify(file)}`);
}
const getFileName = (f) => f.fileName || f.name;
const targetKey = destination.filepath
? `${destination.filepath}/${getFileName(file)}`
: getFileName(file);
const target = {
Bucket: destination.bucket,
Key: targetKey
};
return { source, target, file };
async function getMetadataBodyAndTags(xmlFilePath) {
if (!xmlFilePath) {
throw new errors.XmlMetaFileNotFound('XML Metadata file not provided');
}
const { Bucket, Key } = aws.parseS3Uri(xmlFilePath);
const data = await aws.getS3Object(Bucket, Key);
const tags = await aws.s3GetObjectTagging(Bucket, Key);
return {
Body: data.Body.toString(),
TagSet: tags.TagSet
};
}
async function metadataObjectFromCMRJSONFile(cmrFilename) {
const { Bucket, Key } = aws.parseS3Uri(cmrFilename);
const obj = await aws.getS3Object(Bucket, Key, { retries: 5 });
return JSON.parse(obj.Body.toString());
}
function getS3KeyOfFile(file) {
if (file.filename) return aws.parseS3Uri(file.filename).Key;
if (file.filepath) return file.filepath;
if (file.key) return file.key;
throw new Error(`Unable to determine s3 key of file: ${JSON.stringify(file)}`);
}
return moveGranuleFile(source, target).then(() => {
processedFiles.push({
bucket: target.Bucket,
key: target.Key,
name: file.name || file.fileName
});
});
}
let fileBucket;
let fileKey;
if (file.bucket && file.key) {
fileBucket = file.bucket;
fileKey = file.key;
} else if (file.filename) {
const parsed = aws.parseS3Uri(file.filename);
fileBucket = parsed.Bucket;
fileKey = parsed.Key;
} else {
throw new Error(`Unable to determine location of file: ${JSON.stringify(file)}`);
}
processedFiles.push({
bucket: fileBucket,
key: fileKey,
name: file.name || file.fileName
});
return Promise.resolve();
});
await Promise.all(moveFileRequests);
async function getXMLMetadataAsString(xmlFilePath) {
if (!xmlFilePath) {
throw new errors.XmlMetaFileNotFound('XML Metadata file not provided');
}
const { Bucket, Key } = aws.parseS3Uri(xmlFilePath);
const obj = await aws.getS3Object(Bucket, Key, { retries: 5 });
return obj.Body.toString();
}
async function getXMLMetadataAsString(xmlFilePath) {
if (!xmlFilePath) {
throw new errors.XmlMetaFileNotFound('XML Metadata file not provided');
}
const { Bucket, Key } = aws.parseS3Uri(xmlFilePath);
const obj = await aws.getS3Object(Bucket, Key);
return obj.Body.toString();
}