Skip to content

Commit 5b42d37

Browse files
Update to v2.0.2 (#133)
1 parent 124e6ee commit 5b42d37

1 file changed

Lines changed: 146 additions & 46 deletions

File tree

dist/index.js

Lines changed: 146 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,32 @@ __exportStar(__webpack_require__(323), exports);
723723
__exportStar(__webpack_require__(577), exports);
724724

725725

726+
/***/ }),
727+
728+
/***/ 82:
729+
/***/ (function(__unusedmodule, exports) {
730+
731+
"use strict";
732+
733+
// We use any as a valid input type
734+
/* eslint-disable @typescript-eslint/no-explicit-any */
735+
Object.defineProperty(exports, "__esModule", { value: true });
736+
/**
737+
* Sanitizes an input into a string so it can be passed into issueCommand safely
738+
* @param input input to sanitize into a string
739+
*/
740+
function toCommandValue(input) {
741+
if (input === null || input === undefined) {
742+
return '';
743+
}
744+
else if (typeof input === 'string' || input instanceof String) {
745+
return input;
746+
}
747+
return JSON.stringify(input);
748+
}
749+
exports.toCommandValue = toCommandValue;
750+
//# sourceMappingURL=utils.js.map
751+
726752
/***/ }),
727753

728754
/***/ 87:
@@ -812,6 +838,42 @@ class Response extends Readable {
812838
module.exports = Response;
813839

814840

841+
/***/ }),
842+
843+
/***/ 102:
844+
/***/ (function(__unusedmodule, exports, __webpack_require__) {
845+
846+
"use strict";
847+
848+
// For internal use, subject to change.
849+
var __importStar = (this && this.__importStar) || function (mod) {
850+
if (mod && mod.__esModule) return mod;
851+
var result = {};
852+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
853+
result["default"] = mod;
854+
return result;
855+
};
856+
Object.defineProperty(exports, "__esModule", { value: true });
857+
// We use any as a valid input type
858+
/* eslint-disable @typescript-eslint/no-explicit-any */
859+
const fs = __importStar(__webpack_require__(747));
860+
const os = __importStar(__webpack_require__(87));
861+
const utils_1 = __webpack_require__(82);
862+
function issueCommand(command, message) {
863+
const filePath = process.env[`GITHUB_${command}`];
864+
if (!filePath) {
865+
throw new Error(`Unable to find environment variable for file command ${command}`);
866+
}
867+
if (!fs.existsSync(filePath)) {
868+
throw new Error(`Missing file at path: ${filePath}`);
869+
}
870+
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
871+
encoding: 'utf8'
872+
});
873+
}
874+
exports.issueCommand = issueCommand;
875+
//# sourceMappingURL=file-command.js.map
876+
815877
/***/ }),
816878

