Files
threshold-ui/ui/admin/tests/e2e/helpers/boundary-cli/connect.mjs
T
Michael Li 007f5d8b46 refact(e2e): Split up boundary-cli helper methods (#2430)
* refact(e2e): Split up boundary-cli helper methods

* CR: Use ESM import

* CR: Move authenticated state to a non-shared file

* CR: Use mjs

* CR: Modify playwright config to .mjs
2024-08-19 16:00:16 -04: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;
}