2021-01-29 17:55:55 -05:00
|
|
|
const path = require('path');
|
2021-02-02 12:03:50 -05:00
|
|
|
const { spawnAsyncJSONPromise, spawnSync } = require('./spawn-promise');
|
2020-12-10 16:41:26 -05:00
|
|
|
|
2021-02-01 12:35:02 -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
|
2020-12-15 17:23:02 -05:00
|
|
|
connect: (target_id, token, addr) => {
|
2020-12-10 16:41:26 -05:00
|
|
|
const command = [
|
|
|
|
|
'connect',
|
|
|
|
|
`-target-id=${target_id}`,
|
|
|
|
|
`-token=${token}`,
|
2020-12-15 17:23:02 -05:00
|
|
|
`-addr=${addr}`,
|
2020-12-10 16:41:26 -05:00
|
|
|
'-format=json',
|
|
|
|
|
'--output-json-errors'
|
2021-01-29 17:55:55 -05:00
|
|
|
];
|
2021-02-02 11:12:55 -05:00
|
|
|
return spawnAsyncJSONPromise(command);
|
2021-02-02 12:03:50 -05:00
|
|
|
},
|
|
|
|
|
// 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}`
|
2021-02-02 12:03:50 -05:00
|
|
|
: `CLI Git Rev ${gitRevision}`;
|
|
|
|
|
return { gitRevision, versionNumber, formatted };
|
|
|
|
|
return rawOutput;
|
2020-12-10 16:41:26 -05:00
|
|
|
}
|
2020-12-15 17:23:02 -05:00
|
|
|
}
|