ssh-client-wrapper 1.0.8 → 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.
@@ -1,8 +1,14 @@
1
- name: publish
1
+ name: publish npm package
2
2
  on:
3
- workflow_call:
3
+ push:
4
+ tags:
5
+ - 'v*'
4
6
  jobs:
7
+ test:
8
+ uses: ./.github/workflows/run_test.yml
5
9
  publish-npm:
10
+ needs:
11
+ - test
6
12
  runs-on: ubuntu-latest
7
13
  steps:
8
14
  - uses: actions/checkout@v3
@@ -1,6 +1,12 @@
1
1
  name: run UT
2
2
  on:
3
+ push:
4
+ tags-ignore:
5
+ - 'v*'
3
6
  workflow_call:
7
+ concurrency:
8
+ group: ${{ github.workflow }}-${{ github.ref }}
9
+ cancel-in-progress: true
4
10
  jobs:
5
11
  test:
6
12
  services:
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(ptyProcess.write);
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(ptyProcess.write);
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
- return new Error("src must be array of string");
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
- return new Error("dst must be string");
95
+ const err = "dst must be string";
96
+ debug(err);
97
+ return new Error(err);
94
98
  }
95
- if (!isArrayOfString(opt)) {
96
- return new Error("opt must be array of string");
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
- return new Error("src must be array of string");
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
- return new Error("dst must be string");
123
+ const err = "dst must be string";
124
+ debug(err);
125
+ return new Error(err);
116
126
  }
117
- if (!isArrayOfString(opt)) {
118
- return new Error("opt must be array of string");
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(`-OConnectTimeout=${timeout}`);
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/wheel-%r@%h:%p");
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
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "ssh-client-wrapper",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "wrapper library for open ssh client and rsync",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
7
  "test": "mocha --recursive test",
8
8
  "lint": "eslint --fix lib test",
9
- "postversion": "git push origin $(git describe --abbrev=0 --tags)"
9
+ "postversion": "git push && git push origin $(git describe --abbrev=0 --tags)"
10
10
  },
11
11
  "engines": {
12
12
  "node": ">=12.9"
@@ -1,11 +0,0 @@
1
- name: release package
2
- on:
3
- push:
4
- tags:
5
- - 'v*'
6
- jobs:
7
- test:
8
- uses: ./.github/workflows/run_test.yml
9
- publish-npm:
10
- uses: ./.github/workflows/npm-publish.yml
11
- secrets: inherit
@@ -1,8 +0,0 @@
1
- name: run UT only
2
- on:
3
- push:
4
- tags-ignore:
5
- - 'v*'
6
- jobs:
7
- test:
8
- uses: ./.github/workflows/run_test.yml