@cumulus/cmrjs 20.1.1 → 20.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nycrc.json +4 -4
- package/cmr-utils.d.ts +91 -49
- package/cmr-utils.d.ts.map +1 -1
- package/cmr-utils.js +170 -55
- package/cmr-utils.js.map +1 -1
- package/package.json +11 -10
- package/src/cmr-utils.js +215 -65
- package/tsconfig.tsbuildinfo +1 -1
package/.nycrc.json
CHANGED
package/cmr-utils.d.ts
CHANGED
|
@@ -23,6 +23,9 @@ export type OnlineAccessUrl = {
|
|
|
23
23
|
*/
|
|
24
24
|
Type: string;
|
|
25
25
|
};
|
|
26
|
+
export type CMRConstructorParams = import('@cumulus/cmr-client/CMR').CMRConstructorParams;
|
|
27
|
+
export type DistributionBucketMap = import('@cumulus/distribution-utils/dist/types').DistributionBucketMap;
|
|
28
|
+
export type ApiFile = import('@cumulus/types').ApiFile;
|
|
26
29
|
/**
|
|
27
30
|
* Add ETags to file objects as some downstream functions expect this structure.
|
|
28
31
|
*
|
|
@@ -42,31 +45,22 @@ export function constructCmrConceptLink(conceptId: any, extension: any): string;
|
|
|
42
45
|
/**
|
|
43
46
|
* Construct online access url for a given file and a url type.
|
|
44
47
|
*
|
|
45
|
-
* @param {Object} params - input parameters
|
|
46
48
|
* @param {Object} params.file - file object
|
|
47
49
|
* @param {string} params.distEndpoint - distribution endpoint from config
|
|
48
|
-
* @param {
|
|
50
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket name to bucket type
|
|
49
51
|
* @param {Object} params.urlType - url type, distribution or s3
|
|
50
52
|
* @param {distributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path mapping
|
|
51
53
|
* for all distribution bucketss
|
|
52
54
|
* @param {boolean} [params.useDirectS3Type] - indicate if direct s3 access type is used
|
|
53
55
|
* @returns {(OnlineAccessUrl | undefined)} online access url object, undefined if no URL exists
|
|
54
56
|
*/
|
|
55
|
-
export function constructOnlineAccessUrl({ file, distEndpoint, bucketTypes, urlType, distributionBucketMap, useDirectS3Type, }:
|
|
56
|
-
file: Object;
|
|
57
|
-
distEndpoint: string;
|
|
58
|
-
bucketTypes: Object;
|
|
59
|
-
urlType: Object;
|
|
60
|
-
distributionBucketMap: any;
|
|
61
|
-
useDirectS3Type?: boolean | undefined;
|
|
62
|
-
}): (OnlineAccessUrl | undefined);
|
|
57
|
+
export function constructOnlineAccessUrl({ file, distEndpoint, bucketTypes, urlType, distributionBucketMap, useDirectS3Type, }: Object): (OnlineAccessUrl | undefined);
|
|
63
58
|
/**
|
|
64
59
|
* Construct a list of online access urls grouped by link type.
|
|
65
60
|
*
|
|
66
|
-
* @param {Object} params - input parameters
|
|
67
61
|
* @param {Array<Object>} params.files - array of file objects
|
|
68
62
|
* @param {string} params.distEndpoint - distribution endpoint from config
|
|
69
|
-
* @param {
|
|
63
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket name to bucket type
|
|
70
64
|
* @param {string} params.cmrGranuleUrlType - cmrGranuleUrlType from config
|
|
71
65
|
* @param {distributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path mapping
|
|
72
66
|
* for all distribution bucketss
|
|
@@ -74,14 +68,7 @@ export function constructOnlineAccessUrl({ file, distEndpoint, bucketTypes, urlT
|
|
|
74
68
|
* @returns {Promise<[{URL: string, URLDescription: string}]>} an array of
|
|
75
69
|
* online access url objects grouped by link type.
|
|
76
70
|
*/
|
|
77
|
-
export function constructOnlineAccessUrls({ files, distEndpoint, bucketTypes, cmrGranuleUrlType, distributionBucketMap, useDirectS3Type, }: {
|
|
78
|
-
files: Array<Object>;
|
|
79
|
-
distEndpoint: string;
|
|
80
|
-
bucketTypes: Object;
|
|
81
|
-
cmrGranuleUrlType: string;
|
|
82
|
-
distributionBucketMap: any;
|
|
83
|
-
useDirectS3Type: boolean;
|
|
84
|
-
}): Promise<[{
|
|
71
|
+
export function constructOnlineAccessUrls({ files, distEndpoint, bucketTypes, cmrGranuleUrlType, distributionBucketMap, useDirectS3Type, }: Array<Object>): Promise<[{
|
|
85
72
|
URL: string;
|
|
86
73
|
URLDescription: string;
|
|
87
74
|
}]>;
|
|
@@ -123,30 +110,35 @@ export function granuleToCmrFileObject({ granuleId, files }: {
|
|
|
123
110
|
* Helper to build an CMR settings object, used to initialize CMR.
|
|
124
111
|
*
|
|
125
112
|
* @param {Object} cmrConfig - CMR configuration object
|
|
126
|
-
* @param {string}
|
|
127
|
-
* @param {string}
|
|
128
|
-
* @param {string}
|
|
129
|
-
* @param {string}
|
|
130
|
-
* @param {string}
|
|
131
|
-
* @param {string}
|
|
132
|
-
* @param {string}
|
|
133
|
-
* @param {string}
|
|
134
|
-
* @returns {Promise<
|
|
135
|
-
* object to
|
|
136
|
-
* create CMR instance - contains the
|
|
113
|
+
* @param {string} cmrConfig.oauthProvider - Oauth provider: launchpad or earthdata
|
|
114
|
+
* @param {string} cmrConfig.provider - the CMR provider
|
|
115
|
+
* @param {string} cmrConfig.clientId - Client id for CMR requests
|
|
116
|
+
* @param {string} cmrConfig.passphraseSecretName - Launchpad passphrase secret name
|
|
117
|
+
* @param {string} cmrConfig.api - Launchpad api
|
|
118
|
+
* @param {string} cmrConfig.certificate - Launchpad certificate
|
|
119
|
+
* @param {string} cmrConfig.username - EDL username
|
|
120
|
+
* @param {string} cmrConfig.passwordSecretName - CMR password secret name
|
|
121
|
+
* @returns {Promise<CMRConstructorParams>} object to create CMR instance - contains the
|
|
137
122
|
* provider, clientId, and either launchpad token or EDL username and
|
|
138
123
|
* password
|
|
139
124
|
*/
|
|
140
125
|
export function getCmrSettings(cmrConfig?: {
|
|
141
|
-
oauthProvider
|
|
142
|
-
provider
|
|
143
|
-
clientId
|
|
144
|
-
passphraseSecretName
|
|
145
|
-
api
|
|
146
|
-
certificate
|
|
147
|
-
username
|
|
148
|
-
passwordSecretName
|
|
149
|
-
}): Promise<
|
|
126
|
+
oauthProvider: string;
|
|
127
|
+
provider: string;
|
|
128
|
+
clientId: string;
|
|
129
|
+
passphraseSecretName: string;
|
|
130
|
+
api: string;
|
|
131
|
+
certificate: string;
|
|
132
|
+
username: string;
|
|
133
|
+
passwordSecretName: string;
|
|
134
|
+
}): Promise<CMRConstructorParams>;
|
|
135
|
+
/**
|
|
136
|
+
* Get collectionId from cmr metadata
|
|
137
|
+
* @param {object} cmrObject - cmr metadata object
|
|
138
|
+
* @param {string} cmrFileName - used to know how to parse this object
|
|
139
|
+
* @returns {string}
|
|
140
|
+
*/
|
|
141
|
+
export function getCMRCollectionId(cmrObject: object, cmrFileName: string): string;
|
|
150
142
|
export function getFileDescription(file: any, urlType?: string): string;
|
|
151
143
|
export function getFilename(file: any): any;
|
|
152
144
|
/**
|
|
@@ -254,7 +246,7 @@ export function publish2CMR(cmrPublishObject: {
|
|
|
254
246
|
username: string;
|
|
255
247
|
password: string;
|
|
256
248
|
token: string;
|
|
257
|
-
}, cmrRevisionId: string):
|
|
249
|
+
}, cmrRevisionId: string): Object;
|
|
258
250
|
/**
|
|
259
251
|
* Update CMR Metadata record with the information contained in updatedFiles
|
|
260
252
|
* @param {Object} params - parameter object
|
|
@@ -264,7 +256,7 @@ export function publish2CMR(cmrPublishObject: {
|
|
|
264
256
|
* @param {string} params.distEndpoint - distribution endpoint URL
|
|
265
257
|
* @param {boolean} params.published - boolean true if the data should be published to
|
|
266
258
|
* the CMR service.
|
|
267
|
-
* @param {
|
|
259
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
268
260
|
* @param {string} params.cmrGranuleUrlType - type of granule CMR url
|
|
269
261
|
* @param {distributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path mapping
|
|
270
262
|
* for all distribution buckets
|
|
@@ -274,7 +266,9 @@ export function reconcileCMRMetadata({ granuleId, updatedFiles, distEndpoint, pu
|
|
|
274
266
|
updatedFiles: Object;
|
|
275
267
|
distEndpoint: string;
|
|
276
268
|
published: boolean;
|
|
277
|
-
bucketTypes:
|
|
269
|
+
bucketTypes: {
|
|
270
|
+
[key: string]: string;
|
|
271
|
+
};
|
|
278
272
|
cmrGranuleUrlType: string;
|
|
279
273
|
distributionBucketMap: any;
|
|
280
274
|
}): Promise<void | Object>;
|
|
@@ -298,12 +292,12 @@ export function removeFromCMR(granuleUR: string, creds: CmrCredentials): Promise
|
|
|
298
292
|
* @param {Object} params - parameter object
|
|
299
293
|
* @param {string} params.granuleId - granuleId
|
|
300
294
|
* @param {Object} params.cmrFile - cmr xml file to be updated
|
|
301
|
-
* @param {Array<
|
|
295
|
+
* @param {Array<ApiFile>} params.files - array of file objects
|
|
302
296
|
* @param {string} params.distEndpoint - distribution enpoint from config
|
|
303
297
|
* @param {boolean} params.published - indicate if publish is needed
|
|
304
|
-
* @param {
|
|
298
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
305
299
|
* @param {string} params.cmrGranuleUrlType - type of granule CMR url
|
|
306
|
-
* @param {
|
|
300
|
+
* @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path
|
|
307
301
|
* mapping for all distribution buckets
|
|
308
302
|
* @returns {Promise<Object>} CMR file object with the `etag` of the newly
|
|
309
303
|
* updated metadata file
|
|
@@ -311,13 +305,61 @@ export function removeFromCMR(granuleUR: string, creds: CmrCredentials): Promise
|
|
|
311
305
|
export function updateCMRMetadata({ granuleId, cmrFile, files, distEndpoint, published, bucketTypes, cmrGranuleUrlType, distributionBucketMap, }: {
|
|
312
306
|
granuleId: string;
|
|
313
307
|
cmrFile: Object;
|
|
314
|
-
files: Array<
|
|
308
|
+
files: Array<ApiFile>;
|
|
315
309
|
distEndpoint: string;
|
|
316
310
|
published: boolean;
|
|
317
|
-
bucketTypes:
|
|
311
|
+
bucketTypes: {
|
|
312
|
+
[key: string]: string;
|
|
313
|
+
};
|
|
318
314
|
cmrGranuleUrlType: string;
|
|
319
|
-
distributionBucketMap:
|
|
315
|
+
distributionBucketMap: DistributionBucketMap;
|
|
320
316
|
}): Promise<Object>;
|
|
317
|
+
/**
|
|
318
|
+
* Update the Echo10 cmr metadata object to have corrected urls
|
|
319
|
+
*
|
|
320
|
+
* @param {Object} params.metadataObject - xml cmr metadata object
|
|
321
|
+
* @param {Array<Object>} params.files - files with which to update the cmr metadata
|
|
322
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
323
|
+
* @param {string} params.cmrGranuleUrlType
|
|
324
|
+
* @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path
|
|
325
|
+
* mapping for all distribution buckets
|
|
326
|
+
* @returns {Object}
|
|
327
|
+
*/
|
|
328
|
+
export function updateEcho10XMLMetadataObject({ metadataObject, files, distEndpoint, bucketTypes, cmrGranuleUrlType, distributionBucketMap, }: Object): Object;
|
|
329
|
+
/**
|
|
330
|
+
* Update the UMMG cmr metadata object to have corrected urls
|
|
331
|
+
*
|
|
332
|
+
* @param {Object} params.metadataObject - ummg cmr metadata object
|
|
333
|
+
* @param {Array<ApiFile>} params.files - files with which to update the cmr metadata
|
|
334
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
335
|
+
* @param {string} params.cmrGranuleUrlType
|
|
336
|
+
* @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path
|
|
337
|
+
* mapping for all distribution buckets
|
|
338
|
+
* @returns {Object}
|
|
339
|
+
*/
|
|
340
|
+
export function updateUMMGMetadataObject({ metadataObject, files, distEndpoint, bucketTypes, cmrGranuleUrlType, distributionBucketMap, }: Object): Object;
|
|
341
|
+
/**
|
|
342
|
+
* Update collection in an ECHO10 cmr metadata object
|
|
343
|
+
*
|
|
344
|
+
* @param {object} cmrObject - CMR metadata object
|
|
345
|
+
* @param {{ name: string, version: string }} collection - collection name and version to update to
|
|
346
|
+
* @returns {object}
|
|
347
|
+
*/
|
|
348
|
+
export function setECHO10Collection(cmrObject: object, collection: {
|
|
349
|
+
name: string;
|
|
350
|
+
version: string;
|
|
351
|
+
}): object;
|
|
352
|
+
/**
|
|
353
|
+
* Update collection in an UMMG cmr metadata object
|
|
354
|
+
*
|
|
355
|
+
* @param {object} cmrObject - CMR metadata object
|
|
356
|
+
* @param {{ name: string, version: string }} collection - collection name and version to update to
|
|
357
|
+
* @returns {object}
|
|
358
|
+
*/
|
|
359
|
+
export function setUMMGCollection(cmrObject: object, collection: {
|
|
360
|
+
name: string;
|
|
361
|
+
version: string;
|
|
362
|
+
}): object;
|
|
321
363
|
/**
|
|
322
364
|
* Updates CMR xml file with 'xml' string
|
|
323
365
|
*
|
package/cmr-utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cmr-utils.d.ts","sourceRoot":"","sources":["src/cmr-utils.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cmr-utils.d.ts","sourceRoot":"","sources":["src/cmr-utils.js"],"names":[],"mappings":"6BAkDa;IACZ,QAAY,EAAE,MAAM,CAAC;IACrB,QAAY,EAAE,MAAM,CAAC;IACrB,QAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAS,CAAC,EAAE,MAAM,CAAA;CACf;;;;;SA2aU,MAAM;;;;oBACN,MAAM;;;;iBACN,MAAM;;;;UACN,MAAM;;mCA9bP,OAAO,yBAAyB,EAAE,oBAAoB;oCACtD,OAAO,wCAAwC,EAAE,qBAAqB;sBACtE,OAAO,gBAAgB,EAAE,OAAO;AAuW7C;;;;;;GAMG;AACH,+CAJW,MAAM,SACN,MAAM,GACJ,MAAM,CASlB;AA7TD,gFAA+G;AA+X/G;;;;;;GAMG;AAEH;;;;;;;;;;;GAWG;AACH,gIATW,MAAM,GAOJ,CAAC,eAAe,GAAG,SAAS,CAAC,CAyBzC;AAED;;;;;;;;;;;;GAYG;AACH,4IAVW,MAAM,MAAM,CAAC,GAOX,QAAQ,CAAC;IAAC,KAAK,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAC,CAAC,CAAC,CA0C5D;AA6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N,MAAM,gBAehB"}
|
package/cmr-utils.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
//@ts-check
|
|
2
3
|
const got = require('got');
|
|
3
4
|
const get = require('lodash/get');
|
|
4
5
|
const pick = require('lodash/pick');
|
|
5
6
|
const set = require('lodash/set');
|
|
7
|
+
const cloneDeep = require('lodash/cloneDeep');
|
|
6
8
|
const { promisify } = require('util');
|
|
7
9
|
const js2xmlParser = require('js2xmlparser');
|
|
8
10
|
const path = require('path');
|
|
@@ -18,8 +20,17 @@ const errors = require('@cumulus/errors');
|
|
|
18
20
|
const { CMR, getSearchUrl, ummVersion } = require('@cumulus/cmr-client');
|
|
19
21
|
const { constructDistributionUrl } = require('@cumulus/distribution-utils');
|
|
20
22
|
const { getBucketAccessUrl } = require('@cumulus/cmr-client/getUrl');
|
|
23
|
+
const { constructCollectionId } = require('@cumulus/message/Collections');
|
|
21
24
|
const { xmlParseOptions, ummVersionToMetadataFormat, } = require('./utils');
|
|
25
|
+
/* eslint-disable max-len */
|
|
26
|
+
/**
|
|
27
|
+
* @typedef {import('@cumulus/cmr-client/CMR').CMRConstructorParams} CMRConstructorParams
|
|
28
|
+
* @typedef {import('@cumulus/distribution-utils/dist/types').DistributionBucketMap} DistributionBucketMap
|
|
29
|
+
* @typedef {import('@cumulus/types').ApiFile} ApiFile
|
|
30
|
+
*/
|
|
31
|
+
/* eslint-enable max-len */
|
|
22
32
|
const log = new Logger({ sender: '@cumulus/cmrjs/src/cmr-utils' });
|
|
33
|
+
const s3CredsEndpoint = 's3credentials';
|
|
23
34
|
/**
|
|
24
35
|
* @typedef {{
|
|
25
36
|
* provider: string,
|
|
@@ -208,15 +219,15 @@ async function publishUMMGJSON2CMR(cmrFile, cmrClient, revisionId) {
|
|
|
208
219
|
* @param {string} cmrRevisionId - Optional CMR Revision ID
|
|
209
220
|
* if not provided, CMR username and password are used to get a cmr token
|
|
210
221
|
*/
|
|
211
|
-
|
|
222
|
+
function publish2CMR(cmrPublishObject, creds, cmrRevisionId) {
|
|
212
223
|
const cmrClient = new CMR(creds);
|
|
213
224
|
const cmrFileName = getFilename(cmrPublishObject);
|
|
214
225
|
// choose xml or json and do the things.
|
|
215
226
|
if (isECHO10Filename(cmrFileName)) {
|
|
216
|
-
return
|
|
227
|
+
return publishECHO10XML2CMR(cmrPublishObject, cmrClient, cmrRevisionId);
|
|
217
228
|
}
|
|
218
229
|
if (isUMMGFilename(cmrFileName)) {
|
|
219
|
-
return
|
|
230
|
+
return publishUMMGJSON2CMR(cmrPublishObject, cmrClient, cmrRevisionId);
|
|
220
231
|
}
|
|
221
232
|
throw new Error(`invalid cmrPublishObject passed to publis2CMR ${JSON.stringify(cmrPublishObject)}`);
|
|
222
233
|
}
|
|
@@ -431,10 +442,9 @@ function generateFileUrl({ file, distEndpoint, urlType = 'distribution', distrib
|
|
|
431
442
|
/**
|
|
432
443
|
* Construct online access url for a given file and a url type.
|
|
433
444
|
*
|
|
434
|
-
* @param {Object} params - input parameters
|
|
435
445
|
* @param {Object} params.file - file object
|
|
436
446
|
* @param {string} params.distEndpoint - distribution endpoint from config
|
|
437
|
-
* @param {
|
|
447
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket name to bucket type
|
|
438
448
|
* @param {Object} params.urlType - url type, distribution or s3
|
|
439
449
|
* @param {distributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path mapping
|
|
440
450
|
* for all distribution bucketss
|
|
@@ -461,10 +471,9 @@ function constructOnlineAccessUrl({ file, distEndpoint, bucketTypes, urlType = '
|
|
|
461
471
|
/**
|
|
462
472
|
* Construct a list of online access urls grouped by link type.
|
|
463
473
|
*
|
|
464
|
-
* @param {Object} params - input parameters
|
|
465
474
|
* @param {Array<Object>} params.files - array of file objects
|
|
466
475
|
* @param {string} params.distEndpoint - distribution endpoint from config
|
|
467
|
-
* @param {
|
|
476
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket name to bucket type
|
|
468
477
|
* @param {string} params.cmrGranuleUrlType - cmrGranuleUrlType from config
|
|
469
478
|
* @param {distributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path mapping
|
|
470
479
|
* for all distribution bucketss
|
|
@@ -510,16 +519,15 @@ function constructOnlineAccessUrls({ files, distEndpoint, bucketTypes, cmrGranul
|
|
|
510
519
|
* @param {Object} params - input parameters
|
|
511
520
|
* @param {Array<Object>} params.files - array of file objects
|
|
512
521
|
* @param {string} params.distEndpoint - distribution endpoint from config
|
|
513
|
-
* @param {
|
|
514
|
-
* @param {string} params.s3CredsEndpoint - Optional endpoint for acquiring temporary s3 creds
|
|
522
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
515
523
|
* @param {string} params.cmrGranuleUrlType - cmrGranuleUrlType from config
|
|
516
|
-
* @param {
|
|
524
|
+
* @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path
|
|
517
525
|
* mapping for all distribution buckets
|
|
518
526
|
* @param {boolean} params.useDirectS3Type - indicate if direct s3 access type is used
|
|
519
527
|
* @returns {Promise<[{URL: string, string, Description: string, Type: string}]>}
|
|
520
528
|
* an array of online access url objects
|
|
521
529
|
*/
|
|
522
|
-
function constructRelatedUrls({ files, distEndpoint, bucketTypes,
|
|
530
|
+
function constructRelatedUrls({ files, distEndpoint, bucketTypes, cmrGranuleUrlType = 'both', distributionBucketMap, useDirectS3Type = false, }) {
|
|
523
531
|
const credsUrl = urljoin(distEndpoint, s3CredsEndpoint);
|
|
524
532
|
const s3CredentialsObject = getS3CredentialsObject(credsUrl);
|
|
525
533
|
const cmrUrlObjects = constructOnlineAccessUrls({
|
|
@@ -536,7 +544,7 @@ function constructRelatedUrls({ files, distEndpoint, bucketTypes, s3CredsEndpoin
|
|
|
536
544
|
/**
|
|
537
545
|
* Create a list of URL objects that should not appear under onlineAccess in the CMR metadata.
|
|
538
546
|
* @param {Array<Object>} files - array of updated file objects
|
|
539
|
-
* @param {
|
|
547
|
+
* @param {{ [key: string]: string }} bucketTypes - map of buckets name to bucket types
|
|
540
548
|
* @returns {Array<Object>} array of files to be omitted in cmr's OnlineAccessURLs
|
|
541
549
|
*/
|
|
542
550
|
function onlineAccessURLsToRemove(files, bucketTypes) {
|
|
@@ -627,6 +635,34 @@ function shouldUseDirectS3Type(metadataObject) {
|
|
|
627
635
|
}
|
|
628
636
|
return false;
|
|
629
637
|
}
|
|
638
|
+
/**
|
|
639
|
+
* Update the UMMG cmr metadata object to have corrected urls
|
|
640
|
+
*
|
|
641
|
+
* @param {Object} params.metadataObject - ummg cmr metadata object
|
|
642
|
+
* @param {Array<ApiFile>} params.files - files with which to update the cmr metadata
|
|
643
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
644
|
+
* @param {string} params.cmrGranuleUrlType
|
|
645
|
+
* @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path
|
|
646
|
+
* mapping for all distribution buckets
|
|
647
|
+
* @returns {Object}
|
|
648
|
+
*/
|
|
649
|
+
function updateUMMGMetadataObject({ metadataObject, files, distEndpoint, bucketTypes, cmrGranuleUrlType = 'both', distributionBucketMap, }) {
|
|
650
|
+
const updatedMetadataObject = cloneDeep(metadataObject);
|
|
651
|
+
const useDirectS3Type = shouldUseDirectS3Type(updatedMetadataObject);
|
|
652
|
+
const newURLs = constructRelatedUrls({
|
|
653
|
+
files,
|
|
654
|
+
distEndpoint,
|
|
655
|
+
bucketTypes,
|
|
656
|
+
cmrGranuleUrlType,
|
|
657
|
+
distributionBucketMap,
|
|
658
|
+
useDirectS3Type,
|
|
659
|
+
});
|
|
660
|
+
const removedURLs = onlineAccessURLsToRemove(files, bucketTypes);
|
|
661
|
+
const originalURLs = get(updatedMetadataObject, 'RelatedUrls', []);
|
|
662
|
+
const mergedURLs = mergeURLs(originalURLs, newURLs, removedURLs);
|
|
663
|
+
set(updatedMetadataObject, 'RelatedUrls', mergedURLs);
|
|
664
|
+
return updatedMetadataObject;
|
|
665
|
+
}
|
|
630
666
|
/**
|
|
631
667
|
* After files are moved, create new online access URLs and then update the S3
|
|
632
668
|
* UMMG cmr.json file with this information.
|
|
@@ -635,9 +671,9 @@ function shouldUseDirectS3Type(metadataObject) {
|
|
|
635
671
|
* @param {Object} params.cmrFile - cmr.json file whose contents will be updated.
|
|
636
672
|
* @param {Array<Object>} params.files - array of moved file objects.
|
|
637
673
|
* @param {string} params.distEndpoint - distribution endpoint form config.
|
|
638
|
-
* @param {
|
|
674
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
639
675
|
* @param {string} params.cmrGranuleUrlType - cmrGranuleUrlType from config
|
|
640
|
-
* @param {
|
|
676
|
+
* @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path
|
|
641
677
|
* mapping for all distribution buckets
|
|
642
678
|
* @returns {Promise<{ metadataObject: Object, etag: string}>} an object
|
|
643
679
|
* containing a `metadataObject` (the updated UMMG metadata object) and the
|
|
@@ -646,37 +682,30 @@ function shouldUseDirectS3Type(metadataObject) {
|
|
|
646
682
|
async function updateUMMGMetadata({ cmrFile, files, distEndpoint, bucketTypes, cmrGranuleUrlType = 'both', distributionBucketMap, }) {
|
|
647
683
|
const filename = getS3UrlOfFile(cmrFile);
|
|
648
684
|
const metadataObject = await metadataObjectFromCMRJSONFile(filename);
|
|
649
|
-
const
|
|
650
|
-
|
|
685
|
+
const updatedMetadataObject = updateUMMGMetadataObject({
|
|
686
|
+
metadataObject,
|
|
651
687
|
files,
|
|
652
688
|
distEndpoint,
|
|
653
689
|
bucketTypes,
|
|
654
690
|
cmrGranuleUrlType,
|
|
655
691
|
distributionBucketMap,
|
|
656
|
-
useDirectS3Type,
|
|
657
692
|
});
|
|
658
|
-
const
|
|
659
|
-
|
|
660
|
-
const mergedURLs = mergeURLs(originalURLs, newURLs, removedURLs);
|
|
661
|
-
set(metadataObject, 'RelatedUrls', mergedURLs);
|
|
662
|
-
const { ETag: etag } = await uploadUMMGJSONCMRFile(metadataObject, cmrFile);
|
|
663
|
-
return { metadataObject, etag };
|
|
693
|
+
const { ETag: etag } = await uploadUMMGJSONCMRFile(updatedMetadataObject, cmrFile);
|
|
694
|
+
return { metadataObject: updatedMetadataObject, etag };
|
|
664
695
|
}
|
|
665
696
|
/**
|
|
666
697
|
* Helper to build an CMR settings object, used to initialize CMR.
|
|
667
698
|
*
|
|
668
699
|
* @param {Object} cmrConfig - CMR configuration object
|
|
669
|
-
* @param {string}
|
|
670
|
-
* @param {string}
|
|
671
|
-
* @param {string}
|
|
672
|
-
* @param {string}
|
|
673
|
-
* @param {string}
|
|
674
|
-
* @param {string}
|
|
675
|
-
* @param {string}
|
|
676
|
-
* @param {string}
|
|
677
|
-
* @returns {Promise<
|
|
678
|
-
* object to
|
|
679
|
-
* create CMR instance - contains the
|
|
700
|
+
* @param {string} cmrConfig.oauthProvider - Oauth provider: launchpad or earthdata
|
|
701
|
+
* @param {string} cmrConfig.provider - the CMR provider
|
|
702
|
+
* @param {string} cmrConfig.clientId - Client id for CMR requests
|
|
703
|
+
* @param {string} cmrConfig.passphraseSecretName - Launchpad passphrase secret name
|
|
704
|
+
* @param {string} cmrConfig.api - Launchpad api
|
|
705
|
+
* @param {string} cmrConfig.certificate - Launchpad certificate
|
|
706
|
+
* @param {string} cmrConfig.username - EDL username
|
|
707
|
+
* @param {string} cmrConfig.passwordSecretName - CMR password secret name
|
|
708
|
+
* @returns {Promise<CMRConstructorParams>} object to create CMR instance - contains the
|
|
680
709
|
* provider, clientId, and either launchpad token or EDL username and
|
|
681
710
|
* password
|
|
682
711
|
*/
|
|
@@ -762,23 +791,17 @@ function buildMergedEchoURLObject(URLlist = [], originalURLlist = [], removedURL
|
|
|
762
791
|
return mergeURLs(originalURLlist, filteredURLObjectList, removedURLs);
|
|
763
792
|
}
|
|
764
793
|
/**
|
|
765
|
-
*
|
|
766
|
-
* the S3 ECHO10 CMR XML file with this information.
|
|
794
|
+
* Update the Echo10 cmr metadata object to have corrected urls
|
|
767
795
|
*
|
|
768
|
-
* @param {Object} params -
|
|
769
|
-
* @param {Object} params.
|
|
770
|
-
* @param {
|
|
771
|
-
* @param {string} params.
|
|
772
|
-
* @param {
|
|
773
|
-
* @param {Object} params.distributionBucketMap - Object with bucket:tea-path
|
|
796
|
+
* @param {Object} params.metadataObject - xml cmr metadata object
|
|
797
|
+
* @param {Array<Object>} params.files - files with which to update the cmr metadata
|
|
798
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
799
|
+
* @param {string} params.cmrGranuleUrlType
|
|
800
|
+
* @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path
|
|
774
801
|
* mapping for all distribution buckets
|
|
775
|
-
* @returns {
|
|
776
|
-
* containing a `metadataObject` and the `etag` of the uploaded CMR file
|
|
802
|
+
* @returns {Object}
|
|
777
803
|
*/
|
|
778
|
-
|
|
779
|
-
// add/replace the OnlineAccessUrls
|
|
780
|
-
const filename = getS3UrlOfFile(cmrFile);
|
|
781
|
-
const metadataObject = await metadataObjectFromCMRXMLFile(filename);
|
|
804
|
+
function updateEcho10XMLMetadataObject({ metadataObject, files, distEndpoint, bucketTypes, cmrGranuleUrlType = 'both', distributionBucketMap, }) {
|
|
782
805
|
const metadataGranule = metadataObject.Granule;
|
|
783
806
|
const updatedGranule = { ...metadataGranule };
|
|
784
807
|
const originalOnlineAccessURLs = [].concat(get(metadataGranule, 'OnlineAccessURLs.OnlineAccessURL', []));
|
|
@@ -800,10 +823,40 @@ async function updateEcho10XMLMetadata({ cmrFile, files, distEndpoint, bucketTyp
|
|
|
800
823
|
set(updatedGranule, 'OnlineAccessURLs.OnlineAccessURL', mergedOnlineAccessURLs);
|
|
801
824
|
set(updatedGranule, 'OnlineResources.OnlineResource', mergedOnlineResources);
|
|
802
825
|
set(updatedGranule, 'AssociatedBrowseImageUrls.ProviderBrowseUrl', mergedAssociatedBrowse);
|
|
803
|
-
|
|
804
|
-
|
|
826
|
+
return {
|
|
827
|
+
...metadataObject,
|
|
828
|
+
Granule: updatedGranule,
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* After files are moved, creates new online access URLs and then updates
|
|
833
|
+
* the S3 ECHO10 CMR XML file with this information.
|
|
834
|
+
*
|
|
835
|
+
* @param {Object} params - parameter object
|
|
836
|
+
* @param {Object} params.cmrFile - cmr xml file object to be updated
|
|
837
|
+
* @param {Array<Object>} params.files - array of file objects
|
|
838
|
+
* @param {string} params.distEndpoint - distribution endpoint from config
|
|
839
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
840
|
+
* @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path
|
|
841
|
+
* mapping for all distribution buckets
|
|
842
|
+
* @returns {Promise<{ metadataObject: Object, etag: string}>} an object
|
|
843
|
+
* containing a `metadataObject` and the `etag` of the uploaded CMR file
|
|
844
|
+
*/
|
|
845
|
+
async function updateEcho10XMLMetadata({ cmrFile, files, distEndpoint, bucketTypes, cmrGranuleUrlType = 'both', distributionBucketMap, }) {
|
|
846
|
+
// add/replace the OnlineAccessUrls
|
|
847
|
+
const filename = getS3UrlOfFile(cmrFile);
|
|
848
|
+
const metadataObject = await metadataObjectFromCMRXMLFile(filename);
|
|
849
|
+
const updatedMetadataObject = updateEcho10XMLMetadataObject({
|
|
850
|
+
metadataObject,
|
|
851
|
+
files,
|
|
852
|
+
distEndpoint,
|
|
853
|
+
bucketTypes,
|
|
854
|
+
cmrGranuleUrlType,
|
|
855
|
+
distributionBucketMap,
|
|
856
|
+
});
|
|
857
|
+
const xml = generateEcho10XMLString(updatedMetadataObject.Granule);
|
|
805
858
|
const { ETag: etag } = await uploadEcho10CMRFile(xml, cmrFile);
|
|
806
|
-
return { metadataObject, etag };
|
|
859
|
+
return { metadataObject: updatedMetadataObject, etag };
|
|
807
860
|
}
|
|
808
861
|
/**
|
|
809
862
|
* Modifies cmr metadata file with file's URLs updated to their new locations.
|
|
@@ -811,12 +864,12 @@ async function updateEcho10XMLMetadata({ cmrFile, files, distEndpoint, bucketTyp
|
|
|
811
864
|
* @param {Object} params - parameter object
|
|
812
865
|
* @param {string} params.granuleId - granuleId
|
|
813
866
|
* @param {Object} params.cmrFile - cmr xml file to be updated
|
|
814
|
-
* @param {Array<
|
|
867
|
+
* @param {Array<ApiFile>} params.files - array of file objects
|
|
815
868
|
* @param {string} params.distEndpoint - distribution enpoint from config
|
|
816
869
|
* @param {boolean} params.published - indicate if publish is needed
|
|
817
|
-
* @param {
|
|
870
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
818
871
|
* @param {string} params.cmrGranuleUrlType - type of granule CMR url
|
|
819
|
-
* @param {
|
|
872
|
+
* @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path
|
|
820
873
|
* mapping for all distribution buckets
|
|
821
874
|
* @returns {Promise<Object>} CMR file object with the `etag` of the newly
|
|
822
875
|
* updated metadata file
|
|
@@ -864,7 +917,7 @@ async function updateCMRMetadata({ granuleId, cmrFile, files, distEndpoint, publ
|
|
|
864
917
|
* @param {string} params.distEndpoint - distribution endpoint URL
|
|
865
918
|
* @param {boolean} params.published - boolean true if the data should be published to
|
|
866
919
|
* the CMR service.
|
|
867
|
-
* @param {
|
|
920
|
+
* @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types
|
|
868
921
|
* @param {string} params.cmrGranuleUrlType - type of granule CMR url
|
|
869
922
|
* @param {distributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path mapping
|
|
870
923
|
* for all distribution buckets
|
|
@@ -1032,6 +1085,63 @@ async function getGranuleTemporalInfo(granule) {
|
|
|
1032
1085
|
}
|
|
1033
1086
|
return {};
|
|
1034
1087
|
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Update collection in an ECHO10 cmr metadata object
|
|
1090
|
+
*
|
|
1091
|
+
* @param {object} cmrObject - CMR metadata object
|
|
1092
|
+
* @param {{ name: string, version: string }} collection - collection name and version to update to
|
|
1093
|
+
* @returns {object}
|
|
1094
|
+
*/
|
|
1095
|
+
const setECHO10Collection = (cmrObject, collection) => {
|
|
1096
|
+
const cmrObjectCopy = cloneDeep(cmrObject);
|
|
1097
|
+
if (!cmrObjectCopy.Granule) {
|
|
1098
|
+
throw new errors.ValidationError(`invalid ECHO10 cmr metadata ${JSON.stringify(cmrObjectCopy)}, must have granule tag`);
|
|
1099
|
+
}
|
|
1100
|
+
cmrObjectCopy.Granule.Collection = {
|
|
1101
|
+
ShortName: collection.name,
|
|
1102
|
+
VersionId: collection.version,
|
|
1103
|
+
};
|
|
1104
|
+
return cmrObjectCopy;
|
|
1105
|
+
};
|
|
1106
|
+
/**
|
|
1107
|
+
* Update collection in an UMMG cmr metadata object
|
|
1108
|
+
*
|
|
1109
|
+
* @param {object} cmrObject - CMR metadata object
|
|
1110
|
+
* @param {{ name: string, version: string }} collection - collection name and version to update to
|
|
1111
|
+
* @returns {object}
|
|
1112
|
+
*/
|
|
1113
|
+
const setUMMGCollection = (cmrObject, collection) => {
|
|
1114
|
+
const cmrObjectCopy = cloneDeep(cmrObject);
|
|
1115
|
+
set(cmrObjectCopy, 'CollectionReference', {
|
|
1116
|
+
ShortName: collection.name,
|
|
1117
|
+
Version: collection.version,
|
|
1118
|
+
});
|
|
1119
|
+
return cmrObjectCopy;
|
|
1120
|
+
};
|
|
1121
|
+
/**
|
|
1122
|
+
* Get collectionId from cmr metadata
|
|
1123
|
+
* @param {object} cmrObject - cmr metadata object
|
|
1124
|
+
* @param {string} cmrFileName - used to know how to parse this object
|
|
1125
|
+
* @returns {string}
|
|
1126
|
+
*/
|
|
1127
|
+
const getCMRCollectionId = (cmrObject, cmrFileName) => {
|
|
1128
|
+
if (isUMMGFilename(cmrFileName)) {
|
|
1129
|
+
const collectionName = cmrObject.CollectionReference?.ShortName;
|
|
1130
|
+
const collectionVersion = cmrObject.CollectionReference?.Version;
|
|
1131
|
+
if (!(collectionName && collectionVersion)) {
|
|
1132
|
+
throw new errors.ValidationError('UMMG metadata file has invalid collection configuration' +
|
|
1133
|
+
` ${JSON.stringify(cmrObject.CollectionReference)}`);
|
|
1134
|
+
}
|
|
1135
|
+
return constructCollectionId(collectionName, collectionVersion);
|
|
1136
|
+
}
|
|
1137
|
+
const collectionName = cmrObject.Granule?.Collection?.ShortName;
|
|
1138
|
+
const collectionVersion = cmrObject.Granule?.Collection?.VersionId;
|
|
1139
|
+
if (!(collectionName && collectionVersion)) {
|
|
1140
|
+
throw new errors.ValidationError('ECHO10 metadata file has invalid collection configuration' +
|
|
1141
|
+
` ${JSON.stringify(cmrObject.Granule?.Collection)}`);
|
|
1142
|
+
}
|
|
1143
|
+
return constructCollectionId(collectionName, collectionVersion);
|
|
1144
|
+
};
|
|
1035
1145
|
module.exports = {
|
|
1036
1146
|
addEtagsToFileObjects,
|
|
1037
1147
|
constructCmrConceptLink,
|
|
@@ -1041,6 +1151,7 @@ module.exports = {
|
|
|
1041
1151
|
generateFileUrl,
|
|
1042
1152
|
granuleToCmrFileObject,
|
|
1043
1153
|
getCmrSettings,
|
|
1154
|
+
getCMRCollectionId,
|
|
1044
1155
|
getFileDescription,
|
|
1045
1156
|
getFilename,
|
|
1046
1157
|
getGranuleTemporalInfo,
|
|
@@ -1062,6 +1173,10 @@ module.exports = {
|
|
|
1062
1173
|
removeEtagsFromFileObjects,
|
|
1063
1174
|
removeFromCMR,
|
|
1064
1175
|
updateCMRMetadata,
|
|
1176
|
+
updateEcho10XMLMetadataObject,
|
|
1177
|
+
updateUMMGMetadataObject,
|
|
1178
|
+
setECHO10Collection,
|
|
1179
|
+
setUMMGCollection,
|
|
1065
1180
|
uploadEcho10CMRFile,
|
|
1066
1181
|
uploadUMMGJSONCMRFile,
|
|
1067
1182
|
};
|