Files
threshold-ui/e2e-tests/helpers/vault-cli.js
T

52 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { execSync } from 'node:child_process';
/**
* Checks that the vault cli is available
*/
export async function checkVaultCli() {
try {
execSync('which vault');
} catch (e) {
throw new Error('vault does not exist on the path');
}
}
/**
* Generates a vault token to be used to integrate with Boundary
* @param {string} boundaryPolicyName Name of the boundary policy that's used to create vault token.
* @param {string} secretPolicyName Name of the secret policy that's used to create vault token.
* @returns {Promise<string>} Vault Token
*/
export async function getVaultToken(boundaryPolicyName, secretPolicyName) {
let clientToken;
try {
execSync(
2024-11-12 11:21:37 -05:00
`vault policy write ${boundaryPolicyName} ./admin/tests/fixtures/boundary-controller-policy.hcl`,
);
execSync(
2024-11-12 11:21:37 -05:00
`vault policy write ${secretPolicyName} ./admin/tests/fixtures/kv-policy.hcl`,
);
const vaultToken = JSON.parse(
execSync(
`vault token create \
-no-default-policy=true \
-policy=${boundaryPolicyName} \
-policy=${secretPolicyName} \
-orphan=true \
-period=20m \
-renewable=true \
-format=json`,
),
);
clientToken = vaultToken.auth.client_token;
} catch (e) {
console.log(`${e.stderr}`);
}
return clientToken;
}