Files
threshold-ui/ui/desktop/electron-app/src/boundary-cli.js
T

35 lines
1.2 KiB
JavaScript
Raw Normal View History

const path = require('path');
const { spawnAsyncJSONPromise, spawnSync } = require('./spawn-promise');
2020-12-10 16:41:26 -05:00
const cliPath = async () => path.resolve(__dirname, '..', 'cli', 'boundary');
2020-12-10 16:41:26 -05:00
module.exports = {
// Check boundary cli existence
exists: () => Boolean(cliPath()),
// Initiate connection and return output
connect: (target_id, token, addr) => {
2020-12-10 16:41:26 -05:00
const command = [
'connect',
`-target-id=${target_id}`,
`-token=${token}`,
`-addr=${addr}`,
2020-12-10 16:41:26 -05:00
'-format=json',
'--output-json-errors'
];
return spawnAsyncJSONPromise(command);
},
// Returns JSON-formatted version information from the CLI
version: () => {
const command = [ '-v' ];
const rawOutput = spawnSync(command);
let gitRevision = /Git Revision:\s*(?<rev>.*)\n/.exec(rawOutput);
let versionNumber = /Version Number:\s*(?<ver>.*)\n/.exec(rawOutput);
if (gitRevision) gitRevision = gitRevision.groups.rev;
if (versionNumber) versionNumber = versionNumber.groups.ver;
const formatted = versionNumber
2021-02-02 12:05:34 -05:00
? `CLI Version ${versionNumber}; CLI Git Rev ${gitRevision}`
: `CLI Git Rev ${gitRevision}`;
return { gitRevision, versionNumber, formatted };
return rawOutput;
2020-12-10 16:41:26 -05:00
}
}