How to use the @cumulus/common.aws.parseS3Uri function in @cumulus/common

To help you get started, we’ve selected a few @cumulus/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nasa / cumulus / packages / ingest / granule.js View on Github external
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 };
github nasa / cumulus / packages / cmrjs / granule-extract-cmr.js View on Github external
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
  };
}
github nasa / cumulus / packages / cmrjs / cmr-utils.js View on Github external
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());
}
github nasa / cumulus / packages / cmrjs / cmr-utils.js View on Github external
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)}`);
}
github nasa / cumulus / packages / ingest / granule.js View on Github external
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);
github nasa / cumulus / packages / cmrjs / cmr-utils.js View on Github external
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();
}
github nasa / cumulus / packages / cmrjs / granule-extract-cmr.js View on Github external
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();
}