ssh-client-wrapper 1.0.9 → 1.1.0
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 +9 -3
- package/lib/index.js +24 -13
- package/lib/rsyncExec.js +2 -0
- package/lib/sshExec.js +1 -1
- package/lib/util.js +3 -2
- package/package.json +1 -1
package/lib/fork.js
CHANGED
|
@@ -15,8 +15,8 @@ async function fork(hostInfo, cmd, args, argOpt, outputCallback) {
|
|
|
15
15
|
return new Promise((resolve, reject)=>{
|
|
16
16
|
const opt = argOpt || defaultOpt;
|
|
17
17
|
|
|
18
|
-
const ptyProcess = spawn(cmd, args, opt);
|
|
19
18
|
debug(`cmd=${cmd}: args=${args}`);
|
|
19
|
+
const ptyProcess = spawn(cmd, args, opt);
|
|
20
20
|
ptyProcess.onData(buff2String.bind(null, debugVerbose));
|
|
21
21
|
|
|
22
22
|
ptyProcess.onData((data)=>{
|
|
@@ -31,7 +31,10 @@ async function fork(hostInfo, cmd, args, argOpt, outputCallback) {
|
|
|
31
31
|
debugSendPty(hostInfo.password);
|
|
32
32
|
ptyProcess.write(`${hostInfo.password}\n`);
|
|
33
33
|
} else if (typeof hostInfo.password === "function") {
|
|
34
|
-
hostInfo.password(
|
|
34
|
+
hostInfo.password()
|
|
35
|
+
.then((pw)=>{
|
|
36
|
+
ptyProcess.write(`${pw}\n`);
|
|
37
|
+
});
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
if (rePhPrompt.test(output)) {
|
|
@@ -39,7 +42,10 @@ async function fork(hostInfo, cmd, args, argOpt, outputCallback) {
|
|
|
39
42
|
debugSendPty(hostInfo.passphrase);
|
|
40
43
|
ptyProcess.write(`${hostInfo.passphrase}\n`);
|
|
41
44
|
} else if (typeof hostInfo.passphrase === "function") {
|
|
42
|
-
hostInfo.passphrase(
|
|
45
|
+
hostInfo.passphrase()
|
|
46
|
+
.then((pw)=>{
|
|
47
|
+
ptyProcess.write(`${pw}\n`);
|
|
48
|
+
});
|
|
43
49
|
}
|
|
44
50
|
}
|
|
45
51
|
});
|
package/lib/index.js
CHANGED
|
@@ -83,17 +83,23 @@ class SshClientWrapper {
|
|
|
83
83
|
* @param {[string]} opt - option for rsync
|
|
84
84
|
* @returns {Promise} - Resolved with undefined when file transfer is done.
|
|
85
85
|
*/
|
|
86
|
-
async send(src, dst, opt
|
|
87
|
-
debug("send called", src, dst);
|
|
86
|
+
async send(src, dst, opt) {
|
|
87
|
+
debug("send called", src, dst, opt);
|
|
88
88
|
|
|
89
89
|
if (!isArrayOfString(src)) {
|
|
90
|
-
|
|
90
|
+
const err = "src must be array of string";
|
|
91
|
+
debug(err);
|
|
92
|
+
return new Error(err);
|
|
91
93
|
}
|
|
92
94
|
if (typeof dst !== "string") {
|
|
93
|
-
|
|
95
|
+
const err = "dst must be string";
|
|
96
|
+
debug(err);
|
|
97
|
+
return new Error(err);
|
|
94
98
|
}
|
|
95
|
-
if (!isArrayOfString(opt)) {
|
|
96
|
-
|
|
99
|
+
if (typeof opt !== "undefined" && !isArrayOfString(opt)) {
|
|
100
|
+
const err = "opt must be array of string";
|
|
101
|
+
debug(err);
|
|
102
|
+
return new Error(err);
|
|
97
103
|
}
|
|
98
104
|
return send(this.hostInfo, src, dst, opt);
|
|
99
105
|
}
|
|
@@ -105,19 +111,24 @@ class SshClientWrapper {
|
|
|
105
111
|
* @param {[string]} opt - option for rsync
|
|
106
112
|
* @returns {Promise} - Resolved with undefined when file transfer is done.
|
|
107
113
|
*/
|
|
108
|
-
async recv(src, dst, opt
|
|
109
|
-
debug("recv called", src, dst);
|
|
114
|
+
async recv(src, dst, opt) {
|
|
115
|
+
debug("recv called", src, dst, opt);
|
|
110
116
|
|
|
111
117
|
if (!isArrayOfString(src)) {
|
|
112
|
-
|
|
118
|
+
const err = "src must be array of string";
|
|
119
|
+
debug(err);
|
|
120
|
+
return new Error(err);
|
|
113
121
|
}
|
|
114
122
|
if (typeof dst !== "string") {
|
|
115
|
-
|
|
123
|
+
const err = "dst must be string";
|
|
124
|
+
debug(err);
|
|
125
|
+
return new Error(err);
|
|
116
126
|
}
|
|
117
|
-
if (!isArrayOfString(opt)) {
|
|
118
|
-
|
|
127
|
+
if (typeof opt !== "undefined" && !isArrayOfString(opt)) {
|
|
128
|
+
const err = "opt must be array of string";
|
|
129
|
+
debug(err);
|
|
130
|
+
return new Error(err);
|
|
119
131
|
}
|
|
120
|
-
|
|
121
132
|
return recv(this.hostInfo, src, dst, opt);
|
|
122
133
|
}
|
|
123
134
|
|
package/lib/rsyncExec.js
CHANGED
|
@@ -34,6 +34,8 @@ async function send(hostInfo, argSrc, dst, rsyncOpt = []) {
|
|
|
34
34
|
|
|
35
35
|
const args = ["-amvv", "--copy-unsafe-links", ...rshOpt, ...rsyncOpt, ...src, `${hostInfo.host}:${dst}`];
|
|
36
36
|
const { dir: remoteDir } = path.parse(dst);
|
|
37
|
+
debug("remoteDir=", remoteDir);
|
|
38
|
+
|
|
37
39
|
if (remoteDir !== "" && remoteDir !== "/") {
|
|
38
40
|
debug(`mkdir ${remoteDir}`);
|
|
39
41
|
sshExec(hostInfo, `mkdir -p ${remoteDir}`, debugVerbose);
|
package/lib/sshExec.js
CHANGED
|
@@ -28,7 +28,7 @@ async function canConnect(hostInfo, timeout) {
|
|
|
28
28
|
const words = crypto.randomUUID();
|
|
29
29
|
const args = getSshOption(hostInfo);
|
|
30
30
|
if (Number.isInteger(timeout) && timeout > 0) {
|
|
31
|
-
args.push(`-
|
|
31
|
+
args.push(`-oConnectTimeout=${timeout}`);
|
|
32
32
|
}
|
|
33
33
|
args.push(`echo ${words}`);
|
|
34
34
|
|
package/lib/util.js
CHANGED
|
@@ -50,7 +50,7 @@ const getSshOption = (hostInfo, withoutDestination)=>{
|
|
|
50
50
|
}
|
|
51
51
|
const renewInterval = Number.isInteger(hostInfo.renewInterval) && hostInfo.renewInterval > 0 ? hostInfo.renewInterval : 180;
|
|
52
52
|
args.push("-oControlMaster=auto");
|
|
53
|
-
args.push("-oControlPath=~/.ssh/
|
|
53
|
+
args.push("-oControlPath=~/.ssh/ssh-client-wrapper-%r@%h:%p");
|
|
54
54
|
args.push(`-oControlPersist=${renewInterval}`);
|
|
55
55
|
return args;
|
|
56
56
|
};
|
|
@@ -72,7 +72,8 @@ const isArrayOfString = (target)=>{
|
|
|
72
72
|
if (!Array.isArray(target)) {
|
|
73
73
|
return false;
|
|
74
74
|
}
|
|
75
|
-
return target.some((e)=>{
|
|
75
|
+
return !target.some((e)=>{
|
|
76
|
+
//target has non string member
|
|
76
77
|
return typeof e !== "string";
|
|
77
78
|
});
|
|
78
79
|
};
|