From 2b53344a94c4562622cba17ed22b9252dbd574e6 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Sat, 10 Aug 2019 19:09:37 -0700 Subject: [PATCH] 0.0.5 Update deps, change cli bin name and call. Update testing --- bin/ssh-cli | 3 +++ bin/ssh-cli.js | 3 --- package.json | 24 ++++++++++-------------- src/ssh.js | 8 ++++---- test/config/ssh.yaml | 2 +- test/ssh.test.js | 10 +++++++--- 6 files changed, 25 insertions(+), 25 deletions(-) create mode 100755 bin/ssh-cli delete mode 100644 bin/ssh-cli.js diff --git a/bin/ssh-cli b/bin/ssh-cli new file mode 100755 index 0000000..0b06385 --- /dev/null +++ b/bin/ssh-cli @@ -0,0 +1,3 @@ +#! /usr/bin/env node +require = require('esm')(module) +require('./ssh.js') diff --git a/bin/ssh-cli.js b/bin/ssh-cli.js deleted file mode 100644 index 86c0703..0000000 --- a/bin/ssh-cli.js +++ /dev/null @@ -1,3 +0,0 @@ -// Set options as a parameter, environment variable, or rc file. -require = require('esm')(module) -module.exports = require('./ssh.js') diff --git a/package.json b/package.json index c6f3c36..019237e 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,15 @@ { "name": "@uci-utils/ssh", - "version": "0.0.4", + "version": "0.0.5", "description": "ssh client cli and api, a wrapper on ssh2", "main": "src/ssh.js", "bin": { - "ssh": "./bin/ssh.js" + "sshu": "./bin/ssh-cli" }, "scripts": { "ssh": "node -r esm ./bin/ssh", "testd": "UCI_ENV=dev ./node_modules/.bin/nodemon --exec './node_modules/.bin/mocha -r esm --timeout 30000'", - "test": "UCI_ENV=pro UCI_LOG_PATH=./test/test.log ./node_modules/.bin/mocha -r esm --timeout 30000 || exit 0", - "testibc": "istanbul cover ./node_modules/.bin/_mocha test/ --report lcovonly -- -R spec --recursive && codecov || true" + "test": "UCI_ENV=pro UCI_LOG_PATH=./test/test.log ./node_modules/.bin/mocha -r esm --timeout 30000 || exit 0" }, "author": "David Kebler", "license": "MIT", @@ -28,20 +27,17 @@ }, "homepage": "https://github.com/uCOMmandIt/uci-ssh#readme", "dependencies": { - "@uci-utils/logger": "0.0.13", + "@uci-utils/logger": "^0.0.15", "await-to-js": "^2.1.1", - "conf": "^2.2.0", - "esm": "^3.2.4", + "conf": "^5.0.0", "fs-read-data": "^1.0.4", - "ssh2": "^0.8.2", - "yargs": "^13.1.0" + "ssh2": "^0.8.5", + "yargs": "^13.3.0" }, "devDependencies": { "chai": "^4.2.0", - "chai-arrays": "^2.0.0", - "codecov": "^3.1.0", - "istanbul": "^0.4.5", - "mocha": "^5.x", - "nodemon": "^1.18.9" + "esm": "^3.2.25", + "mocha": "^6.x", + "nodemon": "^1.19.1" } } diff --git a/src/ssh.js b/src/ssh.js index 1c21525..04e751b 100644 --- a/src/ssh.js +++ b/src/ssh.js @@ -30,17 +30,17 @@ class Ssh extends Client { if (typeof opts ==='boolean' || !opts ) { if (typeof opts ==='boolean') overwrite = opts configPath = this.configsDir+'/'+this.config.get('defaultConfig') + log.debug({configPath:this.configPath, msg:'path to default configuration file used'}) opts = await readConfig(configPath) } if (typeof opts === 'string') { configPath = (opts.indexOf('/') === -1)? this.configsDir+'/'+opts : opts + log.debug({configPath:this.configPath, msg:'path to configuration file used'}) opts = await readConfig(configPath) } - - log.debug({configPath:this.configPath, msg:'path to actual configuration file used'}) - log.debug({opts:opts, msg:'connection options as read in from file'}) + log.debug({currentopts:this.opt, newopts:opts, msg:'connection options as read or passed'}) this.opts = overwrite ? Object.assign(this.opts,opts) : Object.assign(opts, this.opts) - log.debug({opts:opts, msg:'connection options as ammended from configure() argument'}) + log.debug({opts:this.opts, overwrite:overwrite, msg:'connection options as ammended from configure arguments'}) } async connect(copts = {}) { diff --git a/test/config/ssh.yaml b/test/config/ssh.yaml index e51f990..d8c14cc 100644 --- a/test/config/ssh.yaml +++ b/test/config/ssh.yaml @@ -1,4 +1,4 @@ -host: switches.kebler.net +host: pine64.kebler.net username: sysadmin #agent: /run/user/1000/ssh-agent.socket #agentenv: SSH_AUTH_SOCK diff --git a/test/ssh.test.js b/test/ssh.test.js index d98eb80..64cd440 100644 --- a/test/ssh.test.js +++ b/test/ssh.test.js @@ -2,7 +2,7 @@ import Ssh from '../src/ssh' import to from 'await-to-js' import { expect } from 'chai' import { it } from 'mocha' -import logger from '@uci/logger' +import logger from '@uci-utils/logger' describe('SSH Class Testing ',async ()=> { @@ -36,13 +36,17 @@ describe('SSH Class Testing ',async ()=> { }) it('connect via an "interactive shell" and cat the test.txt file in home directory"' , async function () { - let [err,res] = await to(remote.shell('cat test.txt')) // cd /opt && pwd + let number = Date.now() + log.info({number:number, msg:'putting number into remote test.text file'}) + // log.info('putting number into remote test.text file') + await to(remote.shell(`echo ${number} > test.txt`)) + let [err,res] = await to(remote.shell('cat test.txt')) if (err) { log.info('error running shell command aborting test', err) throw new Error(err) } let passed = false - if (res.reply.indexOf('47fciogjei439djfjla') > 0) passed=true + if (res.reply.indexOf(number > 0)) passed=true log.info({remoteHost:remote.opts.host, reply:res.reply.toString().trim(), err:err, cmd:res.command, msg:`remote command completed ${res.command}`}) expect(passed, 'test failed').to.equal(true) })