How to use the @cumulus/cmrjs.CMR function in @cumulus/cmrjs

To help you get started, we’ve selected a few @cumulus/cmrjs 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 / api / lambdas / create-reconciliation-report.js View on Github external
async function reconciliationReportForCollections() {
  // compare collection holdings:
  //   Get list of collections from CMR
  //   Get list of collections from CUMULUS
  //   Report collections only in CMR
  //   Report collections only in CUMULUS

  // get all collections from CMR and sort them, since CMR query doesn't support
  // 'Version' as sort_key
  const cmr = new CMR(process.env.cmr_provider, process.env.cmr_client_id);
  const cmrCollectionItems = await cmr.searchCollections({}, 'umm_json');
  const cmrCollectionIds = cmrCollectionItems.map((item) =>
    constructCollectionId(item.umm.ShortName, item.umm.Version)).sort();

  // get all collections from database and sort them, since the scan result is not ordered
  const dbCollectionsItems = await new Collection().getAllCollections();
  const dbCollectionIds = dbCollectionsItems.map((item) =>
    constructCollectionId(item.name, item.version)).sort();

  const okCollections = [];
  let collectionsOnlyInCumulus = [];
  let collectionsOnlyInCmr = [];

  let nextDbCollectionId = (dbCollectionIds.length !== 0) ? dbCollectionIds[0] : null;
  let nextCmrCollectionId = (cmrCollectionIds.length !== 0) ? cmrCollectionIds[0] : null;
github nasa / cumulus / tasks / post-to-cmr / index.js View on Github external
async function publish(cmrFile, creds, bucket, stack) {
  let password;
  try {
    password = await DefaultProvider.decrypt(creds.password, undefined, bucket, stack);
  }
  catch (e) {
    log.error('Decrypting password failed, using unencrypted password');
    password = creds.password;
  }
  const cmr = new CMR(
    creds.provider,
    creds.clientId,
    creds.username,
    password
  );

  const xml = await getMetadata(cmrFile.filename);
  const res = await cmr.ingestGranule(xml);
  const conceptId = res.result['concept-id'];

  log.info(`Published ${cmrFile.granuleId} to the CMR. conceptId: ${conceptId}`);

  return {
    granuleId: cmrFile.granuleId,
    filename: cmrFile.filename,
    conceptId,
github nasa / cumulus / packages / api / models / granules.js View on Github external
async removeGranuleFromCmr(granuleId, collectionId) {
    log.info(`granules.removeGranuleFromCmr ${granuleId}`);
    const password = await DefaultProvider.decrypt(process.env.cmr_password);
    const cmr = new CMR(
      process.env.cmr_provider,
      process.env.cmr_client_id,
      process.env.cmr_username,
      password
    );

    await cmr.deleteGranule(granuleId, collectionId);
    await this.update({ granuleId }, { published: false, cmrLink: null });
  }
github nasa / cumulus-dashboard / app / src / js / actions / index.js View on Github external
export const getMMTLinkFromCmr = (collection, getState) => {
  const {
    cumulusInstance: { cmrProvider, cmrEnvironment }, mmtLinks
  } = getState();

  if (!cmrProvider || !cmrEnvironment) {
    return Promise.reject('Missing Cumulus Instance Metadata in state.' +
      ' Make sure a call to getCumulusInstanceMetadata is dispatched.');
  }

  if (getCollectionId(collection) in mmtLinks) {
    return Promise.resolve(mmtLinks[getCollectionId(collection)]);
  }

  return new CMR(cmrProvider).searchCollections(
    {
      short_name: collection.name,
      version: collection.version
    })
    .then(([result]) =>
      result && result.id && buildMMTLink(result.id, cmrEnvironment));
};
github nasa / cumulus / packages / api / endpoints / cmrjs.js View on Github external
async function getCollection(req, res) {
  const cmrProvider = req.params.provider;
  const collectionName = req.params.name;
  const collectionVersion = req.params.version;
  const cmrEnvironment = req.params.env;

  const search = new CMR(cmrProvider);
  const results = await search.searchCollections({short_name: collectionName, version: collectionVersion});

  if (results.length === 1) {
    const conceptId = results[0].id;
    if (conceptId) {
      const link = buildMMTLink(conceptId, cmrEnvironment);
      return res.send(link);
    }
  }
  return res.send(null);
}
github nasa / cumulus / packages / ingest / cmr.js View on Github external
async function publish(cmrFile, creds, bucket, stack) {
  let password;
  try {
    password = await DefaultProvider.decrypt(creds.password, undefined, bucket, stack);
  }
  catch (e) {
    log.error('Decrypting password failed, using unencrypted password');
    password = creds.password;
  }
  const cmr = new CMR(
    creds.provider,
    creds.clientId,
    creds.username,
    password
  );

  const xml = cmrFile.metadata;
  const res = await cmr.ingestGranule(xml);
  const conceptId = res.result['concept-id'];

  log.info(`Published ${cmrFile.granuleId} to the CMR. conceptId: ${conceptId}`);

  return {
    granuleId: cmrFile.granuleId,
    filename: cmrFile.filename,
    conceptId,