ssh2-connect
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -1,4 +0,14 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. | ||
## [3.2.0](https://github.com/adaltas/node-ssh2-connect/compare/v3.1.0...v3.2.0) (2022-03-08) | ||
### Features | ||
* support ed25519 and rsa discovery ([5b0791f](https://github.com/adaltas/node-ssh2-connect/commit/5b0791f1badd173344e1ad4196e0f3d58ce11f57)) | ||
## Version 3.1.0 | ||
@@ -5,0 +15,0 @@ |
@@ -1,59 +0,18 @@ | ||
// Generated by CoffeeScript 2.5.1 | ||
// # Connect | ||
// Generated by CoffeeScript 2.6.1 | ||
var Client, camelize, constants, fs, path; | ||
// This module provide a promise based api to open an ssh2 connection. | ||
({ | ||
constants, | ||
promises: fs | ||
} = require('fs')); | ||
// For example, the original ssh2 code... | ||
path = require('path'); | ||
// ```js | ||
// const ssh2 = require('ssh2') | ||
// const connection = new ssh2() | ||
// connection.on('error', (err) => { | ||
// // not ready at all | ||
// connection.end() | ||
// }) | ||
// connection.on('ready', () => { | ||
// // ready to go | ||
// }) | ||
// connection.connect(options) | ||
// ``` | ||
({Client} = require('ssh2')); | ||
// ...is now simplified to: | ||
// ```js | ||
// const connect = require('ssh2-exec') | ||
// const ssh = await connect(options, (err, ssh) -> | ||
// // this is more comprehensive | ||
// ) | ||
// ``` | ||
var camelize, fs, ssh2; | ||
fs = require('fs').promises; | ||
ssh2 = require('ssh2'); | ||
// Options are inherited from the [ssh2 `Connection.prototype.connect`][ssh2-connect] | ||
// function with a few additions: | ||
// - `username` | ||
// The username used to initiate the connection, default to the current | ||
// environment user. | ||
// - `privateKeyPath` | ||
// Path to the file containing the private key. | ||
// - `retry` | ||
// Attempt to reconnect multiple times, default to "1". | ||
// - `wait` | ||
// Time to wait in milliseconds between each retry, default to "500". | ||
// Note, the "privateKeyPath" option is provided as a conveniency to prepare the | ||
// "privateKey" property. | ||
// Additionally, all options may be provided in camalize (the default in [ssh2]) or | ||
// underscore form. For example, both "privateKey" and "private_key" would be | ||
// interprated the same. | ||
module.exports = function(options, callback) { | ||
var work; | ||
work = async function(resolve, reject) { | ||
var connect, e, match, retry; | ||
if (options instanceof ssh2) { | ||
var algo, connect, e, err, i, len, match, ref, retry, source; | ||
if (options instanceof Client) { | ||
return resolve(options); | ||
@@ -79,7 +38,4 @@ } | ||
if (options.privateKeyPath == null) { | ||
options.privateKeyPath = '~/.ssh/id_rsa'; | ||
options.privateKeyPath = true; // Auto discovery | ||
} | ||
if (options.privateKeyPath && (match = /~(\/.*)/.exec(options.privateKeyPath))) { | ||
options.privateKeyPath = process.env.HOME + match[1]; | ||
} | ||
} else { | ||
@@ -90,4 +46,23 @@ options.privateKeyPath = null; | ||
// Extract private key from file | ||
if (options.privateKeyPath) { | ||
if (typeof options.privateKeyPath === 'string') { | ||
if (match = /~(\/.*)/.exec(options.privateKeyPath)) { | ||
options.privateKeyPath = path.join(process.env.HOME, match[1]); | ||
} | ||
options.privateKey = (await fs.readFile(options.privateKeyPath, 'ascii')); | ||
} else if (options.privateKeyPath === true) { | ||
ref = ['id_ed25519', 'id_rsa']; | ||
for (i = 0, len = ref.length; i < len; i++) { | ||
algo = ref[i]; | ||
source = path.resolve(process.env.HOME, '.ssh', algo); | ||
try { | ||
options.privateKey = (await fs.readFile(source, 'ascii')); | ||
break; | ||
} catch (error) { | ||
err = error; | ||
({}); | ||
} | ||
} | ||
if (options.privateKey == null) { | ||
throw Error('Failed to discover an ssh private key inside `~/.ssh`.'); | ||
} | ||
} | ||
@@ -106,3 +81,3 @@ } catch (error) { | ||
succeed = false; | ||
connection = new ssh2(); | ||
connection = new Client(); | ||
connection.on('error', function(err) { | ||
@@ -152,4 +127,1 @@ connection.end(); | ||
}; | ||
// [ssh2]: https://github.com/mscdex/ssh2 | ||
// [ssh2-connect]: https://github.com/wdavidw/node-ssh2-connect |
{ | ||
"name": "ssh2-connect", | ||
"description": "Callback-based api behind ssh2 to open an SSH connection", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"author": "David Worms <david@adaltas.com> (https://www.adaltas.com)", | ||
@@ -27,8 +27,13 @@ "coffeelintConfig": { | ||
"dependencies": { | ||
"ssh2": "~0.8.9" | ||
"ssh2": "~1.7.0" | ||
}, | ||
"devDependencies": { | ||
"coffeescript": "^2.5.1", | ||
"mocha": "~8.2.1", | ||
"should": "~13.2.3" | ||
"@commitlint/cli": "^16.0.2", | ||
"@commitlint/config-conventional": "^16.0.0", | ||
"@commitlint/cz-commitlint": "^16.0.0", | ||
"coffeescript": "^2.6.1", | ||
"husky": "^7.0.4", | ||
"mocha": "~9.2.1", | ||
"should": "~13.2.3", | ||
"standard-version": "^9.3.2" | ||
}, | ||
@@ -68,12 +73,9 @@ "engines": { | ||
"scripts": { | ||
"preversion": "grep '## Trunk' CHANGELOG.md && npm test", | ||
"version": "version=`grep '^ \"version\": ' package.json | sed 's/.*\"\\([0-9\\.]*\\)\".*/\\1/'` && sed -i \"s/## Trunk/## Version $version/\" CHANGELOG.md && git add CHANGELOG.md", | ||
"postversion": "git push && git push --tags && npm publish", | ||
"patch": "npm version patch -m 'Bump to version %s'", | ||
"minor": "npm version minor -m 'Bump to version %s'", | ||
"major": "npm version major -m 'Bump to version %s'", | ||
"build": "coffee -b -o lib src", | ||
"prepare": "husky install", | ||
"publish": "git push --follow-tags origin master && npm publish", | ||
"pretest": "npm run build", | ||
"release": "npm test && standard-version", | ||
"test": "mocha 'test/**/*.coffee'" | ||
} | ||
} |
@@ -5,12 +5,12 @@ [![Build Status](https://secure.travis-ci.org/adaltas/node-ssh2-connect.png)][travis] | ||
The Node.js ssh2-connect package extends the [`ssh2`][ssh2] module to provide | ||
a simplified callback-back approach to initiate a new SSH connection. | ||
The Node.js ssh2-connect package extends the [`ssh2`][ssh2] module to provide a simplified callback-back approach to initiate a new SSH connection. | ||
## Usage | ||
Function signature is `connect(options, callback)`. | ||
The `connect` fonction return a promise. Its signature is `await connect(options)` | ||
The main purpose of this module is to simplify the creation of an SSH | ||
connection. For example, the original ssh2 code... | ||
It also accept an optional callback function. In such case, its signature is `connect(options, callback)`. | ||
The main purpose of this module is to simplify the creation of an SSH connection. For example, the original ssh2 code... | ||
```js | ||
@@ -55,4 +55,3 @@ const ssh2 = require('ssh2') | ||
Options are inherited from the [ssh2 `Connection.prototype.connect`][ssh2-connect] | ||
function with a few additions: | ||
Options are inherited from the [ssh2 `Connection.prototype.connect`][ssh2-connect] function with a few additions: | ||
@@ -63,14 +62,11 @@ - `username` | ||
- `privateKeyPath` | ||
Path to the file containing the private key. | ||
Path of the file containing the private key, `true` to enable auto-discovery or `false` to disable auto-discovery, default to `true`. | ||
- `retry` | ||
Attempt to reconnect multiple times, default to "1". | ||
Attempt to reconnect multiple times, default to `1`. | ||
- `wait` | ||
Time to wait in milliseconds between each retry, default to "2000". | ||
Time to wait in milliseconds between each retry, default to `2000`. | ||
Note, the "privateKeyPath" option is provided as a conveniency to prepare the | ||
"privateKey" property. | ||
Note, the "privateKeyPath" option is provided as a conveniency to read the private key and fill the "privateKey" property. | ||
Additionally, all options may be provided in camalize (the default in [ssh2]) or | ||
underscore form. For example, both "privateKey" and "private_key" would be | ||
interprated the same. | ||
Additionally, all options may be provided in camalize (the default in [ssh2]) or underscore form. For example, both "privateKey" and "private_key" would be interprated the same. | ||
@@ -120,4 +116,3 @@ ## Installation | ||
Tests are executed with mocha. To install it, simple run `npm install`, it will install | ||
mocha and its dependencies in your project "node_modules" directory. | ||
Tests are executed with mocha. To install it, simple run `npm install`, it will install mocha and its dependencies in your project "node_modules" directory. | ||
@@ -136,4 +131,3 @@ To run the tests: | ||
The test suite is run online with [Travis][travis] against several Node.js | ||
version. | ||
The test suite is run online with [Travis][travis] against several Node.js version. | ||
@@ -140,0 +134,0 @@ ## Contributors |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12514
9
8
139
139
6
+ Addedcpu-features@0.0.2(transitive)
+ Addednan@2.22.0(transitive)
+ Addedssh2@1.7.0(transitive)
- Removedssh2@0.8.9(transitive)
- Removedssh2-streams@0.4.10(transitive)
- Removedstreamsearch@0.1.2(transitive)
Updatedssh2@~1.7.0