diff --git a/.vscode/settings.json b/.vscode/settings.json index 42162df..3396f6f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "markdown-toc.depthFrom": 2 -} \ No newline at end of file + "markdown-toc.depthFrom": 2, + "editor.formatOnSave": false +} diff --git a/src/secrets.js b/src/secrets.js index 2df2bb2..a012f9b 100644 --- a/src/secrets.js +++ b/src/secrets.js @@ -1,5 +1,6 @@ const jsonata = require("jsonata"); -const { normalizeOutputKey, wildcard} = require('./action'); +const { wildcard } = require('./action'); +const { normalizeOutputKey } = require('./utils'); /** * @typedef {Object} SecretRequest * @property {string} path @@ -75,22 +76,17 @@ async function getSecrets(secretRequests, client) { selector = '"' + selector + '"' } selector = "data." + selector - //body = JSON.parse(body) + if (body.data["data"] != undefined) { selector = "data." + selector } - const value = selectData(body, selector); + const value = await selectData(body, selector); results.push({ request: newRequest, value, cachedResponse }); - //DEBUG - //console.log("After", newRequest, value); - - // used cachedResponse for first entry in wildcard list and set to true for the rest - cachedResponse = true; } } diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..b8dd863 --- /dev/null +++ b/src/utils.js @@ -0,0 +1,19 @@ +/** + * Replaces any dot chars to __ and removes non-ascii charts + * @param {string} dataKey + * @param {boolean=} isEnvVar + */ +function normalizeOutputKey(dataKey, isEnvVar = false) { + let outputKey = dataKey + .replace(".", "__") + .replace(new RegExp("-", "g"), "") + .replace(/[^\p{L}\p{N}_-]/gu, ""); + if (isEnvVar) { + outputKey = outputKey.toUpperCase(); + } + return outputKey; +} + +module.exports = { + normalizeOutputKey +};