mirror of
https://github.com/hashicorp/vault-action.git
synced 2025-11-07 15:16:56 +00:00
Refactored wildcard
This commit is contained in:
parent
c557ed0663
commit
5dda2cf9f8
3 changed files with 13 additions and 17 deletions
|
|
@ -4,11 +4,7 @@ const command = require('@actions/core/lib/command');
|
|||
const got = require('got').default;
|
||||
const jsonata = require('jsonata');
|
||||
const { normalizeOutputKey } = require('./utils');
|
||||
|
||||
module.exports = {};
|
||||
const wildcard = '*';
|
||||
module.exports.wildcard = wildcard;
|
||||
|
||||
const { WILDCARD } = require('./constants');
|
||||
|
||||
const { auth: { retrieveToken }, secrets: { getSecrets } } = require('./index');
|
||||
|
||||
|
|
@ -120,7 +116,6 @@ async function exportSecrets() {
|
|||
core.debug(`✔ ${request.path} => outputs.${request.outputVarName}${exportEnv ? ` | env.${request.envVarName}` : ''}`);
|
||||
}
|
||||
};
|
||||
module.exports.exportSecrets = exportSecrets;
|
||||
|
||||
/** @typedef {Object} SecretRequest
|
||||
* @property {string} path
|
||||
|
|
@ -175,7 +170,7 @@ function parseSecretsInput(secretsInput) {
|
|||
const selectorAst = jsonata(selectorQuoted).ast();
|
||||
const selector = selectorQuoted.replace(new RegExp('"', 'g'), '');
|
||||
|
||||
if (selector !== wildcard && (selectorAst.type !== "path" || selectorAst.steps[0].stages) && selectorAst.type !== "string" && !outputVarName) {
|
||||
if (selector !== WILDCARD && (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}"`);
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +189,6 @@ function parseSecretsInput(secretsInput) {
|
|||
}
|
||||
return output;
|
||||
}
|
||||
module.exports.parseSecretsInput = parseSecretsInput;
|
||||
|
||||
/**
|
||||
* @param {string} inputKey
|
||||
|
|
@ -220,14 +214,10 @@ function parseHeadersInput(inputKey, inputOptions) {
|
|||
return map;
|
||||
}, new Map());
|
||||
}
|
||||
module.exports.parseHeadersInput = parseHeadersInput;
|
||||
// restructured module.exports to avoid circular dependency when secrets imports this.
|
||||
/*
|
||||
|
||||
module.exports = {
|
||||
exportSecrets,
|
||||
parseSecretsInput,
|
||||
normalizeOutputKey,
|
||||
parseHeadersInput,
|
||||
wildcard
|
||||
};
|
||||
*/
|
||||
|
||||
|
|
|
|||
5
src/constants.js
Normal file
5
src/constants.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
const WILDCARD = '*';
|
||||
|
||||
module.exports = {
|
||||
WILDCARD
|
||||
};
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
const jsonata = require("jsonata");
|
||||
const { wildcard } = require('./action');
|
||||
const { normalizeOutputKey } = require('./utils');
|
||||
const { WILDCARD } = require("./constants");
|
||||
const { normalizeOutputKey } = require("./utils");
|
||||
/**
|
||||
* @typedef {Object} SecretRequest
|
||||
* @property {string} path
|
||||
|
|
@ -50,7 +50,7 @@ async function getSecrets(secretRequests, client) {
|
|||
|
||||
body = JSON.parse(body);
|
||||
|
||||
if (selector === wildcard) {
|
||||
if (selector == WILDCARD) {
|
||||
let keys = body.data;
|
||||
if (body.data["data"] != undefined) {
|
||||
keys = keys.data;
|
||||
|
|
@ -104,6 +104,7 @@ async function getSecrets(secretRequests, client) {
|
|||
async function selectData(data, selector) {
|
||||
const ata = jsonata(selector);
|
||||
let result = JSON.stringify(await ata.evaluate(data));
|
||||
|
||||
// Compat for custom engines
|
||||
if (!result && ((ata.ast().type === "path" && ata.ast()['steps'].length === 1) || ata.ast().type === "string") && selector !== 'data' && 'data' in data) {
|
||||
result = JSON.stringify(await jsonata(`data.${selector}`).evaluate(data));
|
||||
|
|
|
|||
Loading…
Reference in a new issue