0.0.5 Update deps, change cli bin name and call. Update testing

master
David Kebler 2019-08-10 19:09:37 -07:00
parent 606978c37e
commit 2b53344a94
6 changed files with 25 additions and 25 deletions

3
bin/ssh-cli Executable file
View File

@ -0,0 +1,3 @@
#! /usr/bin/env node
require = require('esm')(module)
require('./ssh.js')

View File

@ -1,3 +0,0 @@
// Set options as a parameter, environment variable, or rc file.
require = require('esm')(module)
module.exports = require('./ssh.js')

View File

@ -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"
}
}

View File

@ -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 = {}) {

View File

@ -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

View File

@ -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)
})