ssh-client-wrapper 2.2.0 → 2.2.1

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 CHANGED
@@ -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 createMastePty(hostInfo) {
61
+ function createMasterPty(hostInfo) {
62
62
  debug("fork pty for master connection");
63
63
 
64
64
  if (hostInfo.masterPty) {
@@ -125,6 +125,6 @@ async function fork(hostInfo, cmd, args, timeout, outputCallback) {
125
125
  }
126
126
  module.exports = {
127
127
  fork,
128
- createMastePty,
128
+ createMasterPty,
129
129
  sshLoginCallback
130
130
  };
package/lib/sshExec.js CHANGED
@@ -5,7 +5,7 @@ const debug = require("debug")("sshClientWrapper:debug:sshExec");
5
5
  const debugVerbose = require("debug")("sshClientWrapper:verbose:sshExec");
6
6
  const debugSendMasterPty = require("debug")("sshClientWrapper:insecure:sshExec_masterPty");
7
7
  const { sendPty, sshCmd, getSshOption, sanityCheck, watchDogTimer } = require("./util.js");
8
- const { fork, createMastePty, sshLoginCallback } = require("./fork.js");
8
+ const { fork, createMasterPty, sshLoginCallback } = require("./fork.js");
9
9
 
10
10
  /**
11
11
  * Execute command on remote host.
@@ -15,6 +15,7 @@ const { fork, createMastePty, sshLoginCallback } = require("./fork.js");
15
15
  * @param {Function} outputCallback - Callback routine for stdout and stderr.
16
16
  */
17
17
  async function sshExec(hostInfo, cmd, timeout, outputCallback) {
18
+ debug("sshExec called");
18
19
  await connect(hostInfo);
19
20
  debug("exec", cmd, "on remote server");
20
21
  const args = getSshOption(hostInfo, false);
@@ -46,16 +47,13 @@ async function sshExec(hostInfo, cmd, timeout, outputCallback) {
46
47
  * @param {Integer} timeout - timeout in secconds
47
48
  */
48
49
  async function canConnect(hostInfo, timeout = 60) {
49
- debug("sanity check");
50
+ debug("canConnect called");
50
51
  sanityCheck(hostInfo);
51
52
 
52
- debug("check connectibity");
53
-
54
- try {
55
- await connect(hostInfo, timeout);
56
- } finally {
57
- await disconnect(hostInfo);
58
- }
53
+ await connect(hostInfo, timeout);
54
+ await disconnect(hostInfo);
55
+ //if connection fail, Error is throwed.
56
+ //so, if we reach here, connection must be succeeded
59
57
  return true;
60
58
  }
61
59
 
@@ -97,16 +95,17 @@ async function existsMaster(hostInfo, argTimeout) {
97
95
  * @param {Object} hostInfo - hostinfo object
98
96
  */
99
97
  async function connect(hostInfo, timeout = 60) {
98
+ debug("connect called");
99
+
100
100
  if (await existsMaster(hostInfo, timeout)) {
101
101
  debugVerbose("master connection exists");
102
102
  return;
103
103
  }
104
104
 
105
105
  debug(`create master pty for ${hostInfo.host}`);
106
- createMastePty(hostInfo, debugSendMasterPty);
106
+ createMasterPty(hostInfo, debugSendMasterPty);
107
107
 
108
108
  debug(`create master ssh session to ${hostInfo.host}`);
109
-
110
109
  const words = crypto.randomUUID();
111
110
  const re = new RegExp(`^${words}`);
112
111
 
@@ -177,6 +176,8 @@ async function connect(hostInfo, timeout = 60) {
177
176
  * @param {Object} hostInfo - hostinfo object
178
177
  */
179
178
  async function disconnect(hostInfo) {
179
+ debug("disconnect called");
180
+
180
181
  if (await existsMaster(hostInfo)) {
181
182
  const args = getSshOption(hostInfo);
182
183
  args.push("-Oexit");
@@ -218,6 +219,7 @@ async function disconnect(hostInfo) {
218
219
  * @returns {string[]} - output from ls
219
220
  */
220
221
  async function ls(hostInfo, target, lsOpt, timeout) {
222
+ debug("ls called");
221
223
  const outputArray = [];
222
224
  try {
223
225
  await sshExec(hostInfo, `ls ${lsOpt.join(" ")} ${target}`, timeout, (data)=>{
package/lib/util.js CHANGED
@@ -26,6 +26,8 @@ const buff2String = (func, data)=>{
26
26
  * @param { Object} hostInfo - host information object defined in index.js
27
27
  */
28
28
  const sanityCheck = (hostInfo)=>{
29
+ debug("sanityCheck called");
30
+
29
31
  if (typeof hostInfo.host !== "string" || hostInfo.host === "") {
30
32
  throw new Error("host must be non-empty string");
31
33
  }
@@ -43,6 +45,7 @@ const sanityCheck = (hostInfo)=>{
43
45
  * @param {boolean} withoutDestination - return except for hostname
44
46
  */
45
47
  const getSshOption = (hostInfo, withoutDestination)=>{
48
+ debug("getSshOption called");
46
49
  const args = [];
47
50
 
48
51
  if (!withoutDestination) {
@@ -140,7 +143,7 @@ const watchDogTimer = (timeout, label, cb)=>{
140
143
  })
141
144
  .catch((err)=>{
142
145
  if (err.name === "AbortError") {
143
- debug(`timeout was aborted because ${label} has done`);
146
+ debug(`timeout was aborted because ${label} has finished or canceled`);
144
147
  } else {
145
148
  throw err;
146
149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ssh-client-wrapper",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "wrapper library for open ssh client and rsync",
5
5
  "keywords": [
6
6
  "ssh",