0.0.5 Update deps, change cli bin name and call. Update testing
parent
606978c37e
commit
2b53344a94
|
@ -0,0 +1,3 @@
|
||||||
|
#! /usr/bin/env node
|
||||||
|
require = require('esm')(module)
|
||||||
|
require('./ssh.js')
|
|
@ -1,3 +0,0 @@
|
||||||
// Set options as a parameter, environment variable, or rc file.
|
|
||||||
require = require('esm')(module)
|
|
||||||
module.exports = require('./ssh.js')
|
|
24
package.json
24
package.json
|
@ -1,16 +1,15 @@
|
||||||
{
|
{
|
||||||
"name": "@uci-utils/ssh",
|
"name": "@uci-utils/ssh",
|
||||||
"version": "0.0.4",
|
"version": "0.0.5",
|
||||||
"description": "ssh client cli and api, a wrapper on ssh2",
|
"description": "ssh client cli and api, a wrapper on ssh2",
|
||||||
"main": "src/ssh.js",
|
"main": "src/ssh.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"ssh": "./bin/ssh.js"
|
"sshu": "./bin/ssh-cli"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ssh": "node -r esm ./bin/ssh",
|
"ssh": "node -r esm ./bin/ssh",
|
||||||
"testd": "UCI_ENV=dev ./node_modules/.bin/nodemon --exec './node_modules/.bin/mocha -r esm --timeout 30000'",
|
"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",
|
"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"
|
|
||||||
},
|
},
|
||||||
"author": "David Kebler",
|
"author": "David Kebler",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -28,20 +27,17 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/uCOMmandIt/uci-ssh#readme",
|
"homepage": "https://github.com/uCOMmandIt/uci-ssh#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@uci-utils/logger": "0.0.13",
|
"@uci-utils/logger": "^0.0.15",
|
||||||
"await-to-js": "^2.1.1",
|
"await-to-js": "^2.1.1",
|
||||||
"conf": "^2.2.0",
|
"conf": "^5.0.0",
|
||||||
"esm": "^3.2.4",
|
|
||||||
"fs-read-data": "^1.0.4",
|
"fs-read-data": "^1.0.4",
|
||||||
"ssh2": "^0.8.2",
|
"ssh2": "^0.8.5",
|
||||||
"yargs": "^13.1.0"
|
"yargs": "^13.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"chai-arrays": "^2.0.0",
|
"esm": "^3.2.25",
|
||||||
"codecov": "^3.1.0",
|
"mocha": "^6.x",
|
||||||
"istanbul": "^0.4.5",
|
"nodemon": "^1.19.1"
|
||||||
"mocha": "^5.x",
|
|
||||||
"nodemon": "^1.18.9"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,17 +30,17 @@ class Ssh extends Client {
|
||||||
if (typeof opts ==='boolean' || !opts ) {
|
if (typeof opts ==='boolean' || !opts ) {
|
||||||
if (typeof opts ==='boolean') overwrite = opts
|
if (typeof opts ==='boolean') overwrite = opts
|
||||||
configPath = this.configsDir+'/'+this.config.get('defaultConfig')
|
configPath = this.configsDir+'/'+this.config.get('defaultConfig')
|
||||||
|
log.debug({configPath:this.configPath, msg:'path to default configuration file used'})
|
||||||
opts = await readConfig(configPath)
|
opts = await readConfig(configPath)
|
||||||
}
|
}
|
||||||
if (typeof opts === 'string') {
|
if (typeof opts === 'string') {
|
||||||
configPath = (opts.indexOf('/') === -1)? this.configsDir+'/'+opts : opts
|
configPath = (opts.indexOf('/') === -1)? this.configsDir+'/'+opts : opts
|
||||||
|
log.debug({configPath:this.configPath, msg:'path to configuration file used'})
|
||||||
opts = await readConfig(configPath)
|
opts = await readConfig(configPath)
|
||||||
}
|
}
|
||||||
|
log.debug({currentopts:this.opt, newopts:opts, msg:'connection options as read or passed'})
|
||||||
log.debug({configPath:this.configPath, msg:'path to actual configuration file used'})
|
|
||||||
log.debug({opts:opts, msg:'connection options as read in from file'})
|
|
||||||
this.opts = overwrite ? Object.assign(this.opts,opts) : Object.assign(opts, this.opts)
|
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 = {}) {
|
async connect(copts = {}) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
host: switches.kebler.net
|
host: pine64.kebler.net
|
||||||
username: sysadmin
|
username: sysadmin
|
||||||
#agent: /run/user/1000/ssh-agent.socket
|
#agent: /run/user/1000/ssh-agent.socket
|
||||||
#agentenv: SSH_AUTH_SOCK
|
#agentenv: SSH_AUTH_SOCK
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Ssh from '../src/ssh'
|
||||||
import to from 'await-to-js'
|
import to from 'await-to-js'
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { it } from 'mocha'
|
import { it } from 'mocha'
|
||||||
import logger from '@uci/logger'
|
import logger from '@uci-utils/logger'
|
||||||
|
|
||||||
describe('SSH Class Testing ',async ()=> {
|
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 () {
|
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) {
|
if (err) {
|
||||||
log.info('error running shell command aborting test', err)
|
log.info('error running shell command aborting test', err)
|
||||||
throw new Error(err)
|
throw new Error(err)
|
||||||
}
|
}
|
||||||
let passed = false
|
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}`})
|
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)
|
expect(passed, 'test failed').to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue