Files
threshold-ui/e2e-tests/helpers/boundary-cli/connect.js
T
Zhihe Li 7c1814118d refactor: 💡 Move e2e tests to new folder (#2546)
* refactor: 💡 Move e2e tests to new folder

* refactor: 💡 Convert desktop tests to mjs and use es6 imports

* refactor: 💡 Use module setting for e2e directory and remove mjs

* refactor: 💡 Remove "e2e" in all scripts in package.json
2024-11-12 11:21:37 -05:00

58 lines
1.7 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import { exec } from 'node:child_process';
/**
* Connects to the specified target
* exec is used here to keep the session open
* @param {string} targetId ID of the target to be connected to
* @param {string} sshUser User to be used for the ssh connection
* @param {string} sshKeyPath Path to the ssh key to be used for the ssh connection
* @returns ChildProcess representing the result of the command execution
*/
export async function connectToTarget(targetId, sshUser, sshKeyPath) {
let connect;
try {
connect = exec(
`boundary connect -target-id=${targetId}` +
' -exec /usr/bin/ssh --' +
` -l ${sshUser}` +
` -i ${sshKeyPath}` +
' -o UserKnownHostsFile=/dev/null' +
' -o StrictHostKeyChecking=no' +
' -o IdentitiesOnly=yes' + // forces the use of the provided key
' -p {{boundary.port}}' +
' {{boundary.ip}}',
);
} catch (e) {
console.log(`${e.stderr}`);
}
return connect;
}
/**
* Connects via ssh to the specified target
* exec is used here to keep the session open
* @param {string} targetId ID of the target to be connected to
* @returns ChildProcess representing the result of the command execution
*/
export async function connectSshToTarget(targetId) {
let connect;
try {
connect = exec(
'boundary connect ssh' +
` -target-id=${targetId}` +
' --' +
' -o UserKnownHostsFile=/dev/null' +
' -o StrictHostKeyChecking=no' +
' -o IdentitiesOnly=yes', // forces the use of the provided key
);
} catch (e) {
console.log(`${e.stderr}`);
}
return connect;
}