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:
parent
42a9c06aa7
commit
3872511436
2 changed files with 14 additions and 28 deletions
21
action.js
21
action.js
|
|
@ -2,30 +2,25 @@ const core = require('@actions/core');
|
|||
const command = require('@actions/core/lib/command');
|
||||
const got = require('got');
|
||||
|
||||
const AUTH_METHODS = ['approle', 'token'];
|
||||
async function exportSecrets() {
|
||||
const _methods = ['approle', 'token'];
|
||||
|
||||
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 });
|
||||
|
||||
let vaultMethod = core.getInput('method', { required: false });
|
||||
let vaultToken = core.getInput('token', { required: false });
|
||||
|
||||
const secretsInput = core.getInput('secrets', { required: true });
|
||||
const secrets = parseSecretsInput(secretsInput);
|
||||
|
||||
if (!vaultMethod) {
|
||||
vaultMethod = 'token';
|
||||
}
|
||||
|
||||
if (!_methods.includes(vaultMethod)) {
|
||||
const vaultMethod = core.getInput('method', { required: false }) || 'token';
|
||||
if (!AUTH_METHODS.includes(vaultMethod)) {
|
||||
throw Error(`Sorry, the authentication method ${vaultMethod} is not currently supported.`);
|
||||
}
|
||||
|
||||
let vaultToken = null;
|
||||
switch (vaultMethod) {
|
||||
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');
|
||||
var options = {
|
||||
headers: {},
|
||||
|
|
@ -46,9 +41,7 @@ async function exportSecrets() {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
if (!vaultToken) {
|
||||
throw Error(`No token was provided. You must provided a valid vault token if using token authentication.`);
|
||||
}
|
||||
vaultToken = core.getInput('token', { required: true });
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
21
dist/index.js
vendored
21
dist/index.js
vendored
|
|
@ -4065,30 +4065,25 @@ const core = __webpack_require__(470);
|
|||
const command = __webpack_require__(431);
|
||||
const got = __webpack_require__(77);
|
||||
|
||||
const AUTH_METHODS = ['approle', 'token'];
|
||||
async function exportSecrets() {
|
||||
const _methods = ['approle', 'token'];
|
||||
|
||||
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 });
|
||||
|
||||
let vaultMethod = core.getInput('method', { required: false });
|
||||
let vaultToken = core.getInput('token', { required: false });
|
||||
|
||||
const secretsInput = core.getInput('secrets', { required: true });
|
||||
const secrets = parseSecretsInput(secretsInput);
|
||||
|
||||
if (!vaultMethod) {
|
||||
vaultMethod = 'token';
|
||||
}
|
||||
|
||||
if (!_methods.includes(vaultMethod)) {
|
||||
const vaultMethod = core.getInput('method', { required: false }) || 'token';
|
||||
if (!AUTH_METHODS.includes(vaultMethod)) {
|
||||
throw Error(`Sorry, the authentication method ${vaultMethod} is not currently supported.`);
|
||||
}
|
||||
|
||||
let vaultToken = null;
|
||||
switch (vaultMethod) {
|
||||
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');
|
||||
var options = {
|
||||
headers: {},
|
||||
|
|
@ -4109,9 +4104,7 @@ async function exportSecrets() {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
if (!vaultToken) {
|
||||
throw Error(`No token was provided. You must provided a valid vault token if using token authentication.`);
|
||||
}
|
||||
vaultToken = core.getInput('token', { required: true });
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue