postman-runtime 7.52.0-beta.4 → 7.52.0
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/CHANGELOG.yaml +3 -2
- package/README.md +5 -5
- package/dist/index.js +1 -1
- package/lib/runner/extensions/event.command.js +9 -9
- package/lib/runner/extensions/item.command.js +180 -112
- package/lib/runner/index.js +5 -5
- package/lib/runner/resolve-secrets.js +18 -11
- package/lib/runner/util.js +83 -45
- package/package.json +3 -3
package/lib/runner/util.js
CHANGED
|
@@ -121,6 +121,65 @@ prepareLookupHash = function (items) {
|
|
|
121
121
|
return hash;
|
|
122
122
|
};
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Resolve URL string from an item and payload by substituting all variables (including vault).
|
|
126
|
+
* Returns intermediate products needed by callers that do further resolution.
|
|
127
|
+
*
|
|
128
|
+
* @private
|
|
129
|
+
* @param {Item} item - The request item
|
|
130
|
+
* @param {Object} payload - Payload containing variable scopes
|
|
131
|
+
* @returns {{ urlString: string, variableDefinitions: Array, vaultVariables: * }}
|
|
132
|
+
*/
|
|
133
|
+
function resolveUrl (item, payload) {
|
|
134
|
+
if (!(item && item.request && item.request.url)) {
|
|
135
|
+
return { urlString: '', variableDefinitions: [], vaultVariables: null };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// @todo - resolve variables in a more graceful way
|
|
139
|
+
var variableDefinitions = [
|
|
140
|
+
// extract the variable list from variable scopes
|
|
141
|
+
// @note: this is the order of precedence for variable resolution - don't change it
|
|
142
|
+
_.get(payload, '_variables.values', []),
|
|
143
|
+
_.get(payload, 'data', []),
|
|
144
|
+
_.get(payload, 'environment.values', []),
|
|
145
|
+
_.get(payload, 'collectionVariables.values', []),
|
|
146
|
+
_.get(payload, 'globals.values', [])
|
|
147
|
+
// @note vault variables are added later
|
|
148
|
+
],
|
|
149
|
+
vaultValues = _.get(payload, 'vaultSecrets.values'),
|
|
150
|
+
hasVaultSecrets = vaultValues ? vaultValues.count() > 0 : false,
|
|
151
|
+
urlObj = item.request.url,
|
|
152
|
+
urlString = urlObj.toString(),
|
|
153
|
+
unresolvedUrlString = urlString,
|
|
154
|
+
vaultVariables = null,
|
|
155
|
+
vaultUrl;
|
|
156
|
+
|
|
157
|
+
if (hasVaultSecrets) {
|
|
158
|
+
// get the vault variables that match the unresolved URL string
|
|
159
|
+
vaultUrl = urlObj.protocol ? urlString : 'http://' + urlString; // force protocol
|
|
160
|
+
vaultVariables = payload.vaultSecrets.__getMatchingVariables(vaultUrl);
|
|
161
|
+
|
|
162
|
+
// resolve variables in URL string with initial vault variables
|
|
163
|
+
urlString = sdk.Property.replaceSubstitutions(urlString,
|
|
164
|
+
[...variableDefinitions, vaultVariables]);
|
|
165
|
+
|
|
166
|
+
if (urlString !== unresolvedUrlString) {
|
|
167
|
+
// get the final list of vault variables that match the resolved URL string
|
|
168
|
+
vaultUrl = new sdk.Url(urlString).toString(true);
|
|
169
|
+
vaultVariables = payload.vaultSecrets.__getMatchingVariables(vaultUrl);
|
|
170
|
+
|
|
171
|
+
// resolve vault variables in URL string
|
|
172
|
+
// @note other variable scopes are skipped as they are already resolved
|
|
173
|
+
urlString = sdk.Property.replaceSubstitutions(urlString, [vaultVariables]);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (urlString) {
|
|
177
|
+
urlString = sdk.Property.replaceSubstitutions(urlString, variableDefinitions);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return { urlString, variableDefinitions, vaultVariables };
|
|
181
|
+
}
|
|
182
|
+
|
|
124
183
|
/**
|
|
125
184
|
* Utility functions that are required to be re-used throughout the runner
|
|
126
185
|
*
|
|
@@ -397,6 +456,23 @@ module.exports = {
|
|
|
397
456
|
};
|
|
398
457
|
},
|
|
399
458
|
|
|
459
|
+
/**
|
|
460
|
+
* Resolve the URL string from an item by substituting all variables (including vault).
|
|
461
|
+
*
|
|
462
|
+
* @param {Item} item - The request item
|
|
463
|
+
* @param {Object} payload - Payload containing variable scopes
|
|
464
|
+
* @param {VariableScope} payload._variables -
|
|
465
|
+
* @param {Object} payload.data -
|
|
466
|
+
* @param {VariableScope} payload.environment -
|
|
467
|
+
* @param {VariableScope} payload.collectionVariables -
|
|
468
|
+
* @param {VariableScope} payload.globals -
|
|
469
|
+
* @param {VariableScope} payload.vaultSecrets -
|
|
470
|
+
* @returns {String} - The fully resolved URL string
|
|
471
|
+
*/
|
|
472
|
+
resolveUrlString (item, payload) {
|
|
473
|
+
return resolveUrl(item, payload).urlString;
|
|
474
|
+
},
|
|
475
|
+
|
|
400
476
|
/**
|
|
401
477
|
* Resolve variables in item and auth in context.
|
|
402
478
|
*
|
|
@@ -414,55 +490,16 @@ module.exports = {
|
|
|
414
490
|
resolveVariables (context, payload) {
|
|
415
491
|
if (!(context.item && context.item.request)) { return; }
|
|
416
492
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
// @note: this is the order of precedence for variable resolution - don't change it
|
|
421
|
-
_.get(payload, '_variables.values', []),
|
|
422
|
-
_.get(payload, 'data', []),
|
|
423
|
-
_.get(payload, 'environment.values', []),
|
|
424
|
-
_.get(payload, 'collectionVariables.values', []),
|
|
425
|
-
_.get(payload, 'globals.values', [])
|
|
426
|
-
// @note vault variables are added later
|
|
427
|
-
],
|
|
428
|
-
vaultValues = _.get(payload, 'vaultSecrets.values'),
|
|
429
|
-
|
|
430
|
-
hasVaultSecrets = vaultValues ? vaultValues.count() > 0 : false,
|
|
431
|
-
|
|
493
|
+
var resolved = resolveUrl(context.item, payload),
|
|
494
|
+
urlString = resolved.urlString,
|
|
495
|
+
variableDefinitions = resolved.variableDefinitions,
|
|
432
496
|
itemParent = context.item.parent(),
|
|
433
|
-
urlObj = context.item.request.url,
|
|
434
|
-
// @note URL string is used to resolve nested variables as URL parser doesn't support them well.
|
|
435
|
-
urlString = urlObj.toString(),
|
|
436
|
-
unresolvedUrlString = urlString,
|
|
437
|
-
|
|
438
|
-
vaultVariables,
|
|
439
|
-
vaultUrl,
|
|
440
497
|
item,
|
|
441
498
|
auth;
|
|
442
499
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
vaultVariables = payload.vaultSecrets.__getMatchingVariables(vaultUrl);
|
|
447
|
-
|
|
448
|
-
// resolve variables in URL string with initial vault variables
|
|
449
|
-
urlString = sdk.Property.replaceSubstitutions(urlString, [...variableDefinitions, vaultVariables]);
|
|
450
|
-
|
|
451
|
-
if (urlString !== unresolvedUrlString) {
|
|
452
|
-
// get the final list of vault variables that match the resolved URL string
|
|
453
|
-
vaultUrl = new sdk.Url(urlString).toString(true);
|
|
454
|
-
vaultVariables = payload.vaultSecrets.__getMatchingVariables(vaultUrl);
|
|
455
|
-
|
|
456
|
-
// resolve vault variables in URL string
|
|
457
|
-
// @note other variable scopes are skipped as they are already resolved
|
|
458
|
-
urlString = sdk.Property.replaceSubstitutions(urlString, [vaultVariables]);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// add vault variables to the list of variable definitions
|
|
462
|
-
variableDefinitions.push(vaultVariables);
|
|
463
|
-
}
|
|
464
|
-
else if (urlString) {
|
|
465
|
-
urlString = sdk.Property.replaceSubstitutions(urlString, variableDefinitions);
|
|
500
|
+
// add vault variables to the list of variable definitions
|
|
501
|
+
if (resolved.vaultVariables) {
|
|
502
|
+
variableDefinitions.push(resolved.vaultVariables);
|
|
466
503
|
}
|
|
467
504
|
|
|
468
505
|
// @todo - no need to sync variables when SDK starts supporting resolution from scope directly
|
|
@@ -474,6 +511,7 @@ module.exports = {
|
|
|
474
511
|
item.setParent(itemParent);
|
|
475
512
|
|
|
476
513
|
// re-parse and update the URL from the resolved string
|
|
514
|
+
// @note URL string is used to resolve nested variables as URL parser doesn't support them well.
|
|
477
515
|
urlString && (item.request.url = new sdk.Url(urlString));
|
|
478
516
|
|
|
479
517
|
auth = context.auth;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postman-runtime",
|
|
3
|
-
"version": "7.52.0
|
|
3
|
+
"version": "7.52.0",
|
|
4
4
|
"description": "Underlying library of executing Postman Collections",
|
|
5
5
|
"author": "Postman Inc.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"node-forge": "1.3.3",
|
|
55
55
|
"node-oauth1": "1.3.0",
|
|
56
56
|
"performance-now": "2.1.0",
|
|
57
|
-
"postman-collection": "5.3.0
|
|
57
|
+
"postman-collection": "5.3.0",
|
|
58
58
|
"postman-request": "2.88.1-postman.48",
|
|
59
|
-
"postman-sandbox": "6.6.1
|
|
59
|
+
"postman-sandbox": "6.6.1",
|
|
60
60
|
"postman-url-encoder": "3.0.8",
|
|
61
61
|
"serialised-error": "1.1.3",
|
|
62
62
|
"strip-json-comments": "3.1.1",
|