mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-06 06:37:02 +02:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
/* eslint-env node */
|
|
/* eslint-disable no-console */
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const chalk = require('chalk');
|
|
const execa = require('execa');
|
|
|
|
/**
|
|
* Writes a vault keys file that can be imported in other scripts, that includes the unseal keys and the root token.
|
|
* @param unsealKeys an array of unseal keys, must contain at least one key
|
|
* @param rootToken the root token
|
|
* @param filePath optional file path, if not provided the default path of <cwd>/tests/helpers/vault-keys.js
|
|
* will be used.
|
|
*/
|
|
function writeKeysFile(unsealKeys, rootToken, filePath) {
|
|
if (filePath === undefined) {
|
|
filePath = path.join(process.cwd(), 'tests/helpers/vault-keys.js');
|
|
}
|
|
const keys = {};
|
|
keys.unsealKeys = unsealKeys;
|
|
keys.rootToken = rootToken;
|
|
|
|
fs.writeFile(filePath, `export default ${JSON.stringify(keys, null, 2)}`, (err) => {
|
|
if (err) throw err;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Runs the provided command and pipes the processes stdout and stderr to the terminal. Upon completion with
|
|
* success or error the child process will be cleaned up.
|
|
* @param command some command to run
|
|
* @param args some arguments for the command to run
|
|
* @param shareStd if true the sub process created by the command will share the stdout and stderr of the parent
|
|
* process
|
|
* @returns {*} The child_process for the executed command which is also a Promise.
|
|
*/
|
|
function run(command, args = [], shareStd = true) {
|
|
console.log(chalk.dim('$ ' + command + ' ' + args.join(' ')));
|
|
// cleanup means that execa will handle stopping the subprocess
|
|
// inherit all of the stdin/out/err so that testem still works as if you were running it directly
|
|
if (shareStd) {
|
|
return execa(command, args, { cleanup: true, stdin: 'inherit', stdout: 'inherit', stderr: 'inherit' });
|
|
}
|
|
const p = execa(command, args, { cleanup: true });
|
|
p.stdout.pipe(process.stdout);
|
|
p.stderr.pipe(process.stderr);
|
|
return p;
|
|
}
|
|
|
|
module.exports = {
|
|
writeKeysFile: writeKeysFile,
|
|
run: run,
|
|
};
|