5
0
Fork 0
mirror of https://github.com/hashicorp/vault-action.git synced 2025-11-09 16:16:55 +00:00

Add postPayload

This commit is contained in:
Joannis Orlandos 2022-09-23 09:19:04 +02:00
parent 7ec3aeab19
commit 19a3799291
3 changed files with 10 additions and 10 deletions

View file

@ -39,6 +39,9 @@ inputs:
authPayload: authPayload:
description: 'The JSON payload to be sent to Vault when using a custom authentication method.' description: 'The JSON payload to be sent to Vault when using a custom authentication method.'
required: false required: false
postPayload:
description: 'The JSON payload to be sent to Vault over a POST request, enabled POST instead of GET.'
required: false
extraHeaders: extraHeaders:
description: 'A string of newline separated extra headers to include on every request.' description: 'A string of newline separated extra headers to include on every request.'
required: false required: false

View file

@ -19,6 +19,8 @@ async function exportSecrets() {
const vaultMethod = (core.getInput('method', { required: false }) || 'token').toLowerCase(); const vaultMethod = (core.getInput('method', { required: false }) || 'token').toLowerCase();
const authPayload = core.getInput('authPayload', { required: false }); const authPayload = core.getInput('authPayload', { required: false });
const postPayload = core.getInput('postPayload', { required: false });
if (!AUTH_METHODS.includes(vaultMethod) && !authPayload) { if (!AUTH_METHODS.includes(vaultMethod) && !authPayload) {
throw Error(`Sorry, the provided authentication method ${vaultMethod} is not currently supported and no custom authPayload was provided.`); 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; return request;
}); });
const results = await getSecrets(requests, client); const results = await getSecrets(requests, client, postPayload);
for (const result of results) { for (const result of results) {
const { value, request, cachedResponse } = result; const { value, request, cachedResponse } = result;
@ -99,7 +101,7 @@ async function exportSecrets() {
} }
}; };
/** @typedef {Object} SecretRequest /** @typedef {Object} SecretRequest
* @property {string} path * @property {string} path
* @property {string} envVarName * @property {string} envVarName
* @property {string} outputVarName * @property {string} outputVarName

View file

@ -21,11 +21,6 @@ const jsonata = require("jsonata");
* @param {import('got').Got} client * @param {import('got').Got} client
* @return {Promise<SecretResponse<TRequest>[]>} * @return {Promise<SecretResponse<TRequest>[]>}
*/ */
async function getSecrets(secretRequests, client) {
getSecrets(secretRequests, client, undefined);
}
async function getSecrets(secretRequests, client, body) { async function getSecrets(secretRequests, client, body) {
const responseCache = new Map(); const responseCache = new Map();
const results = []; const results = [];
@ -77,8 +72,8 @@ async function getSecrets(secretRequests, client, body) {
/** /**
* Uses a Jsonata selector retrieve a bit of data from the result * Uses a Jsonata selector retrieve a bit of data from the result
* @param {object} data * @param {object} data
* @param {string} selector * @param {string} selector
*/ */
function selectData(data, selector) { function selectData(data, selector) {
const ata = jsonata(selector); const ata = jsonata(selector);
@ -99,4 +94,4 @@ function selectData(data, selector) {
module.exports = { module.exports = {
getSecrets, getSecrets,
selectData selectData
} }