ssh-client-wrapper 2.2.4 → 2.2.7
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/fork.js +12 -12
- package/lib/index.js +11 -12
- package/lib/rsyncExec.js +9 -9
- package/lib/sshExec.js +23 -23
- package/lib/util.js +18 -18
- package/package.json +1 -2
- package/test/interface.js +48 -49
- package/test/rsyncExec.js +72 -73
- package/test/sshExec.js +40 -40
- package/test/testUtil/testFiles.js +7 -8
- package/test/util.js +12 -13
package/lib/fork.js
CHANGED
|
@@ -11,8 +11,8 @@ const nodePtyOpt = {
|
|
|
11
11
|
windowsHide: true
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
function sshLoginCallback(output, ptyProcess, pw, ph, logger = debugSendPty) {
|
|
15
|
-
return new Promise((resolve, reject)=>{
|
|
14
|
+
function sshLoginCallback (output, ptyProcess, pw, ph, logger = debugSendPty) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
16
|
if (reNewHostPrompt.test(output)) {
|
|
17
17
|
sendPty(ptyProcess, "yes\n", logger, 17);
|
|
18
18
|
resolve();
|
|
@@ -26,10 +26,10 @@ function sshLoginCallback(output, ptyProcess, pw, ph, logger = debugSendPty) {
|
|
|
26
26
|
if (typeof pw === "function") {
|
|
27
27
|
debug("call password callback function");
|
|
28
28
|
pw()
|
|
29
|
-
.then((v)=>{
|
|
29
|
+
.then((v) => {
|
|
30
30
|
sendPty(ptyProcess, `${v}\n`, logger, 30);
|
|
31
31
|
})
|
|
32
|
-
.catch((e)=>{
|
|
32
|
+
.catch((e) => {
|
|
33
33
|
reject(e);
|
|
34
34
|
});
|
|
35
35
|
resolve();
|
|
@@ -44,10 +44,10 @@ function sshLoginCallback(output, ptyProcess, pw, ph, logger = debugSendPty) {
|
|
|
44
44
|
if (typeof ph === "function") {
|
|
45
45
|
debug("call passphrase callback function");
|
|
46
46
|
ph()
|
|
47
|
-
.then((v)=>{
|
|
47
|
+
.then((v) => {
|
|
48
48
|
sendPty(ptyProcess, `${v}\n`, logger, 45);
|
|
49
49
|
})
|
|
50
|
-
.catch((e)=>{
|
|
50
|
+
.catch((e) => {
|
|
51
51
|
reject(e);
|
|
52
52
|
});
|
|
53
53
|
}
|
|
@@ -58,7 +58,7 @@ function sshLoginCallback(output, ptyProcess, pw, ph, logger = debugSendPty) {
|
|
|
58
58
|
/**
|
|
59
59
|
* create pty for master ssh session and store to hostInfo.masterPty
|
|
60
60
|
*/
|
|
61
|
-
function createMasterPty(hostInfo) {
|
|
61
|
+
function createMasterPty (hostInfo) {
|
|
62
62
|
debug("fork pty for master connection");
|
|
63
63
|
|
|
64
64
|
if (hostInfo.masterPty) {
|
|
@@ -69,13 +69,13 @@ function createMasterPty(hostInfo) {
|
|
|
69
69
|
hostInfo.masterPty = ptyProcess;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
async function fork(hostInfo, cmd, args, timeout, outputCallback) {
|
|
73
|
-
return new Promise((resolve, reject)=>{
|
|
72
|
+
async function fork (hostInfo, cmd, args, timeout, outputCallback) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
74
|
debug(`cmd=${cmd}: args=${args}`);
|
|
75
75
|
const ptyProcess = spawn(cmd, args, nodePtyOpt);
|
|
76
76
|
let ac = null;
|
|
77
77
|
if (timeout > 0) {
|
|
78
|
-
ac = watchDogTimer(timeout, cmd, ()=>{
|
|
78
|
+
ac = watchDogTimer(timeout, cmd, () => {
|
|
79
79
|
ptyProcess.kill();
|
|
80
80
|
const err = new Error(`watchdog timer expired ${timeout}`);
|
|
81
81
|
err.code = "TIMEEXPIRE";
|
|
@@ -85,7 +85,7 @@ async function fork(hostInfo, cmd, args, timeout, outputCallback) {
|
|
|
85
85
|
ptyProcess.onData(buff2String.bind(null, debugVerbose));
|
|
86
86
|
|
|
87
87
|
if (hostInfo !== null) {
|
|
88
|
-
ptyProcess.onData(async (data)=>{
|
|
88
|
+
ptyProcess.onData(async (data) => {
|
|
89
89
|
const output = data.toString();
|
|
90
90
|
sshLoginCallback(output, ptyProcess, hostInfo.password, hostInfo.passphrase)
|
|
91
91
|
.catch(reject);
|
|
@@ -102,7 +102,7 @@ async function fork(hostInfo, cmd, args, timeout, outputCallback) {
|
|
|
102
102
|
if (typeof outputCallback === "function") {
|
|
103
103
|
ptyProcess.onData(buff2String.bind(null, outputCallback));
|
|
104
104
|
}
|
|
105
|
-
ptyProcess.onExit(({ exitCode, signal })=>{
|
|
105
|
+
ptyProcess.onExit(({ exitCode, signal }) => {
|
|
106
106
|
debug("onExit", exitCode, signal);
|
|
107
107
|
|
|
108
108
|
if (ac !== null) {
|
package/lib/index.js
CHANGED
|
@@ -32,7 +32,7 @@ const { isArrayOfString, sanityCheck } = require("./util.js");
|
|
|
32
32
|
* @param {string[]} hostInfo.sshOpt - additional options for ssh
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
|
-
const logAndReject = (message)=>{
|
|
35
|
+
const logAndReject = (message) => {
|
|
36
36
|
debug(message);
|
|
37
37
|
return Promise.reject(new Error(message));
|
|
38
38
|
};
|
|
@@ -42,11 +42,11 @@ const logAndReject = (message)=>{
|
|
|
42
42
|
* @constructor
|
|
43
43
|
*/
|
|
44
44
|
class SshClientWrapper {
|
|
45
|
-
constructor(hostInfo) {
|
|
45
|
+
constructor (hostInfo) {
|
|
46
46
|
debug("constructor called for", hostInfo.host);
|
|
47
47
|
debugVerbose("hostInfo=", hostInfo);
|
|
48
|
-
sanityCheck(hostInfo);
|
|
49
48
|
this.hostInfo = { ...hostInfo };
|
|
49
|
+
sanityCheck(this.hostInfo);
|
|
50
50
|
this.hostInfo.masterPty = null;
|
|
51
51
|
this.hostInfo.rsyncVersion = null;
|
|
52
52
|
|
|
@@ -68,7 +68,7 @@ class SshClientWrapper {
|
|
|
68
68
|
* @param { Function } outputCallback - call back routine for output
|
|
69
69
|
* @returns {Integer} - Return code of cmd.
|
|
70
70
|
*/
|
|
71
|
-
async exec(cmd, timeout = 0, outputCallback = null) {
|
|
71
|
+
async exec (cmd, timeout = 0, outputCallback = null) {
|
|
72
72
|
debug("exec called", cmd);
|
|
73
73
|
|
|
74
74
|
if (typeof cmd !== "string" || cmd === "") {
|
|
@@ -77,7 +77,6 @@ class SshClientWrapper {
|
|
|
77
77
|
return sshExec(this.hostInfo, cmd, timeout, outputCallback);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
81
80
|
/**
|
|
82
81
|
* execute ls command and return output
|
|
83
82
|
* @param {string} target - file or directory path to watch
|
|
@@ -85,7 +84,7 @@ class SshClientWrapper {
|
|
|
85
84
|
* @param {Integer} timeout - timeout in secconds
|
|
86
85
|
* @returns {string[]} - output from ls
|
|
87
86
|
*/
|
|
88
|
-
async ls(target, lsOpt = [], timeout = 0) {
|
|
87
|
+
async ls (target, lsOpt = [], timeout = 0) {
|
|
89
88
|
debug("ls called", target, lsOpt);
|
|
90
89
|
return ls(this.hostInfo, target, lsOpt, timeout);
|
|
91
90
|
}
|
|
@@ -98,13 +97,13 @@ class SshClientWrapper {
|
|
|
98
97
|
* @param {Integer} timeout - timeout in secconds
|
|
99
98
|
* @returns {Promise} - Resolved with undefined when file transfer is done.
|
|
100
99
|
*/
|
|
101
|
-
async send(src, dst, opt = [], timeout = 0) {
|
|
100
|
+
async send (src, dst, opt = [], timeout = 0) {
|
|
102
101
|
debug("send called", src, dst, opt);
|
|
103
102
|
|
|
104
103
|
if (!isArrayOfString(src)) {
|
|
105
104
|
return logAndReject("src must be array of string");
|
|
106
105
|
}
|
|
107
|
-
if (!src.some((e)=>{
|
|
106
|
+
if (!src.some((e) => {
|
|
108
107
|
return e !== "";
|
|
109
108
|
})) {
|
|
110
109
|
return logAndReject("src must contain non-empty string");
|
|
@@ -129,13 +128,13 @@ class SshClientWrapper {
|
|
|
129
128
|
* @param {Integer} timeout - timeout in secconds
|
|
130
129
|
* @returns {Promise} - Resolved with undefined when file transfer is done.
|
|
131
130
|
*/
|
|
132
|
-
async recv(src, dst, opt = [], timeout = 0) {
|
|
131
|
+
async recv (src, dst, opt = [], timeout = 0) {
|
|
133
132
|
debug("recv called", src, dst, opt);
|
|
134
133
|
|
|
135
134
|
if (!isArrayOfString(src)) {
|
|
136
135
|
return logAndReject("src must be array of string");
|
|
137
136
|
}
|
|
138
|
-
if (!src.some((e)=>{
|
|
137
|
+
if (!src.some((e) => {
|
|
139
138
|
return e !== "";
|
|
140
139
|
})) {
|
|
141
140
|
return logAndReject("src must contain non-empty string");
|
|
@@ -157,7 +156,7 @@ class SshClientWrapper {
|
|
|
157
156
|
* @param {Integer} timeout - timeout in secconds
|
|
158
157
|
* @returns {Promise} - Resolved with true on success, otherwise rejected with Error.
|
|
159
158
|
*/
|
|
160
|
-
async canConnect(timeout = 60) {
|
|
159
|
+
async canConnect (timeout = 60) {
|
|
161
160
|
debug("canConnect called with timeout=", timeout);
|
|
162
161
|
debugVerbose("hostInfo=", this.hostInfo);
|
|
163
162
|
|
|
@@ -170,7 +169,7 @@ class SshClientWrapper {
|
|
|
170
169
|
/**
|
|
171
170
|
* Disconnect master session
|
|
172
171
|
*/
|
|
173
|
-
async disconnect() {
|
|
172
|
+
async disconnect () {
|
|
174
173
|
debug(`disconnect from ${this.hostInfo.host} called`);
|
|
175
174
|
disconnect(this.hostInfo);
|
|
176
175
|
}
|
package/lib/rsyncExec.js
CHANGED
|
@@ -9,9 +9,9 @@ const { fork } = require("./fork.js");
|
|
|
9
9
|
|
|
10
10
|
const { sshCmd, rsyncCmd, getSshOption } = require("./util.js");
|
|
11
11
|
|
|
12
|
-
async function checkRsyncVersion(timeout) {
|
|
12
|
+
async function checkRsyncVersion (timeout) {
|
|
13
13
|
const rt = {};
|
|
14
|
-
await fork(null, rsyncCmd, ["--version"], timeout, (output)=>{
|
|
14
|
+
await fork(null, rsyncCmd, ["--version"], timeout, (output) => {
|
|
15
15
|
const result = /^rsync *version *(\d+)\.(\d+)\.(\d+).*$/m.exec(output);
|
|
16
16
|
|
|
17
17
|
if (result) {
|
|
@@ -33,13 +33,13 @@ async function checkRsyncVersion(timeout) {
|
|
|
33
33
|
*
|
|
34
34
|
* this function execute rsync -avv --copy-unsafe-links src rsync://[user@]host[:port]/dst
|
|
35
35
|
*/
|
|
36
|
-
async function send(hostInfo, argSrc, dst, rsyncOpt, timeout) {
|
|
36
|
+
async function send (hostInfo, argSrc, dst, rsyncOpt, timeout) {
|
|
37
37
|
await connect(hostInfo);
|
|
38
|
-
const promises = await Promise.allSettled(argSrc.map((e)=>{
|
|
38
|
+
const promises = await Promise.allSettled(argSrc.map((e) => {
|
|
39
39
|
return glob(e);
|
|
40
40
|
}));
|
|
41
41
|
const src = promises
|
|
42
|
-
.map((e, i)=>{
|
|
42
|
+
.map((e, i) => {
|
|
43
43
|
if (e.status !== "fulfilled") {
|
|
44
44
|
return null;
|
|
45
45
|
}
|
|
@@ -48,10 +48,10 @@ async function send(hostInfo, argSrc, dst, rsyncOpt, timeout) {
|
|
|
48
48
|
}
|
|
49
49
|
return e.value;
|
|
50
50
|
})
|
|
51
|
-
.filter((e)=>{
|
|
51
|
+
.filter((e) => {
|
|
52
52
|
return e !== null;
|
|
53
53
|
})
|
|
54
|
-
.flatMap((e)=>{
|
|
54
|
+
.flatMap((e) => {
|
|
55
55
|
return e;
|
|
56
56
|
});
|
|
57
57
|
|
|
@@ -87,7 +87,7 @@ async function send(hostInfo, argSrc, dst, rsyncOpt, timeout) {
|
|
|
87
87
|
* @param {Object} hostInfo - hostinfo object
|
|
88
88
|
* @returns {boolean} - rsync command version is higher than 3.2.4 or not
|
|
89
89
|
*/
|
|
90
|
-
async function isNewRsync(hostInfo) {
|
|
90
|
+
async function isNewRsync (hostInfo) {
|
|
91
91
|
if (!hostInfo.rsyncVersion ||
|
|
92
92
|
!Number.isInteger(hostInfo.rsyncVersion.major) ||
|
|
93
93
|
!Number.isInteger(hostInfo.rsyncVersion.minor) ||
|
|
@@ -107,7 +107,7 @@ async function isNewRsync(hostInfo) {
|
|
|
107
107
|
*
|
|
108
108
|
* this function execute rsync -av --copy-unsafe-links rsync://[user@]host[:port]/src dst
|
|
109
109
|
*/
|
|
110
|
-
async function recv(hostInfo, argSrc, dst, rsyncOpt, timeout) {
|
|
110
|
+
async function recv (hostInfo, argSrc, dst, rsyncOpt, timeout) {
|
|
111
111
|
await connect(hostInfo);
|
|
112
112
|
const src = `${hostInfo.host}:${argSrc.join(" ")}`;
|
|
113
113
|
const sshArgs = getSshOption(hostInfo, true);
|
package/lib/sshExec.js
CHANGED
|
@@ -14,7 +14,7 @@ const { fork, createMasterPty, sshLoginCallback } = require("./fork.js");
|
|
|
14
14
|
* @param {number} timeout - timeout (in sec.)
|
|
15
15
|
* @param {Function} outputCallback - Callback routine for stdout and stderr.
|
|
16
16
|
*/
|
|
17
|
-
async function sshExec(hostInfo, cmd, timeout, outputCallback) {
|
|
17
|
+
async function sshExec (hostInfo, cmd, timeout, outputCallback) {
|
|
18
18
|
debug("sshExec called");
|
|
19
19
|
await connect(hostInfo);
|
|
20
20
|
debug("exec", cmd, "on remote server");
|
|
@@ -46,14 +46,14 @@ async function sshExec(hostInfo, cmd, timeout, outputCallback) {
|
|
|
46
46
|
* @param {Object} hostInfo - hostinfo object
|
|
47
47
|
* @param {Integer} timeout - timeout in secconds
|
|
48
48
|
*/
|
|
49
|
-
async function canConnect(hostInfo, timeout = 60) {
|
|
49
|
+
async function canConnect (hostInfo, timeout = 60) {
|
|
50
50
|
debug("canConnect called");
|
|
51
51
|
sanityCheck(hostInfo);
|
|
52
52
|
|
|
53
53
|
await connect(hostInfo, timeout);
|
|
54
54
|
await disconnect(hostInfo);
|
|
55
|
-
//if connection fail, Error is throwed.
|
|
56
|
-
//so, if we reach here, connection must be succeeded
|
|
55
|
+
// if connection fail, Error is throwed.
|
|
56
|
+
// so, if we reach here, connection must be succeeded
|
|
57
57
|
return true;
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -62,13 +62,13 @@ async function canConnect(hostInfo, timeout = 60) {
|
|
|
62
62
|
* @param {Object} hostInfo - hostinfo object
|
|
63
63
|
* @returns {boolean} - true if master session exists
|
|
64
64
|
*/
|
|
65
|
-
async function existsMaster(hostInfo, argTimeout) {
|
|
65
|
+
async function existsMaster (hostInfo, argTimeout) {
|
|
66
66
|
debugVerbose("existsMaster called");
|
|
67
67
|
const args = getSshOption(hostInfo);
|
|
68
68
|
args.push("-Ocheck");
|
|
69
69
|
|
|
70
70
|
let output = "";
|
|
71
|
-
const cb = (e)=>{
|
|
71
|
+
const cb = (e) => {
|
|
72
72
|
output += e;
|
|
73
73
|
};
|
|
74
74
|
|
|
@@ -94,7 +94,7 @@ async function existsMaster(hostInfo, argTimeout) {
|
|
|
94
94
|
* create master ssh connection
|
|
95
95
|
* @param {Object} hostInfo - hostinfo object
|
|
96
96
|
*/
|
|
97
|
-
async function connect(hostInfo, timeout = 60) {
|
|
97
|
+
async function connect (hostInfo, timeout = 60) {
|
|
98
98
|
debug("connect called");
|
|
99
99
|
|
|
100
100
|
if (await existsMaster(hostInfo, timeout)) {
|
|
@@ -110,8 +110,8 @@ async function connect(hostInfo, timeout = 60) {
|
|
|
110
110
|
const re = new RegExp(`^${words}`);
|
|
111
111
|
|
|
112
112
|
let ac = null;
|
|
113
|
-
const p = new Promise((resolve, reject)=>{
|
|
114
|
-
ac = watchDogTimer(timeout, "make connection", ()=>{
|
|
113
|
+
const p = new Promise((resolve, reject) => {
|
|
114
|
+
ac = watchDogTimer(timeout, "make connection", () => {
|
|
115
115
|
sendPty(hostInfo.masterPty, "\n", debugSendMasterPty, 137);
|
|
116
116
|
sendPty(hostInfo.masterPty, "exit\n", debugSendMasterPty, 138);
|
|
117
117
|
|
|
@@ -123,9 +123,9 @@ async function connect(hostInfo, timeout = 60) {
|
|
|
123
123
|
});
|
|
124
124
|
|
|
125
125
|
let done = false;
|
|
126
|
-
hostInfo.masterPty.onData((data)=>{
|
|
126
|
+
hostInfo.masterPty.onData((data) => {
|
|
127
127
|
if (done) {
|
|
128
|
-
//safeguard
|
|
128
|
+
// safeguard
|
|
129
129
|
return;
|
|
130
130
|
}
|
|
131
131
|
const output = data.toString();
|
|
@@ -145,12 +145,12 @@ async function connect(hostInfo, timeout = 60) {
|
|
|
145
145
|
reject(new Error("Operation timed out"));
|
|
146
146
|
}
|
|
147
147
|
});
|
|
148
|
-
hostInfo.masterPty.onData((data)=>{
|
|
148
|
+
hostInfo.masterPty.onData((data) => {
|
|
149
149
|
const output = data.toString();
|
|
150
150
|
sshLoginCallback(output, hostInfo.masterPty, hostInfo.password, hostInfo.passphrase, debugSendMasterPty)
|
|
151
151
|
.catch(reject);
|
|
152
152
|
});
|
|
153
|
-
hostInfo.masterPty.onExit((e)=>{
|
|
153
|
+
hostInfo.masterPty.onExit((e) => {
|
|
154
154
|
debug("master pty exit", e);
|
|
155
155
|
resolve(e);
|
|
156
156
|
});
|
|
@@ -175,7 +175,7 @@ async function connect(hostInfo, timeout = 60) {
|
|
|
175
175
|
* remove master session
|
|
176
176
|
* @param {Object} hostInfo - hostinfo object
|
|
177
177
|
*/
|
|
178
|
-
async function disconnect(hostInfo) {
|
|
178
|
+
async function disconnect (hostInfo) {
|
|
179
179
|
debug("disconnect called");
|
|
180
180
|
|
|
181
181
|
if (await existsMaster(hostInfo)) {
|
|
@@ -183,7 +183,7 @@ async function disconnect(hostInfo) {
|
|
|
183
183
|
args.push("-Oexit");
|
|
184
184
|
|
|
185
185
|
let output = "";
|
|
186
|
-
const cb = (e)=>{
|
|
186
|
+
const cb = (e) => {
|
|
187
187
|
output += e;
|
|
188
188
|
};
|
|
189
189
|
try {
|
|
@@ -218,20 +218,21 @@ async function disconnect(hostInfo) {
|
|
|
218
218
|
* @param {number} timeout - timeout (in sec.)
|
|
219
219
|
* @returns {string[]} - output from ls
|
|
220
220
|
*/
|
|
221
|
-
async function ls(hostInfo, target, lsOpt, timeout) {
|
|
221
|
+
async function ls (hostInfo, target, lsOpt, timeout) {
|
|
222
222
|
debug("ls called");
|
|
223
223
|
const outputArray = [];
|
|
224
224
|
try {
|
|
225
|
-
await sshExec(hostInfo, `ls ${lsOpt.join(" ")} ${target}`, timeout, (data)=>{
|
|
225
|
+
await sshExec(hostInfo, `ls ${lsOpt.join(" ")} ${target}`, timeout, (data) => {
|
|
226
226
|
outputArray.push(data);
|
|
227
227
|
});
|
|
228
228
|
} catch (e) {
|
|
229
|
-
//non-zero retrun should be allowed
|
|
229
|
+
// non-zero retrun should be allowed
|
|
230
230
|
if (typeof e.rt === "undefined" || e.rt < 0) {
|
|
231
231
|
throw e;
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
-
return outputArray.length === 0
|
|
234
|
+
return outputArray.length === 0
|
|
235
|
+
? []
|
|
235
236
|
: outputArray
|
|
236
237
|
.join("\n")
|
|
237
238
|
.replace(/\n+/g, "\n")
|
|
@@ -243,13 +244,13 @@ async function ls(hostInfo, target, lsOpt, timeout) {
|
|
|
243
244
|
* retry fork() if it throw retryable error
|
|
244
245
|
* @param {Function} func - function to be wrapped
|
|
245
246
|
*/
|
|
246
|
-
async function retryWrapper(func, hostInfo) {
|
|
247
|
+
async function retryWrapper (func, hostInfo) {
|
|
247
248
|
const minTimeout = hostInfo.retryMinTimeout * 1000 || 1000;
|
|
248
249
|
const maxTimeout = hostInfo.retryMaxTimeout * 1000 || 5000;
|
|
249
250
|
const retries = hostInfo.maxRetry || 1;
|
|
250
|
-
return promiseRetry({ retries, minTimeout, maxTimeout }, (retry, number)=>{
|
|
251
|
+
return promiseRetry({ retries, minTimeout, maxTimeout }, (retry, number) => {
|
|
251
252
|
return func()
|
|
252
|
-
.catch((e)=>{
|
|
253
|
+
.catch((e) => {
|
|
253
254
|
if (e.retryable) {
|
|
254
255
|
debug(`retrying: ${number} times`);
|
|
255
256
|
disconnect(hostInfo).then(retry);
|
|
@@ -259,7 +260,6 @@ async function retryWrapper(func, hostInfo) {
|
|
|
259
260
|
});
|
|
260
261
|
}
|
|
261
262
|
|
|
262
|
-
|
|
263
263
|
module.exports = {
|
|
264
264
|
sshExec,
|
|
265
265
|
canConnect,
|
package/lib/util.js
CHANGED
|
@@ -25,7 +25,7 @@ const ajv = new Ajv({
|
|
|
25
25
|
});
|
|
26
26
|
require("ajv-keywords")(ajv, "transform");
|
|
27
27
|
|
|
28
|
-
//never validate password and passphrase value to avoid security insident
|
|
28
|
+
// never validate password and passphrase value to avoid security insident
|
|
29
29
|
const hostInfoSchema = {
|
|
30
30
|
type: "object",
|
|
31
31
|
properties: {
|
|
@@ -64,7 +64,7 @@ const validate = ajv.compile(hostInfoSchema);
|
|
|
64
64
|
* @param {Function} func - function
|
|
65
65
|
* @param {data} data - binary data which can be converted to string
|
|
66
66
|
*/
|
|
67
|
-
const buff2String = (func, data)=>{
|
|
67
|
+
const buff2String = (func, data) => {
|
|
68
68
|
func(data.toString().replace(/\r\n/g, EOL));
|
|
69
69
|
};
|
|
70
70
|
|
|
@@ -72,12 +72,12 @@ const buff2String = (func, data)=>{
|
|
|
72
72
|
* check if given hostInfo object is OK
|
|
73
73
|
* @param { Object } hostInfo - host information object defined in index.js
|
|
74
74
|
*/
|
|
75
|
-
const sanityCheck = (hostInfo)=>{
|
|
75
|
+
const sanityCheck = (hostInfo) => {
|
|
76
76
|
debug("sanityCheck called", hostInfo);
|
|
77
|
-
//keep password, passphrase, and masterPty before validate.
|
|
78
|
-
//these properties can have invalid value for JSON.
|
|
79
|
-
//ajv will remove that at validation pahse becase of additionalProperties setting
|
|
80
|
-
//so we keep them here and put back later.
|
|
77
|
+
// keep password, passphrase, and masterPty before validate.
|
|
78
|
+
// these properties can have invalid value for JSON.
|
|
79
|
+
// ajv will remove that at validation pahse becase of additionalProperties setting
|
|
80
|
+
// so we keep them here and put back later.
|
|
81
81
|
const { password, passphrase, masterPty } = hostInfo;
|
|
82
82
|
validate(hostInfo);
|
|
83
83
|
|
|
@@ -99,7 +99,7 @@ const sanityCheck = (hostInfo)=>{
|
|
|
99
99
|
}
|
|
100
100
|
if (prop.startsWith("sshOpt")) {
|
|
101
101
|
debug("remove empty member of sshOpt");
|
|
102
|
-
hostInfo.sshOpt = hostInfo.sshOpt.filter((opt)=>{
|
|
102
|
+
hostInfo.sshOpt = hostInfo.sshOpt.filter((opt) => {
|
|
103
103
|
return opt !== "";
|
|
104
104
|
});
|
|
105
105
|
continue;
|
|
@@ -123,7 +123,7 @@ const sanityCheck = (hostInfo)=>{
|
|
|
123
123
|
hostInfo.password = password;
|
|
124
124
|
}
|
|
125
125
|
if (["string", "function"].includes(typeof passphrase)) {
|
|
126
|
-
hostInfo.
|
|
126
|
+
hostInfo.passphrase = passphrase;
|
|
127
127
|
}
|
|
128
128
|
if (masterPty === null || typeof masterPty === "function") {
|
|
129
129
|
hostInfo.masterPty = masterPty;
|
|
@@ -136,7 +136,7 @@ const sanityCheck = (hostInfo)=>{
|
|
|
136
136
|
* @param { Object} hostInfo - host information object defined in index.js
|
|
137
137
|
* @param {boolean} withoutDestination - return except for hostname
|
|
138
138
|
*/
|
|
139
|
-
const getSshOption = (hostInfo, withoutDestination)=>{
|
|
139
|
+
const getSshOption = (hostInfo, withoutDestination) => {
|
|
140
140
|
debug("getSshOption called");
|
|
141
141
|
const args = [];
|
|
142
142
|
|
|
@@ -189,19 +189,19 @@ const getSshOption = (hostInfo, withoutDestination)=>{
|
|
|
189
189
|
args.push(`-oConnectTimeout=${hostInfo.ConnectTimeout}`);
|
|
190
190
|
}
|
|
191
191
|
if (Array.isArray(hostInfo.sshOpt)) {
|
|
192
|
-
args.push(...hostInfo.sshOpt.filter((e)=>{
|
|
192
|
+
args.push(...hostInfo.sshOpt.filter((e) => {
|
|
193
193
|
return typeof e === "string";
|
|
194
194
|
}));
|
|
195
195
|
}
|
|
196
196
|
return args;
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
const isArrayOfString = (target)=>{
|
|
199
|
+
const isArrayOfString = (target) => {
|
|
200
200
|
if (!Array.isArray(target)) {
|
|
201
201
|
return false;
|
|
202
202
|
}
|
|
203
|
-
return !target.some((e)=>{
|
|
204
|
-
//target has non string member
|
|
203
|
+
return !target.some((e) => {
|
|
204
|
+
// target has non string member
|
|
205
205
|
return typeof e !== "string";
|
|
206
206
|
});
|
|
207
207
|
};
|
|
@@ -213,7 +213,7 @@ const isArrayOfString = (target)=>{
|
|
|
213
213
|
* @param {Function} logger - logging function
|
|
214
214
|
* @param {string} label - where this function is called
|
|
215
215
|
*/
|
|
216
|
-
const sendPty = async (pty, message, logger, label)=>{
|
|
216
|
+
const sendPty = async (pty, message, logger, label) => {
|
|
217
217
|
logger(`${label}: ${message}`);
|
|
218
218
|
pty.write(message);
|
|
219
219
|
};
|
|
@@ -225,15 +225,15 @@ const sendPty = async (pty, message, logger, label)=>{
|
|
|
225
225
|
* @param {Function} cb - call back function which will be called after timeout
|
|
226
226
|
* @returns {AbortController} - ac to stop watch dog timer
|
|
227
227
|
*/
|
|
228
|
-
const watchDogTimer = (timeout, label, cb)=>{
|
|
228
|
+
const watchDogTimer = (timeout, label, cb) => {
|
|
229
229
|
const ac = new AbortController();
|
|
230
230
|
const signal = ac.signal;
|
|
231
231
|
setTimeoutPromise(timeout * 1000, "neverUsedValue", { signal })
|
|
232
|
-
.then(()=>{
|
|
232
|
+
.then(() => {
|
|
233
233
|
debug(`can not finish ${label} within ${timeout} sec`);
|
|
234
234
|
return typeof cb === "function" ? cb() : true;
|
|
235
235
|
})
|
|
236
|
-
.catch((err)=>{
|
|
236
|
+
.catch((err) => {
|
|
237
237
|
if (err.name === "AbortError") {
|
|
238
238
|
debug(`timeout was aborted because ${label} has finished or canceled`);
|
|
239
239
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ssh-client-wrapper",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.7",
|
|
4
4
|
"description": "wrapper library for open ssh client and rsync",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ssh",
|
|
@@ -46,7 +46,6 @@
|
|
|
46
46
|
"chai-as-promised": "^7.1.1",
|
|
47
47
|
"chai-fs": "^2.0.0",
|
|
48
48
|
"eslint": "^8.38.0",
|
|
49
|
-
"eslint-config-eslint": "^7.0.0",
|
|
50
49
|
"eslint-config-standard": "^17.1.0",
|
|
51
50
|
"eslint-plugin-chai-expect": "^3.0.0",
|
|
52
51
|
"eslint-plugin-chai-friendly": "^0.7.4",
|