ssh-client-wrapper 3.4.5 → 3.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +1 -1
- package/lib/sshError.js +9 -7
- package/lib/sshExec.js +2 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
package/lib/sshError.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { stripTerminalSequences } from "./util.js";
|
|
2
2
|
|
|
3
3
|
const MAX_OUTPUT = 4096;
|
|
4
|
+
const OK_PREFIX = "SCWOK";
|
|
4
5
|
const FAIL_PREFIX = "SCWFAIL";
|
|
5
6
|
|
|
6
7
|
//messages of ssh after which there is nothing to wait for. The first match wins.
|
|
@@ -56,18 +57,19 @@ export const makeSshError = (output, hostInfo)=>{
|
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
* make the command line which is typed into the shell of the master pty
|
|
59
|
-
* the
|
|
60
|
-
* so that the line which the terminal echoes back
|
|
61
|
-
* "||" is understood by sh, bash, zsh, fish and csh.
|
|
60
|
+
* the remote host echoes okMark if the login succeeds, and the shell prints failMark only if ssh fails.
|
|
61
|
+
* Both marks are written with "" in them, so that the line which the terminal echoes back (in one or more pieces)
|
|
62
|
+
* does not contain them. "||" is understood by sh, bash, zsh, fish and csh.
|
|
62
63
|
* @param {string} cmd - ssh command
|
|
63
64
|
* @param {Array} args - arguments of ssh
|
|
64
|
-
* @param {string} words - string which
|
|
65
|
-
* @param {string} failId - string which makes
|
|
66
|
-
* @returns {object} - { line: command line,
|
|
65
|
+
* @param {string} words - string which makes okMark unique
|
|
66
|
+
* @param {string} failId - string which makes failMark unique. It must differ from words
|
|
67
|
+
* @returns {object} - { line: command line, okMark: string which tells success, failMark: string which tells failure }
|
|
67
68
|
*/
|
|
68
69
|
export const makeMasterCommand = (cmd, args, words, failId)=>{
|
|
69
70
|
return {
|
|
70
|
-
line: `${cmd} ${args.join(" ")} echo ${words} || echo ${FAIL_PREFIX}""-${failId}\n`,
|
|
71
|
+
line: `${cmd} ${args.join(" ")} echo ${OK_PREFIX}""-${words} || echo ${FAIL_PREFIX}""-${failId}\n`,
|
|
72
|
+
okMark: `${OK_PREFIX}-${words}`,
|
|
71
73
|
failMark: `${FAIL_PREFIX}-${failId}`
|
|
72
74
|
};
|
|
73
75
|
};
|
package/lib/sshExec.js
CHANGED
|
@@ -237,9 +237,7 @@ export async function connect(hostInfo, timeout = 60) {
|
|
|
237
237
|
let over = false;
|
|
238
238
|
|
|
239
239
|
debug(`create master ssh session to ${hostInfo.host}`);
|
|
240
|
-
const
|
|
241
|
-
const re = new RegExp(`^${words}`);
|
|
242
|
-
const { line, failMark } = makeMasterCommand(sshCmd, getSshOption(hostInfo), words, crypto.randomUUID());
|
|
240
|
+
const { line, okMark, failMark } = makeMasterCommand(sshCmd, getSshOption(hostInfo), crypto.randomUUID(), crypto.randomUUID());
|
|
243
241
|
|
|
244
242
|
let ac = null;
|
|
245
243
|
let output = "";
|
|
@@ -264,7 +262,7 @@ export async function connect(hostInfo, timeout = 60) {
|
|
|
264
262
|
output = `${output}${chunk}`.slice(-65536);
|
|
265
263
|
debugVerbose(chunk);
|
|
266
264
|
|
|
267
|
-
if (
|
|
265
|
+
if (output.includes(okMark)) {
|
|
268
266
|
debug("test done. call exit on remotehost");
|
|
269
267
|
done = true;
|
|
270
268
|
resolve();
|