2018-04-03 14:16:57 +00:00
|
|
|
#!/usr/bin/env node
|
2018-09-25 16:28:26 +00:00
|
|
|
/* eslint-disable */
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
if (process.argv[2]) {
|
2018-04-03 14:16:57 +00:00
|
|
|
process.kill(process.argv[2], 'SIGINT');
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
|
2018-04-16 22:18:46 +00:00
|
|
|
process.env.TERM = 'dumb';
|
2018-04-03 14:16:57 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
2018-09-25 16:28:26 +00:00
|
|
|
var readline = require('readline');
|
2018-04-03 14:16:57 +00:00
|
|
|
var spawn = require('child_process').spawn;
|
2018-09-25 16:28:26 +00:00
|
|
|
var vault = spawn('vault', [
|
|
|
|
'server',
|
|
|
|
'-dev',
|
|
|
|
'-dev-ha',
|
|
|
|
'-dev-transactional',
|
|
|
|
'-dev-root-token-id=root',
|
|
|
|
'-dev-listen-address=127.0.0.1:9200',
|
|
|
|
]);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
var output = '';
|
|
|
|
var unseal, root;
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
readline
|
|
|
|
.createInterface({
|
|
|
|
input: vault.stdout,
|
|
|
|
terminal: false,
|
|
|
|
})
|
|
|
|
.on('line', function(line) {
|
|
|
|
output = output + line;
|
|
|
|
console.log(line);
|
|
|
|
var unsealMatch = output.match(/Unseal Key: (.+)$/m);
|
|
|
|
if (unsealMatch && !unseal) {
|
|
|
|
unseal = unsealMatch[1];
|
|
|
|
}
|
|
|
|
var rootMatch = output.match(/Root Token: (.+)$/m);
|
|
|
|
if (rootMatch && !root) {
|
|
|
|
root = rootMatch[1];
|
|
|
|
}
|
|
|
|
if (root && unseal) {
|
|
|
|
fs.writeFile(
|
|
|
|
path.join(process.cwd(), 'tests/helpers/vault-keys.js'),
|
2018-11-05 16:56:59 +00:00
|
|
|
`export default ${JSON.stringify({ unseal, root }, null, 2)}`
|
2018-09-25 16:28:26 +00:00
|
|
|
);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
console.log('VAULT SERVER READY');
|
|
|
|
}
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
vault.stderr.on('data', function(data) {
|
|
|
|
console.log(data.toString());
|
|
|
|
});
|
|
|
|
|
|
|
|
vault.on('close', function(code) {
|
|
|
|
console.log(`child process exited with code ${code}`);
|
|
|
|
process.exit();
|
|
|
|
});
|
|
|
|
vault.on('error', function(error) {
|
|
|
|
console.log(`child process errored: ${error}`);
|
|
|
|
process.exit();
|
|
|
|
});
|
|
|
|
|
|
|
|
var pidFile = 'vault-ui-integration-server.pid';
|
|
|
|
process.on('SIGINT', function() {
|
|
|
|
vault.kill('SIGINT');
|
|
|
|
process.exit();
|
|
|
|
});
|
|
|
|
process.on('exit', function() {
|
|
|
|
vault.kill('SIGINT');
|
|
|
|
});
|
|
|
|
|
2019-02-13 14:34:38 +00:00
|
|
|
fs.writeFile(pidFile, process.pid, (err) => {
|
|
|
|
if (err) throw err;
|
|
|
|
console.log('The file has been saved!');
|
|
|
|
});
|