From 19a379929160b1ac97781a740bbab1d29c6a74d8 Mon Sep 17 00:00:00 2001 From: Joannis Orlandos Date: Fri, 23 Sep 2022 09:19:04 +0200 Subject: [PATCH] Add postPayload --- action.yml | 3 +++ src/action.js | 6 ++++-- src/secrets.js | 11 +++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/action.yml b/action.yml index 5a06b95..02fda8e 100644 --- a/action.yml +++ b/action.yml @@ -39,6 +39,9 @@ inputs: authPayload: description: 'The JSON payload to be sent to Vault when using a custom authentication method.' required: false + postPayload: + description: 'The JSON payload to be sent to Vault over a POST request, enabled POST instead of GET.' + required: false extraHeaders: description: 'A string of newline separated extra headers to include on every request.' required: false diff --git a/src/action.js b/src/action.js index b52bba3..2712241 100644 --- a/src/action.js +++ b/src/action.js @@ -19,6 +19,8 @@ async function exportSecrets() { const vaultMethod = (core.getInput('method', { required: false }) || 'token').toLowerCase(); const authPayload = core.getInput('authPayload', { required: false }); + const postPayload = core.getInput('postPayload', { required: false }); + if (!AUTH_METHODS.includes(vaultMethod) && !authPayload) { throw Error(`Sorry, the provided authentication method ${vaultMethod} is not currently supported and no custom authPayload was provided.`); } @@ -79,7 +81,7 @@ async function exportSecrets() { return request; }); - const results = await getSecrets(requests, client); + const results = await getSecrets(requests, client, postPayload); for (const result of results) { const { value, request, cachedResponse } = result; @@ -99,7 +101,7 @@ async function exportSecrets() { } }; -/** @typedef {Object} SecretRequest +/** @typedef {Object} SecretRequest * @property {string} path * @property {string} envVarName * @property {string} outputVarName diff --git a/src/secrets.js b/src/secrets.js index 1e35a32..0c248f4 100644 --- a/src/secrets.js +++ b/src/secrets.js @@ -21,11 +21,6 @@ const jsonata = require("jsonata"); * @param {import('got').Got} client * @return {Promise[]>} */ -async function getSecrets(secretRequests, client) { - getSecrets(secretRequests, client, undefined); -} - - async function getSecrets(secretRequests, client, body) { const responseCache = new Map(); const results = []; @@ -77,8 +72,8 @@ async function getSecrets(secretRequests, client, body) { /** * Uses a Jsonata selector retrieve a bit of data from the result - * @param {object} data - * @param {string} selector + * @param {object} data + * @param {string} selector */ function selectData(data, selector) { const ata = jsonata(selector); @@ -99,4 +94,4 @@ function selectData(data, selector) { module.exports = { getSecrets, selectData -} \ No newline at end of file +}