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:
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

View file

@ -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

View file

@ -21,11 +21,6 @@ const jsonata = require("jsonata");
* @param {import('got').Got} client
* @return {Promise<SecretResponse<TRequest>[]>}
*/
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
}
}