mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-07-27 00:43:14 +03:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ca76a4465 | |||
| 5b42d37bab | |||
| 124e6eecdb | |||
| 43c4212f70 | |||
| d4487e4dd0 | |||
| c7f47bbfcf | |||
| 11e2f12f99 | |||
| 6c64e41adc | |||
| 2f76ad395b | |||
| 307c9ae581 | |||
| b35ef16370 |
@@ -2,9 +2,8 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
pull_request_target:
|
||||
types: [opened, reopened, synchronize]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
## Unreleased
|
||||
|
||||
## 2.1.0 (October 6th, 2020)
|
||||
|
||||
Features:
|
||||
* Added `exportToken` to share the Vault token as an environment variable [GH-127](https://github.com/hashicorp/vault-action/pull/127)
|
||||
|
||||
Security:
|
||||
* `action/core` updated to 1.2.6 to address minor CVE [GH-130](https://github.com/hashicorp/vault-action/pull/130)
|
||||
|
||||
## 2.0.1 (September 15th, 2020)
|
||||
|
||||
Improvements:
|
||||
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
steps:
|
||||
# ...
|
||||
- name: Import Secrets
|
||||
uses: hashicorp/vault-action
|
||||
uses: hashicorp/vault-action@v2.0.1
|
||||
with:
|
||||
url: https://vault.mycompany.com:8200
|
||||
token: ${{ secrets.VaultToken }}
|
||||
@@ -250,6 +250,7 @@ Here are all the inputs available through `with`:
|
||||
| `authPayload` | The JSON payload to be sent to Vault when using a custom authentication method. | | |
|
||||
| `extraHeaders` | A string of newline separated extra headers to include on every request. | | |
|
||||
| `exportEnv` | Whether or not export secrets as environment variables. | `true` | |
|
||||
| `exportToken` | Whether or not export Vault token as environment variables (i.e VAULT_TOKEN). | `false` | |
|
||||
| `caCertificate` | Base64 encoded CA certificate the server certificate was signed with. | | |
|
||||
| `clientCertificate` | Base64 encoded client certificate the action uses to authenticate with Vault when mTLS is enabled. | | |
|
||||
| `clientKey` | Base64 encoded client key the action uses to authenticate with Vault when mTLS is enabled. | | |
|
||||
|
||||
@@ -36,6 +36,10 @@ inputs:
|
||||
description: 'Whether or not export secrets as environment variables.'
|
||||
default: 'true'
|
||||
required: false
|
||||
exportToken:
|
||||
description: 'Whether or not export Vault token as environment variables.'
|
||||
default: 'false'
|
||||
required: false
|
||||
caCertificate:
|
||||
description: 'Base64 encoded CA certificate to verify the Vault server certificate.'
|
||||
required: false
|
||||
|
||||
Vendored
+145
-45
@@ -723,6 +723,32 @@ __exportStar(__webpack_require__(323), exports);
|
||||
__exportStar(__webpack_require__(577), exports);
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 82:
|
||||
/***/ (function(__unusedmodule, exports) {
|
||||
|
||||
"use strict";
|
||||
|
||||
// We use any as a valid input type
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/**
|
||||
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
||||
* @param input input to sanitize into a string
|
||||
*/
|
||||
function toCommandValue(input) {
|
||||
if (input === null || input === undefined) {
|
||||
return '';
|
||||
}
|
||||
else if (typeof input === 'string' || input instanceof String) {
|
||||
return input;
|
||||
}
|
||||
return JSON.stringify(input);
|
||||
}
|
||||
exports.toCommandValue = toCommandValue;
|
||||
//# sourceMappingURL=utils.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 87:
|
||||
@@ -812,6 +838,42 @@ class Response extends Readable {
|
||||
module.exports = Response;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 102:
|
||||
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
// For internal use, subject to change.
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
// We use any as a valid input type
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
const fs = __importStar(__webpack_require__(747));
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const utils_1 = __webpack_require__(82);
|
||||
function issueCommand(command, message) {
|
||||
const filePath = process.env[`GITHUB_${command}`];
|
||||
if (!filePath) {
|
||||
throw new Error(`Unable to find environment variable for file command ${command}`);
|
||||
}
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new Error(`Missing file at path: ${filePath}`);
|
||||
}
|
||||
fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
}
|
||||
exports.issueCommand = issueCommand;
|
||||
//# sourceMappingURL=file-command.js.map
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 121:
|
||||
@@ -831,7 +893,7 @@ const parseBody = (response, responseType, parseJson, encoding) => {
|
||||
return rawBody.length === 0 ? '' : parseJson(rawBody.toString());
|
||||
}
|
||||
if (responseType === 'buffer') {
|
||||
return Buffer.from(rawBody);
|
||||
return rawBody;
|
||||
}
|
||||
throw new types_1.ParseError({
|
||||
message: `Unknown body type '${responseType}'`,
|
||||
@@ -10435,6 +10497,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const utils_1 = __webpack_require__(82);
|
||||
/**
|
||||
* Commands
|
||||
*
|
||||
@@ -10488,28 +10551,14 @@ class Command {
|
||||
return cmdStr;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Sanitizes an input into a string so it can be passed into issueCommand safely
|
||||
* @param input input to sanitize into a string
|
||||
*/
|
||||
function toCommandValue(input) {
|
||||
if (input === null || input === undefined) {
|
||||
return '';
|
||||
}
|
||||
else if (typeof input === 'string' || input instanceof String) {
|
||||
return input;
|
||||
}
|
||||
return JSON.stringify(input);
|
||||
}
|
||||
exports.toCommandValue = toCommandValue;
|
||||
function escapeData(s) {
|
||||
return toCommandValue(s)
|
||||
return utils_1.toCommandValue(s)
|
||||
.replace(/%/g, '%25')
|
||||
.replace(/\r/g, '%0D')
|
||||
.replace(/\n/g, '%0A');
|
||||
}
|
||||
function escapeProperty(s) {
|
||||
return toCommandValue(s)
|
||||
return utils_1.toCommandValue(s)
|
||||
.replace(/%/g, '%25')
|
||||
.replace(/\r/g, '%0D')
|
||||
.replace(/\n/g, '%0A')
|
||||
@@ -10688,7 +10737,9 @@ async function getSecrets(secretRequests, client) {
|
||||
body = result.body;
|
||||
responseCache.set(requestPath, body);
|
||||
}
|
||||
|
||||
if (!selector.match(/.*[\.].*/)) {
|
||||
selector = '"' + selector + '"'
|
||||
}
|
||||
selector = "data." + selector
|
||||
body = JSON.parse(body)
|
||||
if (body.data["data"] != undefined) {
|
||||
@@ -10714,7 +10765,7 @@ function selectData(data, selector) {
|
||||
const ata = jsonata(selector);
|
||||
let result = JSON.stringify(ata.evaluate(data));
|
||||
// Compat for custom engines
|
||||
if (!result && ata.ast().type === "path" && ata.ast()['steps'].length === 1 && selector !== 'data' && 'data' in data) {
|
||||
if (!result && ((ata.ast().type === "path" && ata.ast()['steps'].length === 1) || ata.ast().type === "string") && selector !== 'data' && 'data' in data) {
|
||||
result = JSON.stringify(jsonata(`data.${selector}`).evaluate(data));
|
||||
} else if (!result) {
|
||||
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) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const command_1 = __webpack_require__(431);
|
||||
const file_command_1 = __webpack_require__(102);
|
||||
const utils_1 = __webpack_require__(82);
|
||||
const os = __importStar(__webpack_require__(87));
|
||||
const path = __importStar(__webpack_require__(622));
|
||||
/**
|
||||
@@ -10782,9 +10835,17 @@ var ExitCode;
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function exportVariable(name, val) {
|
||||
const convertedVal = command_1.toCommandValue(val);
|
||||
const convertedVal = utils_1.toCommandValue(val);
|
||||
process.env[name] = convertedVal;
|
||||
command_1.issueCommand('set-env', { name }, convertedVal);
|
||||
const filePath = process.env['GITHUB_ENV'] || '';
|
||||
if (filePath) {
|
||||
const delimiter = '_GitHubActionsFileCommandDelimeter_';
|
||||
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
|
||||
file_command_1.issueCommand('ENV', commandValue);
|
||||
}
|
||||
else {
|
||||
command_1.issueCommand('set-env', { name }, convertedVal);
|
||||
}
|
||||
}
|
||||
exports.exportVariable = exportVariable;
|
||||
/**
|
||||
@@ -10800,7 +10861,13 @@ exports.setSecret = setSecret;
|
||||
* @param inputPath
|
||||
*/
|
||||
function addPath(inputPath) {
|
||||
command_1.issueCommand('add-path', {}, inputPath);
|
||||
const filePath = process.env['GITHUB_PATH'] || '';
|
||||
if (filePath) {
|
||||
file_command_1.issueCommand('PATH', inputPath);
|
||||
}
|
||||
else {
|
||||
command_1.issueCommand('add-path', {}, inputPath);
|
||||
}
|
||||
process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`;
|
||||
}
|
||||
exports.addPath = addPath;
|
||||
@@ -14022,6 +14089,7 @@ async function exportSecrets() {
|
||||
const vaultNamespace = core.getInput('namespace', { required: false });
|
||||
const extraHeaders = parseHeadersInput('extraHeaders', { required: false });
|
||||
const exportEnv = core.getInput('exportEnv', { required: false }) != 'false';
|
||||
const exportToken = (core.getInput('exportToken', { required: false }) || 'false').toLowerCase() != 'false';
|
||||
|
||||
const secretsInput = core.getInput('secrets', { required: true });
|
||||
const secretRequests = parseSecretsInput(secretsInput);
|
||||
@@ -14070,6 +14138,11 @@ async function exportSecrets() {
|
||||
defaultOptions.headers['X-Vault-Token'] = vaultToken;
|
||||
const client = got.extend(defaultOptions);
|
||||
|
||||
if (exportToken === true) {
|
||||
command.issue('add-mask', vaultToken);
|
||||
core.exportVariable('VAULT_TOKEN', `${vaultToken}`);
|
||||
}
|
||||
|
||||
const requests = secretRequests.map(request => {
|
||||
const { path, selector } = request;
|
||||
return request;
|
||||
@@ -14134,12 +14207,13 @@ function parseSecretsInput(secretsInput) {
|
||||
throw Error(`You must provide a valid path and key. Input: "${secret}"`);
|
||||
}
|
||||
|
||||
const [path, selector] = pathParts;
|
||||
const [path, selectorQuoted] = pathParts;
|
||||
|
||||
/** @type {any} */
|
||||
const selectorAst = jsonata(selector).ast();
|
||||
const selectorAst = jsonata(selectorQuoted).ast();
|
||||
const selector = selectorQuoted.replace(new RegExp('"', 'g'), '');
|
||||
|
||||
if ((selectorAst.type !== "path" || selectorAst.steps[0].stages) && !outputVarName) {
|
||||
if ((selectorAst.type !== "path" || selectorAst.steps[0].stages) && selectorAst.type !== "string" && !outputVarName) {
|
||||
throw Error(`You must provide a name for the output key when using json selectors. Input: "${secret}"`);
|
||||
}
|
||||
|
||||
@@ -14166,7 +14240,7 @@ function parseSecretsInput(secretsInput) {
|
||||
*/
|
||||
function normalizeOutputKey(dataKey, isEnvVar = false) {
|
||||
let outputKey = dataKey
|
||||
.replace('.', '__').replace(/[^\p{L}\p{N}_-]/gu, '');
|
||||
.replace('.', '__').replace(new RegExp('-', 'g'), '').replace(/[^\p{L}\p{N}_-]/gu, '');
|
||||
if (isEnvVar) {
|
||||
outputKey = outputKey.toUpperCase();
|
||||
}
|
||||
@@ -14509,18 +14583,28 @@ class Request extends stream_1.Duplex {
|
||||
if (json || body || form) {
|
||||
this._lockWrite();
|
||||
}
|
||||
(async (nonNormalizedOptions) => {
|
||||
if (exports.kIsNormalizedAlready in options) {
|
||||
this.options = options;
|
||||
}
|
||||
else {
|
||||
try {
|
||||
// @ts-expect-error Common TypeScript bug saying that `this.constructor` is not accessible
|
||||
this.options = this.constructor.normalizeArguments(url, options, defaults);
|
||||
}
|
||||
catch (error) {
|
||||
// TODO: Move this to `_destroy()`
|
||||
if (is_1.default.nodeStream(options.body)) {
|
||||
options.body.destroy();
|
||||
}
|
||||
this.destroy(error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
(async () => {
|
||||
var _a;
|
||||
try {
|
||||
if (nonNormalizedOptions.body instanceof fs_1.ReadStream) {
|
||||
await waitForOpenFile(nonNormalizedOptions.body);
|
||||
}
|
||||
if (exports.kIsNormalizedAlready in nonNormalizedOptions) {
|
||||
this.options = nonNormalizedOptions;
|
||||
}
|
||||
else {
|
||||
// @ts-expect-error Common TypeScript bug saying that `this.constructor` is not accessible
|
||||
this.options = this.constructor.normalizeArguments(url, nonNormalizedOptions, defaults);
|
||||
if (this.options.body instanceof fs_1.ReadStream) {
|
||||
await waitForOpenFile(this.options.body);
|
||||
}
|
||||
const { url: normalizedURL } = this.options;
|
||||
if (!normalizedURL) {
|
||||
@@ -14552,7 +14636,7 @@ class Request extends stream_1.Duplex {
|
||||
this.destroy(error);
|
||||
}
|
||||
}
|
||||
})(options);
|
||||
})();
|
||||
}
|
||||
static normalizeArguments(url, options, defaults) {
|
||||
var _a, _b, _c, _d, _e;
|
||||
@@ -14608,6 +14692,7 @@ class Request extends stream_1.Duplex {
|
||||
is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.key);
|
||||
is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.certificate);
|
||||
is_1.assert.any([is_1.default.string, is_1.default.undefined], options.https.passphrase);
|
||||
is_1.assert.any([is_1.default.string, is_1.default.buffer, is_1.default.array, is_1.default.undefined], options.https.pfx);
|
||||
}
|
||||
is_1.assert.any([is_1.default.object, is_1.default.undefined], options.cacheOptions);
|
||||
// `options.method`
|
||||
@@ -14686,6 +14771,9 @@ class Request extends stream_1.Duplex {
|
||||
options.url = options_to_url_1.default(options.prefixUrl, options);
|
||||
}
|
||||
if (options.url) {
|
||||
if ('port' in options) {
|
||||
delete options.port;
|
||||
}
|
||||
// Make it possible to change `options.prefixUrl`
|
||||
let { prefixUrl } = options;
|
||||
Object.defineProperty(options, 'prefixUrl', {
|
||||
@@ -14863,6 +14951,9 @@ class Request extends stream_1.Duplex {
|
||||
if ('passphrase' in options) {
|
||||
deprecation_warning_1.default('"options.passphrase" was never documented, please use "options.https.passphrase"');
|
||||
}
|
||||
if ('pfx' in options) {
|
||||
deprecation_warning_1.default('"options.pfx" was never documented, please use "options.https.pfx"');
|
||||
}
|
||||
// Other options
|
||||
if ('followRedirects' in options) {
|
||||
throw new TypeError('The `followRedirects` option does not exist. Use `followRedirect` instead.');
|
||||
@@ -15040,6 +15131,8 @@ class Request extends stream_1.Duplex {
|
||||
if ('form' in options) {
|
||||
delete options.form;
|
||||
}
|
||||
this[kBody] = undefined;
|
||||
delete options.headers['content-length'];
|
||||
}
|
||||
if (this.redirects.length >= options.maxRedirects) {
|
||||
this._beforeError(new MaxRedirectsError(this));
|
||||
@@ -15064,16 +15157,14 @@ class Request extends stream_1.Duplex {
|
||||
delete options.headers.authorization;
|
||||
}
|
||||
if (options.username || options.password) {
|
||||
// TODO: Fix this ignore.
|
||||
// @ts-expect-error
|
||||
delete options.username;
|
||||
// @ts-expect-error
|
||||
delete options.password;
|
||||
}
|
||||
if ('port' in options) {
|
||||
delete options.port;
|
||||
options.username = '';
|
||||
options.password = '';
|
||||
}
|
||||
}
|
||||
else {
|
||||
redirectUrl.username = options.username;
|
||||
redirectUrl.password = options.password;
|
||||
}
|
||||
this.redirects.push(redirectString);
|
||||
options.url = redirectUrl;
|
||||
for (const hook of options.hooks.beforeRedirect) {
|
||||
@@ -15240,6 +15331,9 @@ class Request extends stream_1.Duplex {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (options.body && this[kBody] !== options.body) {
|
||||
this[kBody] = options.body;
|
||||
}
|
||||
const { agent, request, timeout, url } = options;
|
||||
if (options.dnsCache && !('lookup' in options)) {
|
||||
options.lookup = options.dnsCache.lookup;
|
||||
@@ -15312,6 +15406,9 @@ class Request extends stream_1.Duplex {
|
||||
if (options.https.passphrase) {
|
||||
requestOptions.passphrase = options.https.passphrase;
|
||||
}
|
||||
if (options.https.pfx) {
|
||||
requestOptions.pfx = options.https.pfx;
|
||||
}
|
||||
}
|
||||
try {
|
||||
let requestOrResponse = await fn(url, requestOptions);
|
||||
@@ -15343,6 +15440,9 @@ class Request extends stream_1.Duplex {
|
||||
if (options.https.passphrase) {
|
||||
delete requestOptions.passphrase;
|
||||
}
|
||||
if (options.https.pfx) {
|
||||
delete requestOptions.pfx;
|
||||
}
|
||||
}
|
||||
if (isClientRequest(requestOrResponse)) {
|
||||
this._onRequest(requestOrResponse);
|
||||
|
||||
@@ -37,7 +37,7 @@ describe('integration', () => {
|
||||
},
|
||||
json: {
|
||||
data: {
|
||||
otherSecret: 'OTHERSUPERSECRET',
|
||||
"other-Secret-dash": 'OTHERSUPERSECRET',
|
||||
},
|
||||
}
|
||||
});
|
||||
@@ -100,7 +100,7 @@ describe('integration', () => {
|
||||
'X-Vault-Token': 'testtoken',
|
||||
},
|
||||
json: {
|
||||
otherSecret: 'OTHERCUSTOMSECRET',
|
||||
"other-Secret-dash": 'OTHERCUSTOMSECRET',
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -140,18 +140,18 @@ describe('integration', () => {
|
||||
});
|
||||
|
||||
it('get nested secret', async () => {
|
||||
mockInput('secret/data/nested/test otherSecret');
|
||||
mockInput(`secret/data/nested/test "other-Secret-dash"`);
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET');
|
||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRETDASH', 'OTHERSUPERSECRET');
|
||||
});
|
||||
|
||||
it('get multiple secrets', async () => {
|
||||
mockInput(`
|
||||
secret/data/test secret ;
|
||||
secret/data/test secret | NAMED_SECRET ;
|
||||
secret/data/nested/test otherSecret ;`);
|
||||
secret/data/nested/test "other-Secret-dash" ;`);
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
@@ -159,7 +159,7 @@ describe('integration', () => {
|
||||
|
||||
expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET');
|
||||
expect(core.exportVariable).toBeCalledWith('NAMED_SECRET', 'SUPERSECRET');
|
||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERSUPERSECRET');
|
||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRETDASH', 'OTHERSUPERSECRET');
|
||||
});
|
||||
|
||||
it('leading slash kvv2', async () => {
|
||||
@@ -179,11 +179,11 @@ describe('integration', () => {
|
||||
});
|
||||
|
||||
it('get nested secret from K/V v1', async () => {
|
||||
mockInput('secret-kv1/nested/test otherSecret');
|
||||
mockInput('secret-kv1/nested/test "other-Secret-dash"');
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRET', 'OTHERCUSTOMSECRET');
|
||||
expect(core.exportVariable).toBeCalledWith('OTHERSECRETDASH', 'OTHERCUSTOMSECRET');
|
||||
});
|
||||
|
||||
it('leading slash kvv1', async () => {
|
||||
|
||||
Generated
+968
-914
File diff suppressed because it is too large
Load Diff
+11
-4
@@ -12,6 +12,7 @@ async function exportSecrets() {
|
||||
const vaultNamespace = core.getInput('namespace', { required: false });
|
||||
const extraHeaders = parseHeadersInput('extraHeaders', { required: false });
|
||||
const exportEnv = core.getInput('exportEnv', { required: false }) != 'false';
|
||||
const exportToken = (core.getInput('exportToken', { required: false }) || 'false').toLowerCase() != 'false';
|
||||
|
||||
const secretsInput = core.getInput('secrets', { required: true });
|
||||
const secretRequests = parseSecretsInput(secretsInput);
|
||||
@@ -60,6 +61,11 @@ async function exportSecrets() {
|
||||
defaultOptions.headers['X-Vault-Token'] = vaultToken;
|
||||
const client = got.extend(defaultOptions);
|
||||
|
||||
if (exportToken === true) {
|
||||
command.issue('add-mask', vaultToken);
|
||||
core.exportVariable('VAULT_TOKEN', `${vaultToken}`);
|
||||
}
|
||||
|
||||
const requests = secretRequests.map(request => {
|
||||
const { path, selector } = request;
|
||||
return request;
|
||||
@@ -124,12 +130,13 @@ function parseSecretsInput(secretsInput) {
|
||||
throw Error(`You must provide a valid path and key. Input: "${secret}"`);
|
||||
}
|
||||
|
||||
const [path, selector] = pathParts;
|
||||
const [path, selectorQuoted] = pathParts;
|
||||
|
||||
/** @type {any} */
|
||||
const selectorAst = jsonata(selector).ast();
|
||||
const selectorAst = jsonata(selectorQuoted).ast();
|
||||
const selector = selectorQuoted.replace(new RegExp('"', 'g'), '');
|
||||
|
||||
if ((selectorAst.type !== "path" || selectorAst.steps[0].stages) && !outputVarName) {
|
||||
if ((selectorAst.type !== "path" || selectorAst.steps[0].stages) && selectorAst.type !== "string" && !outputVarName) {
|
||||
throw Error(`You must provide a name for the output key when using json selectors. Input: "${secret}"`);
|
||||
}
|
||||
|
||||
@@ -156,7 +163,7 @@ function parseSecretsInput(secretsInput) {
|
||||
*/
|
||||
function normalizeOutputKey(dataKey, isEnvVar = false) {
|
||||
let outputKey = dataKey
|
||||
.replace('.', '__').replace(/[^\p{L}\p{N}_-]/gu, '');
|
||||
.replace('.', '__').replace(new RegExp('-', 'g'), '').replace(/[^\p{L}\p{N}_-]/gu, '');
|
||||
if (isEnvVar) {
|
||||
outputKey = outputKey.toUpperCase();
|
||||
}
|
||||
|
||||
@@ -178,6 +178,12 @@ describe('exportSecrets', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function mockExportToken(doExport) {
|
||||
when(core.getInput)
|
||||
.calledWith('exportToken')
|
||||
.mockReturnValueOnce(doExport);
|
||||
}
|
||||
|
||||
it('simple secret retrieval', async () => {
|
||||
mockInput('test key');
|
||||
mockVaultData({
|
||||
@@ -257,4 +263,35 @@ describe('exportSecrets', () => {
|
||||
expect(core.exportVariable).toBeCalledWith('KEY__VALUE', '1');
|
||||
expect(core.setOutput).toBeCalledWith('key__value', '1');
|
||||
});
|
||||
|
||||
it('export Vault token', async () => {
|
||||
mockInput('test key');
|
||||
mockVaultData({
|
||||
key: 1
|
||||
});
|
||||
mockExportToken("true")
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportVariable).toBeCalledTimes(2);
|
||||
|
||||
expect(core.exportVariable).toBeCalledWith('VAULT_TOKEN', 'EXAMPLE');
|
||||
expect(core.exportVariable).toBeCalledWith('KEY', '1');
|
||||
expect(core.setOutput).toBeCalledWith('key', '1');
|
||||
});
|
||||
|
||||
it('not export Vault token', async () => {
|
||||
mockInput('test key');
|
||||
mockVaultData({
|
||||
key: 1
|
||||
});
|
||||
mockExportToken("false")
|
||||
|
||||
await exportSecrets();
|
||||
|
||||
expect(core.exportVariable).toBeCalledTimes(1);
|
||||
|
||||
expect(core.exportVariable).toBeCalledWith('KEY', '1');
|
||||
expect(core.setOutput).toBeCalledWith('key', '1');
|
||||
});
|
||||
});
|
||||
|
||||
+4
-2
@@ -38,7 +38,9 @@ async function getSecrets(secretRequests, client) {
|
||||
body = result.body;
|
||||
responseCache.set(requestPath, body);
|
||||
}
|
||||
|
||||
if (!selector.match(/.*[\.].*/)) {
|
||||
selector = '"' + selector + '"'
|
||||
}
|
||||
selector = "data." + selector
|
||||
body = JSON.parse(body)
|
||||
if (body.data["data"] != undefined) {
|
||||
@@ -64,7 +66,7 @@ function selectData(data, selector) {
|
||||
const ata = jsonata(selector);
|
||||
let result = JSON.stringify(ata.evaluate(data));
|
||||
// Compat for custom engines
|
||||
if (!result && ata.ast().type === "path" && ata.ast()['steps'].length === 1 && selector !== 'data' && 'data' in data) {
|
||||
if (!result && ((ata.ast().type === "path" && ata.ast()['steps'].length === 1) || ata.ast().type === "string") && selector !== 'data' && 'data' in data) {
|
||||
result = JSON.stringify(jsonata(`data.${selector}`).evaluate(data));
|
||||
} else if (!result) {
|
||||
throw Error(`Unable to retrieve result for ${selector}. No match data was found. Double check your Key or Selector.`);
|
||||
|
||||
Reference in New Issue
Block a user