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

chore: streamline method logic

This commit is contained in:
Richard Simpson 2020-01-14 20:48:48 -06:00
parent 42a9c06aa7
commit 3872511436
2 changed files with 14 additions and 28 deletions

View file

@ -2,30 +2,25 @@ const core = require('@actions/core');
const command = require('@actions/core/lib/command'); const command = require('@actions/core/lib/command');
const got = require('got'); const got = require('got');
const AUTH_METHODS = ['approle', 'token'];
async function exportSecrets() { async function exportSecrets() {
const _methods = ['approle', 'token'];
const vaultUrl = core.getInput('url', { required: true }); const vaultUrl = core.getInput('url', { required: true });
const vaultRoleId = core.getInput('roleId', { required: false });
const vaultSecretId = core.getInput('secretId', { required: false });
const vaultNamespace = core.getInput('namespace', { required: false }); const vaultNamespace = core.getInput('namespace', { required: false });
let vaultMethod = core.getInput('method', { required: false });
let vaultToken = core.getInput('token', { required: false });
const secretsInput = core.getInput('secrets', { required: true }); const secretsInput = core.getInput('secrets', { required: true });
const secrets = parseSecretsInput(secretsInput); const secrets = parseSecretsInput(secretsInput);
if (!vaultMethod) { const vaultMethod = core.getInput('method', { required: false }) || 'token';
vaultMethod = 'token'; if (!AUTH_METHODS.includes(vaultMethod)) {
}
if (!_methods.includes(vaultMethod)) {
throw Error(`Sorry, the authentication method ${vaultMethod} is not currently supported.`); throw Error(`Sorry, the authentication method ${vaultMethod} is not currently supported.`);
} }
let vaultToken = null;
switch (vaultMethod) { switch (vaultMethod) {
case 'approle': case 'approle':
const vaultRoleId = core.getInput('roleId', { required: false });
const vaultSecretId = core.getInput('secretId', { required: false });
core.debug('Try to retrieve Vault Token from approle'); core.debug('Try to retrieve Vault Token from approle');
var options = { var options = {
headers: {}, headers: {},
@ -46,9 +41,7 @@ async function exportSecrets() {
} }
break; break;
default: default:
if (!vaultToken) { vaultToken = core.getInput('token', { required: true });
throw Error(`No token was provided. You must provided a valid vault token if using token authentication.`);
}
break; break;
} }

21
dist/index.js vendored
View file

@ -4065,30 +4065,25 @@ const core = __webpack_require__(470);
const command = __webpack_require__(431); const command = __webpack_require__(431);
const got = __webpack_require__(77); const got = __webpack_require__(77);
const AUTH_METHODS = ['approle', 'token'];
async function exportSecrets() { async function exportSecrets() {
const _methods = ['approle', 'token'];
const vaultUrl = core.getInput('url', { required: true }); const vaultUrl = core.getInput('url', { required: true });
const vaultRoleId = core.getInput('roleId', { required: false });
const vaultSecretId = core.getInput('secretId', { required: false });
const vaultNamespace = core.getInput('namespace', { required: false }); const vaultNamespace = core.getInput('namespace', { required: false });
let vaultMethod = core.getInput('method', { required: false });
let vaultToken = core.getInput('token', { required: false });
const secretsInput = core.getInput('secrets', { required: true }); const secretsInput = core.getInput('secrets', { required: true });
const secrets = parseSecretsInput(secretsInput); const secrets = parseSecretsInput(secretsInput);
if (!vaultMethod) { const vaultMethod = core.getInput('method', { required: false }) || 'token';
vaultMethod = 'token'; if (!AUTH_METHODS.includes(vaultMethod)) {
}
if (!_methods.includes(vaultMethod)) {
throw Error(`Sorry, the authentication method ${vaultMethod} is not currently supported.`); throw Error(`Sorry, the authentication method ${vaultMethod} is not currently supported.`);
} }
let vaultToken = null;
switch (vaultMethod) { switch (vaultMethod) {
case 'approle': case 'approle':
const vaultRoleId = core.getInput('roleId', { required: false });
const vaultSecretId = core.getInput('secretId', { required: false });
core.debug('Try to retrieve Vault Token from approle'); core.debug('Try to retrieve Vault Token from approle');
var options = { var options = {
headers: {}, headers: {},
@ -4109,9 +4104,7 @@ async function exportSecrets() {
} }
break; break;
default: default:
if (!vaultToken) { vaultToken = core.getInput('token', { required: true });
throw Error(`No token was provided. You must provided a valid vault token if using token authentication.`);
}
break; break;
} }