feat: add the ability to set extra headers (#27)
* feat: add the ability to set extra headers * switch to more generic map solution for headers
This commit is contained in:
36
action.js
36
action.js
@@ -12,6 +12,7 @@ const VALID_KV_VERSION = [-1, 1, 2];
|
||||
async function exportSecrets() {
|
||||
const vaultUrl = core.getInput('url', { required: true });
|
||||
const vaultNamespace = core.getInput('namespace', { required: false });
|
||||
const extraHeaders = parseHeadersInput('extraHeaders', { required: false });
|
||||
|
||||
let enginePath = core.getInput('path', { required: false });
|
||||
let kvVersion = core.getInput('kv-version', { required: false });
|
||||
@@ -76,6 +77,10 @@ async function exportSecrets() {
|
||||
},
|
||||
};
|
||||
|
||||
for (const [headerName, headerValue] of extraHeaders) {
|
||||
requestOptions.headers[headerName] = headerValue;
|
||||
}
|
||||
|
||||
if (vaultNamespace != null) {
|
||||
requestOptions.headers["X-Vault-Namespace"] = vaultNamespace;
|
||||
}
|
||||
@@ -216,6 +221,9 @@ function normalizeOutputKey(dataKey) {
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
/**
|
||||
* @param {string} input
|
||||
*/
|
||||
function parseBoolInput(input) {
|
||||
if (input === null || input === undefined || input.trim() === '') {
|
||||
return null;
|
||||
@@ -223,9 +231,35 @@ function parseBoolInput(input) {
|
||||
return Boolean(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} inputKey
|
||||
* @param {any} inputOptions
|
||||
*/
|
||||
function parseHeadersInput(inputKey, inputOptions) {
|
||||
/** @type {string}*/
|
||||
const rawHeadersString = core.getInput(inputKey, inputOptions) || '';
|
||||
const headerStrings = rawHeadersString
|
||||
.split('\n')
|
||||
.map(line => line.trim())
|
||||
.filter(line => line !== '');
|
||||
return headerStrings
|
||||
.reduce((map, line) => {
|
||||
const seperator = line.indexOf(':');
|
||||
const key = line.substring(0, seperator).trim().toLowerCase();
|
||||
const value = line.substring(seperator + 1).trim();
|
||||
if (map.has(key)) {
|
||||
map.set(key, [map.get(key), value].join(', '));
|
||||
} else {
|
||||
map.set(key, value);
|
||||
}
|
||||
return map;
|
||||
}, new Map());
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
exportSecrets,
|
||||
parseSecretsInput,
|
||||
parseResponse: getResponseData,
|
||||
normalizeOutputKey
|
||||
normalizeOutputKey,
|
||||
parseHeadersInput
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user