mirror of
https://github.com/hashicorp/vault-action.git
synced 2026-05-06 10:04:45 +00:00
make output more forgiving and shore up selectors
This commit is contained in:
parent
5099ea65b2
commit
fc73c8c906
5 changed files with 88 additions and 31 deletions
30
dist/index.js
vendored
30
dist/index.js
vendored
|
|
@ -11024,11 +11024,15 @@ async function getSecrets(secretRequests, client) {
|
|||
* @param {string} selector
|
||||
*/
|
||||
function selectData(data, selector) {
|
||||
let result = JSON.stringify(jsonata(selector).evaluate(data));
|
||||
const ata = jsonata(selector);
|
||||
let result = JSON.stringify(ata.evaluate(data));
|
||||
// Compat for custom engines
|
||||
if (!result && !selector.includes('.') && selector !== 'data' && 'data' in data) {
|
||||
if (!result && ata.ast().type === "path" && ata.ast()['steps'].length === 1 && 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.`);
|
||||
}
|
||||
|
||||
if (result.startsWith(`"`)) {
|
||||
result = result.substring(1, result.length - 1);
|
||||
}
|
||||
|
|
@ -13381,18 +13385,14 @@ function parseSecretsInput(secretsInput) {
|
|||
/** @type {any} */
|
||||
const selectorAst = jsonata(selector).ast();
|
||||
|
||||
if (selectorAst.type !== "path") {
|
||||
throw Error(`Invalid path selector.`);
|
||||
}
|
||||
|
||||
if ((selectorAst.steps > 1 || selectorAst.steps[0].stages) && !outputVarName) {
|
||||
if ((selectorAst.type !== "path" || selectorAst.steps[0].stages) && !outputVarName) {
|
||||
throw Error(`You must provide a name for the output key when using json selectors. Input: "${secret}"`);
|
||||
}
|
||||
|
||||
let envVarName = outputVarName;
|
||||
if (!outputVarName) {
|
||||
outputVarName = selector;
|
||||
envVarName = normalizeOutputKey(outputVarName);
|
||||
outputVarName = normalizeOutputKey(selector);
|
||||
envVarName = normalizeOutputKey(selector, true);
|
||||
}
|
||||
|
||||
output.push({
|
||||
|
|
@ -13406,11 +13406,17 @@ function parseSecretsInput(secretsInput) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Replaces any forward-slash characters to
|
||||
* Replaces any dot chars to __ and removes non-ascii charts
|
||||
* @param {string} dataKey
|
||||
* @param {boolean=} isEnvVar
|
||||
*/
|
||||
function normalizeOutputKey(dataKey) {
|
||||
return dataKey.replace('/', '__').replace('.', '__').replace(/[^\w-]/, '').toUpperCase();
|
||||
function normalizeOutputKey(dataKey, isEnvVar = false) {
|
||||
let outputKey = dataKey
|
||||
.replace('.', '__').replace(/[^\p{L}\p{N}_-]/gu, '');
|
||||
if (isEnvVar) {
|
||||
outputKey = outputKey.toUpperCase();
|
||||
}
|
||||
return outputKey;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue