You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.2 KiB
50 lines
1.2 KiB
import isUndefined from 'lodash/isUndefined.js';
|
|
import { logger } from '../../shared/logger.js';
|
|
|
|
export function sshOptions(
|
|
{
|
|
pass,
|
|
path,
|
|
command,
|
|
host,
|
|
port,
|
|
auth,
|
|
knownhosts,
|
|
}: { [s: string]: string },
|
|
key?: string,
|
|
): string[] {
|
|
const cmd = parseCommand(command, path);
|
|
const hostChecking = knownhosts !== '/dev/null' ? 'yes' : 'no';
|
|
const sshRemoteOptsBase = [
|
|
'ssh',
|
|
host,
|
|
'-t',
|
|
'-p',
|
|
port,
|
|
'-o',
|
|
`PreferredAuthentications=${auth}`,
|
|
'-o',
|
|
`UserKnownHostsFile=${knownhosts}`,
|
|
'-o',
|
|
`StrictHostKeyChecking=${hostChecking}`,
|
|
];
|
|
logger.info(`Authentication Type: ${auth}`);
|
|
if (!isUndefined(key)) {
|
|
return sshRemoteOptsBase.concat(['-i', key, cmd]);
|
|
}
|
|
if (pass !== '') {
|
|
return ['sshpass', '-p', pass].concat(sshRemoteOptsBase, [cmd]);
|
|
}
|
|
if (auth === 'none') {
|
|
sshRemoteOptsBase.splice(sshRemoteOptsBase.indexOf('-o'), 2);
|
|
}
|
|
|
|
return cmd === '' ? sshRemoteOptsBase : sshRemoteOptsBase.concat([cmd]);
|
|
}
|
|
|
|
function parseCommand(command: string, path?: string): string {
|
|
if (command === 'login' && isUndefined(path)) return '';
|
|
return !isUndefined(path)
|
|
? `$SHELL -c "cd ${path};${command === 'login' ? '$SHELL' : command}"`
|
|
: command;
|
|
}
|
|
|