817879
/***/ 121:
@@ -831,7 +893,7 @@ const parseBody = (response, responseType, parseJson, encoding) => {
831893
return rawBody.length === 0 ? '' : parseJson(rawBody.toString());
832894
}
833895
if (responseType === 'buffer') {
834-
return Buffer.from(rawBody);
896+
return rawBody;
835897
}
836898
throw new types_1.ParseError({
837899
message: `Unknown body type '${responseType}'`,
@@ -10435,6 +10497,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
1043510497
};
1043610498
Object.defineProperty(exports, "__esModule", { value: true });
1043710499
const os = __importStar(__webpack_require__(87));
10500+
const utils_1 = __webpack_require__(82);
1043810501
/**
1043910502
* Commands
1044010503
*
@@ -10488,28 +10551,14 @@ class Command {
1048810551
return cmdStr;
1048910552
}
1049010553
}
10491-
/**
10492-
* Sanitizes an input into a string so it can be passed into issueCommand safely
10493-
* @param input input to sanitize into a string
10494-
*/
10495-
function toCommandValue(input) {
10496-
if (input === null || input === undefined) {
10497-
return '';
10498-
}
10499-
else if (typeof input === 'string' || input instanceof String) {
10500-
return input;
10501-
}
10502-
return JSON.stringify(input);
10503-
}
10504-
exports.toCommandValue = toCommandValue;
1050510554
function escapeData(s) {
10506-
return toCommandValue(s)
10555+
return utils_1.toCommandValue(s)
1050710556
.replace(/%/g, '%25')
1050810557
.replace(/\r/g, '%0D')
1050910558
.replace(/\n/g, '%0A');
1051010559
}
1051110560
function escapeProperty(s) {
10512-
return toCommandValue(s)
10561+
return utils_1.toCommandValue(s)
1051310562
.replace(/%/g, '%25')
1051410563
.replace(/\r/g, '%0D')
1051510564
.replace(/\n/g, '%0A')
@@ -10688,7 +10737,9 @@ async function getSecrets(secretRequests, client) {
1068810737
body = result.body;
1068910738
responseCache.set(requestPath, body);
1069010739
}
10691-
10740+
if (!selector.match(/.*[\.].*/)) {
10741+
selector = '"' + selector + '"'
10742+
}
1069210743
selector = "data." + selector
1069310744
body = JSON.parse(body)
1069410745
if (body.data["data"] != undefined) {
@@ -10714,7 +10765,7 @@ function selectData(data, selector) {
1071410765
const ata = jsonata(selector);
1071510766
let result = JSON.stringify(ata.evaluate(data));
1071610767
// Compat for custom engines
10717-
if (!result && ata.ast().type === "path" && ata.ast()['steps'].length === 1 && selector !== 'data' && 'data' in data) {
10768+
if (!result && ((ata.ast().type === "path" && ata.ast()['steps'].length === 1) || ata.ast().type === "string") && selector !== 'data' && 'data' in data) {
1071810769
result = JSON.stringify(jsonata(`data.${selector}`).evaluate(data));
1071910770
} else if (!result) {
1072010771
throw Error(`Unable to retrieve result for ${selector}. No match data was found. Double check your Key or Selector.`);
@@ -10756,6 +10807,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
1075610807
};
1075710808
Object.defineProperty(exports, "__esModule", { value: true });
1075810809
const command_1 = __webpack_require__(431);
10810+
const file_command_1 = __webpack_require__(102);
10811+
const utils_1 = __webpack_require__(82);
1075910812
const os = __importStar(__webpack_require__(87));
1076010813
const path = __importStar(__webpack_require__(622));
1076110814
/**
@@ -10782,9 +10835,17 @@ var ExitCode;
1078210835
*/
1078310836
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1078410837
function exportVariable(name, val) {
10785-
const convertedVal = command_1.toCommandValue(val);
10838+
const convertedVal = utils_1.toCommandValue(val);
1078610839
process.env[name] = convertedVal;
10787-
command_1.issueCommand('set-env', { name }, convertedVal);
10840+
const filePath = process.env['GITHUB_ENV'] || '';
10841+
if (filePath) {
10842+
const delimiter = '_GitHubActionsFileCommandDelimeter_';
10843+
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
10844+
file_command_1.issueCommand('ENV', commandValue);
10845+
}
10846+
else {
10847+
command_1.issueCommand('set-env', { name }, convertedVal);
10848+
}
1078810849
}
1078910850
exports.exportVariable = exportVariable;
1079010851
/**
@@ -10800,7 +10861,13 @@ exports.setSecret = setSecret;
1080010861
* @param inputPath
1080110862
*/
1080210863
function addPath(inputPath) {
10803-
command_1.issueCommand('add-path', {}, inputPath);
10864+
const filePath = process.env['GITHUB_PATH'] || '';
10865+
if (filePath) {
10866+
file_command_1.issueCommand('PATH', inputPath);
10867+
}
10868+
else {
10869+
command_1.issueCommand('add-path', {}, inputPath);
10870+
}
1080410871
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
1080510872
}
1080610873
exports.addPath = addPath;
@@ -14022,6 +14089,7 @@ async function exportSecrets() {
1402214089
const vaultNamespace = core.getInput('namespace', { required: false });
1402314090
const extraHeaders = parseHeadersInput('extraHeaders', { required: false });
1402414091
const exportEnv = core.getInput('exportEnv', { required: false }) != 'false';
14092+
const exportToken = (core.getInput('exportToken', { required: false }) || 'false').toLowerCase() != 'false';
1402514093

1402614094
const secretsInput = core.getInput('secrets', { required: true });
1402714095
const secretRequests = parseSecretsInput(secretsInput);
@@ -14070,6 +14138,11 @@ async function exportSecrets() {
1407014138
defaultOptions.headers['X-Vault-Token'] = vaultToken;
1407114139
const client = got.extend(defaultOptions);
1407214140

14141+
if (exportToken === true) {
14142+
command.issue('add-mask', vaultToken);
14143+
core.exportVariable('VAULT_TOKEN', `${vaultToken}`);
14144+
}
14145+
1407314146
const requests = secretRequests.map(request => {
1407414147
const { path, selector } = request;
1407514148
return request;
@@ -14134,12 +14207,13 @@ function parseSecretsInput(secretsInput) {
1413414207
throw Error(`You must provide a valid path and key. Input: "${secret}"`);
1413514208
}
1413614209

14137-
const [path, selector] = pathParts;
14210+
const [path, selectorQuoted] = pathParts;
1413814211

1413914212
/** @type {any} */
14140-
const selectorAst = jsonata(selector).ast();
14213+
const selectorAst = jsonata(selectorQuoted).ast();
14214+
const selector = selectorQuoted.replace(new RegExp('"', 'g'), '');
1414114215

14142-
if ((selectorAst.type !== "path" || selectorAst.steps[0].stages) && !outputVarName) {
14216+
if ((selectorAst.type !== "path" || selectorAst.steps[0].stages) && selectorAst.type !== "string" && !outputVarName) {
1414314217
throw Error(`You must provide a name for the output key when using json selectors. Input: "${secret}"`);
1414414218
}
1414514219

@@ -14166,7 +14240,7 @@ function parseSecretsInput(secretsInput) {
1416614240
*/
1416714241
function normalizeOutputKey(dataKey, isEnvVar = false) {
1416814242
let outputKey = dataKey
14169-
.replace('.', '__').replace(/[^\p{L}\p{N}_-]/gu, '');
14243+
.replace('.', '__').replace(new RegExp('-', 'g'), '').replace(/[^\p{L}\p{N}_-]/gu, '');
1417014244
if (isEnvVar) {
1417114245
outputKey = outputKey.toUpperCase();
1417214246
}
@@ -14509,18 +14583,28 @@ class Request extends stream_1.Duplex {
1450914583
if (json || body || form) {
1451014584
this._lockWrite();
1451114585
}
14512-
(async (nonNormalizedOptions) => {
14513-
var _a;
14586+
if (exports.kIsNormalizedAlready in options) {
14587+
this.options = options;
14588+
}
14589+
else {
1451414590
try {
14515-
if (nonNormalizedOptions.body instanceof fs_1.ReadStream) {
14516-
await waitForOpenFile(nonNormalizedOptions.body);
14517-
}
14518-
if (exports.kIsNormalizedAlready in nonNormalizedOptions) {
14519-
this.options = nonNormalizedOptions;
14591+
// @ts-expect-error Common TypeScript bug saying that `this.constructor` is not accessible
14592+
this.options = this.constructor.normalizeArguments(url, options, defaults);
14593+
}
14594+
catch (error) {
14595+
// TODO: Move this to `_destroy()`
14596+
if (is_1.default.nodeStream(options.body)) {
14597+
options.body.destroy();
1452014598
}
14521-
else {
14522-
// @ts-expect-error Common TypeScript bug saying that `this.constructor` is not accessible
14523-
this.options = this.constructor.normalizeArguments(url, nonNormalizedOptions, defaults);
14599+
this.destroy(error);
14600+
return;
14601+
}
14602+
}
14603+
(async () => {
14604+
var _a;
14605+
try {
14606+
if (this.options.body instanceof fs_1.ReadStream) {
14607+
await waitForOpenFile(this.options.body);
1452414608
}
1452514609
const { url: normalizedURL } = this.options;
1452614610
if (!normalizedURL) {
@@ -14552,7 +14636,7 @@ class Request extends stream_1.Duplex {
1455214636
this.destroy(error);
1455314637
}
1455414638
}
14555-
})(options);
14639+
})();
1455614640
}
1455714641
static normalizeArguments(url, options, defaults) {
1455814642
var _a, _b, _c, _d, _e;
@@ -14608,6 +14692,7 @@ class Request extends stream_1.Duplex {
1460814692
is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.key);
1460914693
is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.certificate);
1461014694
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.https.passphrase);
14695+
is_1.assert.any([is_1.default.string, is_1.default.buffer, is_1.default.array, is_1.default.undefined], options.https.pfx);
1461114696
}
1461214697
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.cacheOptions);
1461314698
// `options.method`
@@ -14686,6 +14771,9 @@ class Request extends stream_1.Duplex {
1468614771
options.url = options_to_url_1.default(options.prefixUrl, options);
1468714772
}
1468814773
if (options.url) {
14774+
if ('port' in options) {
14775+
delete options.port;
14776+
}
1468914777
// Make it possible to change `options.prefixUrl`
1469014778
let { prefixUrl } = options;
1469114779
Object.defineProperty(options, 'prefixUrl', {
@@ -14863,6 +14951,9 @@ class Request extends stream_1.Duplex {
1486314951
if ('passphrase' in options) {
1486414952
deprecation_warning_1.default('"options.passphrase" was never documented, please use "options.https.passphrase"');
1486514953
}
14954+
if ('pfx' in options) {
14955+
deprecation_warning_1.default('"options.pfx" was never documented, please use "options.https.pfx"');
14956+
}
1486614957
// Other options
1486714958
if ('followRedirects' in options) {
1486814959
throw new TypeError('The `followRedirects` option does not exist. Use `followRedirect` instead.');
@@ -15040,6 +15131,8 @@ class Request extends stream_1.Duplex {
1504015131
if ('form' in options) {
1504115132
delete options.form;
1504215133
}
15134+
this[kBody] = undefined;
15135+
delete options.headers['content-length'];
1504315136
}
1504415137
if (this.redirects.length >= options.maxRedirects) {
1504515138
this._beforeError(new MaxRedirectsError(this));
@@ -15064,16 +15157,14 @@ class Request extends stream_1.Duplex {
1506415157
delete options.headers.authorization;
1506515158
}
1506615159
if (options.username || options.password) {
15067-
// TODO: Fix this ignore.
15068-
// @ts-expect-error
15069-
delete options.username;
15070-
// @ts-expect-error
15071-
delete options.password;
15072-
}
15073-
if ('port' in options) {
15074-
delete options.port;
15160+
options.username = '';
15161+
options.password = '';
1507515162
}
1507615163
}
15164+
else {
15165+
redirectUrl.username = options.username;
15166+
redirectUrl.password = options.password;
15167+
}
1507715168
this.redirects.push(redirectString);
1507815169
options.url = redirectUrl;
1507915170
for (const hook of options.hooks.beforeRedirect) {
@@ -15240,6 +15331,9 @@ class Request extends stream_1.Duplex {
1524015331
break;
1524115332
}
1524215333
}
15334+
if (options.body && this[kBody] !== options.body) {
15335+
this[kBody] = options.body;
15336+
}
1524315337
const { agent, request, timeout, url } = options;
1524415338
if (options.dnsCache && !('lookup' in options)) {
1524515339
options.lookup = options.dnsCache.lookup;
@@ -15312,6 +15406,9 @@ class Request extends stream_1.Duplex {
1531215406
if (options.https.passphrase) {
1531315407
requestOptions.passphrase = options.https.passphrase;
1531415408
}
15409+
if (options.https.pfx) {
15410+
requestOptions.pfx = options.https.pfx;
15411+
}
1531515412
}
1531615413
try {
1531715414
let requestOrResponse = await fn(url, requestOptions);
@@ -15343,6 +15440,9 @@ class Request extends stream_1.Duplex {
1534315440
if (options.https.passphrase) {
1534415441
delete requestOptions.passphrase;
1534515442
}
15443+
if (options.https.pfx) {
15444+
delete requestOptions.pfx;
15445+
}
1534615446
}
1534715447
if (isClientRequest(requestOrResponse)) {
1534815448
this._onRequest(requestOrResponse);
@@ -15994,4 +16094,4 @@ module.exports.MaxBufferError = MaxBufferError;
1599416094

1599516095
/***/ })
1599616096

15997-
/******/ });
16097+
/******/ });

0 commit comments

Comments
 (0)