From 1f60b5a9c01e7dea129743360bb3194f85798945 Mon Sep 17 00:00:00 2001 From: Jorge Hernandez Date: Thu, 8 Jun 2023 18:06:01 -0500 Subject: [PATCH 1/4] update tunnel ssh --- index.js | 50 +++++++++--------- package.json | 2 +- yarn.lock | 141 ++++++++++++++++++++++++++++----------------------- 3 files changed, 103 insertions(+), 90 deletions(-) diff --git a/index.js b/index.js index 22cb9e2..e962dab 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ var RSVP = require('rsvp'); var fs = require('fs'); -var tunnelSsh = require('tunnel-ssh'); +var { createTunnel } = require('tunnel-ssh'); var untildify = require('untildify'); var DeployPluginBase = require('ember-cli-deploy-plugin'); @@ -13,6 +13,7 @@ var MIN_PORT_NUMBER = 49151; module.exports = { name: 'ember-cli-deploy-ssh-tunnel', + createDeployPlugin: function(options) { var DeployPlugin = DeployPluginBase.extend({ name: options.name, @@ -24,10 +25,6 @@ module.exports = { var range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1; return Math.floor(Math.random() * range) + MIN_PORT_NUMBER; }, - tunnelClient: function(context) { - // if you want to provide your own ssh client to be used instead of one from this plugin - return context.tunnelClient || tunnelSsh; - } }, requiredConfig: ['host', 'username'], @@ -39,38 +36,41 @@ module.exports = { throw 'Port ' + srcPort + ' is not available to open a SSH connection on.\n' + 'Please choose a port between ' + MIN_PORT_NUMBER + ' and ' + MAX_PORT_NUMBER + '.'; } - var sshConfig = { + const tunnelOptions = { + autoClose: true + }; + + const serverOptions = { + port: srcPort + }; + + const sshOptions = { host: this.readConfig('host'), port: this.readConfig('port'), - dstPort: this.readConfig('dstPort'), - dstHost: this.readConfig('dstHost'), username: this.readConfig('username'), - localPort: srcPort + privateKey: fs.readFileSync(untildify(this.readConfig('privateKeyPath'))) }; - var password = this.readConfig('password'); - var privateKey = this.readConfig('privateKeyPath'); - var tunnel = this.readConfig('tunnelClient'); - - if (password) { - sshConfig.password = password; - } else if (privateKey) { - sshConfig.privateKey = fs.readFileSync(untildify(privateKey)); - } + const forwardOptions = { + srcAddr: 'localhost', + srcPort: this.readConfig('srcPort'), + dstAddr: this.readConfig('dstHost'), + dstPort: this.readConfig('dstPort') + }; return new RSVP.Promise(function(resolve, reject) { - var sshTunnel = tunnel(sshConfig, function(error /*, result */) { - if (error) { - reject(error); - } else { + createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions) + .then(([server, conn]) => { resolve({ tunnel: { - handler: sshTunnel, + handler: server, srcPort: srcPort } }); - } - }); + }) + .catch((error) => { + reject(error); + }); }); }, diff --git a/package.json b/package.json index 1cbfb3c..c847d2d 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ ], "dependencies": { "ember-cli-deploy-plugin": "^0.2.6", - "tunnel-ssh": "^1.0.1", + "tunnel-ssh": "^5.0.5", "untildify": "^2.0.0" } } diff --git a/yarn.lock b/yarn.lock index 64d7683..3c77a24 100644 --- a/yarn.lock +++ b/yarn.lock @@ -74,14 +74,14 @@ ansi-escapes@^1.1.0: version "1.4.0" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-1.4.0.tgz#d3a8a83b319aa67793662b13e761c7911422306e" -ansi-regex@*, ansi-regex@^2.0.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" - ansi-regex@^0.2.0, ansi-regex@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-0.2.1.tgz#0d8e946967a3d8143f93e24e298525fc1b2235f9" +ansi-regex@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" + ansi-styles@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.1.0.tgz#eaecbf66cd706882760b2f4691582b8f55d7a7de" @@ -206,7 +206,14 @@ asap@^2.0.0: version "2.0.5" resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.5.tgz#522765b50c3510490e52d7dcfe085ef9ba96958f" -asn1@~0.2.0, asn1@~0.2.3: +asn1@^0.2.6: + version "0.2.6" + resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.6.tgz#0d3a7bb6e64e02a90c0303b31f292868ea09a08d" + integrity sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ== + dependencies: + safer-buffer "~2.1.0" + +asn1@~0.2.3: version "0.2.3" resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86" @@ -432,6 +439,13 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" +bcrypt-pbkdf@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e" + integrity sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w== + dependencies: + tweetnacl "^0.14.3" + better-assert@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/better-assert/-/better-assert-1.0.2.tgz#40866b9e1b9e0b55b481894311e68faffaebc522" @@ -732,6 +746,11 @@ buffer-shims@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/buffer-shims/-/buffer-shims-1.0.0.tgz#9978ce317388c649ad8793028c3477ef044a8b51" +buildcheck@~0.0.6: + version "0.0.6" + resolved "https://registry.yarnpkg.com/buildcheck/-/buildcheck-0.0.6.tgz#89aa6e417cfd1e2196e3f8fe915eb709d2fe4238" + integrity sha512-8f9ZJCUXyT1M35Jx7MkBgmBMo3oHTTBIPLiY9xyL0pl3T5RwcPEY8cUHr5LBNfu/fk6c2T4DJZuVM/8ZZT2D2A== + builtin-modules@^1.0.0: version "1.1.1" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" @@ -1121,6 +1140,14 @@ core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" +cpu-features@~0.0.7: + version "0.0.8" + resolved "https://registry.yarnpkg.com/cpu-features/-/cpu-features-0.0.8.tgz#a2d464b023b8ad09004c8cdca23b33f192f63546" + integrity sha512-BbHBvtYhUhksqTjr6bhNOjGgMnhwhGTQmOoZGD+K7BCaQDCuZl/Ve1ZxUSMRwVC4D/rkCPQ2MAIeYzrWyK7eEg== + dependencies: + buildcheck "~0.0.6" + nan "^2.17.0" + cross-spawn@^5.0.0, cross-spawn@^5.0.1: version "5.1.0" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" @@ -1171,7 +1198,7 @@ debug@2.6.3, debug@^2.1.0, debug@^2.1.1, debug@^2.1.3, debug@^2.2.0: dependencies: ms "0.7.2" -debuglog@*, debuglog@^1.0.1: +debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" @@ -2488,7 +2515,7 @@ ignore@^3.2.0: version "3.2.6" resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.2.6.tgz#26e8da0644be0bb4cb39516f6c79f0e0f4ffe48c" -imurmurhash@*, imurmurhash@^0.1.4: +imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" @@ -2970,7 +2997,7 @@ lodash._basefor@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/lodash._basefor/-/lodash._basefor-3.0.3.tgz#7550b4e9218ef09fad24343b612021c79b4c20c2" -lodash._baseindexof@*, lodash._baseindexof@^3.0.0: +lodash._baseindexof@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c" @@ -2982,13 +3009,6 @@ lodash._baseisequal@^3.0.0: lodash.istypedarray "^3.0.0" lodash.keys "^3.0.0" -lodash._baseuniq@*: - version "4.6.0" - resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8" - dependencies: - lodash._createset "~4.0.0" - lodash._root "~3.0.0" - lodash._baseuniq@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-3.0.3.tgz#2123fa0db2d69c28d5beb1c1f36d61522a740234" @@ -2997,11 +3017,11 @@ lodash._baseuniq@^3.0.0: lodash._cacheindexof "^3.0.0" lodash._createcache "^3.0.0" -lodash._bindcallback@*, lodash._bindcallback@^3.0.0: +lodash._bindcallback@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e" -lodash._cacheindexof@*, lodash._cacheindexof@^3.0.0: +lodash._cacheindexof@^3.0.0: version "3.0.2" resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92" @@ -3013,17 +3033,13 @@ lodash._createassigner@^3.0.0: lodash._isiterateecall "^3.0.0" lodash.restparam "^3.0.0" -lodash._createcache@*, lodash._createcache@^3.0.0: +lodash._createcache@^3.0.0: version "3.1.2" resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093" dependencies: lodash._getnative "^3.0.0" -lodash._createset@~4.0.0: - version "4.0.3" - resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26" - -lodash._getnative@*, lodash._getnative@^3.0.0: +lodash._getnative@^3.0.0: version "3.9.1" resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" @@ -3035,10 +3051,6 @@ lodash._reinterpolate@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" -lodash._root@~3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692" - lodash.assign@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/lodash.assign/-/lodash.assign-3.2.0.tgz#3ce9f0234b4b2223e296b8fa0ac1fee8ebca64fa" @@ -3087,11 +3099,11 @@ lodash.flatten@^3.0.2: lodash._baseflatten "^3.0.0" lodash._isiterateecall "^3.0.0" -lodash.isarguments@*, lodash.isarguments@^3.0.0: +lodash.isarguments@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a" -lodash.isarray@*, lodash.isarray@^3.0.0: +lodash.isarray@^3.0.0: version "3.0.4" resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55" @@ -3107,7 +3119,7 @@ lodash.istypedarray@^3.0.0: version "3.0.6" resolved "https://registry.yarnpkg.com/lodash.istypedarray/-/lodash.istypedarray-3.0.6.tgz#c9a477498607501d8e8494d283b87c39281cef62" -lodash.keys@*, lodash.keys@^3.0.0: +lodash.keys@^3.0.0: version "3.1.2" resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a" dependencies: @@ -3164,7 +3176,7 @@ lodash.pairs@^3.0.0: dependencies: lodash.keys "^3.0.0" -lodash.restparam@*, lodash.restparam@^3.0.0: +lodash.restparam@^3.0.0: version "3.6.1" resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" @@ -3217,7 +3229,7 @@ lodash.without@~3.2.1: lodash._basedifference "^3.0.0" lodash.restparam "^3.0.0" -lodash@^3.10.0, lodash@^3.10.1, lodash@^3.5.0, lodash@^3.9.3: +lodash@^3.10.0, lodash@^3.10.1, lodash@^3.9.3: version "3.10.1" resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" @@ -3451,6 +3463,11 @@ mute-stream@0.0.6, mute-stream@~0.0.4: version "0.0.6" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.6.tgz#48962b19e169fd1dfc240b3f1e7317627bbc47db" +nan@^2.17.0: + version "2.17.0" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.17.0.tgz#c0150a2368a182f033e9aa5195ec76ea41a199cb" + integrity sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" @@ -4075,7 +4092,7 @@ read@1, read@~1.0.1, read@~1.0.7: string_decoder "~0.10.x" util-deprecate "~1.0.1" -readable-stream@~1.0.0, readable-stream@~1.0.2: +readable-stream@~1.0.2: version "1.0.34" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c" dependencies: @@ -4095,7 +4112,7 @@ readable-stream@~2.0.5: string_decoder "~0.10.x" util-deprecate "~1.0.1" -readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0: +readdir-scoped-modules@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747" dependencies: @@ -4336,6 +4353,11 @@ safe-json-parse@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/safe-json-parse/-/safe-json-parse-1.0.1.tgz#3e76723e38dfdda13c9b1d29a1e07ffee4b30b57" +safer-buffer@~2.1.0: + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== + sane@^1.1.1: version "1.6.0" resolved "https://registry.yarnpkg.com/sane/-/sane-1.6.0.tgz#9610c452307a135d29c1fdfe2547034180c46775" @@ -4581,20 +4603,16 @@ sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" -ssh2-streams@~0.0.22: - version "0.0.23" - resolved "https://registry.yarnpkg.com/ssh2-streams/-/ssh2-streams-0.0.23.tgz#aeef30831bb5fc4af6aa3f6d0a261a413531612b" +ssh2@^1.11.0: + version "1.13.0" + resolved "https://registry.yarnpkg.com/ssh2/-/ssh2-1.13.0.tgz#9b53a07534fa72283ada471b82395a3b3c875934" + integrity sha512-CIZBFRRY1y9mAZSqBGFE4EB4dNJad2ysT2PqO8OpkiI3UTB/gUZwE5EaN16qVyQ6s/M7EgC/iaV/MnjdlvnuzA== dependencies: - asn1 "~0.2.0" - readable-stream "~1.0.0" - streamsearch "~0.1.2" - -ssh2@^0.4.8: - version "0.4.15" - resolved "https://registry.yarnpkg.com/ssh2/-/ssh2-0.4.15.tgz#07c6f4106d9f7b6ea6e4df636c6c53f1f9817ff8" - dependencies: - readable-stream "~1.0.0" - ssh2-streams "~0.0.22" + asn1 "^0.2.6" + bcrypt-pbkdf "^1.0.2" + optionalDependencies: + cpu-features "~0.0.7" + nan "^2.17.0" sshpk@^1.7.0: version "1.11.0" @@ -4619,10 +4637,6 @@ stable@~0.1.3: version "1.3.1" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e" -streamsearch@~0.1.2: - version "0.1.2" - resolved "https://registry.yarnpkg.com/streamsearch/-/streamsearch-0.1.2.tgz#808b9d0e56fc273d809ba57338e929919a1a9f1a" - string-template@~0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/string-template/-/string-template-0.2.1.tgz#42932e598a352d01fc22ec3367d9d84eec6c9add" @@ -4658,18 +4672,18 @@ stringstream@~0.0.4: version "0.0.5" resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878" -strip-ansi@*, strip-ansi@^3.0.0, strip-ansi@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" - dependencies: - ansi-regex "^2.0.0" - strip-ansi@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.3.0.tgz#25f48ea22ca79187f3174a4db8759347bb126220" dependencies: ansi-regex "^0.2.1" +strip-ansi@^3.0.0, strip-ansi@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" + dependencies: + ansi-regex "^2.0.0" + strip-bom@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" @@ -4860,13 +4874,12 @@ tunnel-agent@~0.4.1: version "0.4.3" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.4.3.tgz#6373db76909fe570e08d73583365ed828a74eeeb" -tunnel-ssh@^1.0.1: - version "1.1.0" - resolved "https://registry.yarnpkg.com/tunnel-ssh/-/tunnel-ssh-1.1.0.tgz#2bf21f422448e979d60d590baa2da820ce852759" +tunnel-ssh@^5.0.5: + version "5.0.5" + resolved "https://registry.yarnpkg.com/tunnel-ssh/-/tunnel-ssh-5.0.5.tgz#c643dab6057aed8f5261a45868ec8f43764b4fb4" + integrity sha512-3W6q2hj8S3c6lvdlknpE0ew2jMsIPou8DdSeRDHK/WrA+d9jZlryXOc45yvmHpBv7MyoWHHZvs2IKEtHJFazeg== dependencies: - debug "^2.1.3" - lodash "^3.5.0" - ssh2 "^0.4.8" + ssh2 "^1.11.0" tweetnacl@^0.14.3, tweetnacl@~0.14.0: version "0.14.5" @@ -4986,7 +4999,7 @@ uuid@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1" -validate-npm-package-license@*, validate-npm-package-license@^3.0.1: +validate-npm-package-license@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc" dependencies: From f24ed3729a79ce97956a23c6abc7f38fe53c1fea Mon Sep 17 00:00:00 2001 From: Liam Potter Date: Fri, 1 Sep 2023 01:29:11 +0100 Subject: [PATCH 2/4] - add prettier - add ability to pass private key contents as well as file path - add password as an option - add passphrase as an option for protected private keys --- .prettierrc.js | 12 ++++++++++ index.js | 64 +++++++++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 24 deletions(-) create mode 100644 .prettierrc.js diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..4d8243e --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,12 @@ +'use strict'; + +module.exports = { + semi: true, + singleQuote: true, + useTabs: false, + quoteProps: 'consistent', + bracketSpacing: true, + arrowParens: 'always', + printWidth: 120, + trailingComma: 'none' +}; diff --git a/index.js b/index.js index e962dab..d1affd5 100644 --- a/index.js +++ b/index.js @@ -1,39 +1,47 @@ 'use strict'; -var RSVP = require('rsvp'); -var fs = require('fs'); -var { createTunnel } = require('tunnel-ssh'); -var untildify = require('untildify'); +const RSVP = require('rsvp'); +const fs = require('fs'); +const { createTunnel } = require('tunnel-ssh'); +const untildify = require('untildify'); -var DeployPluginBase = require('ember-cli-deploy-plugin'); +const DeployPluginBase = require('ember-cli-deploy-plugin'); -var MAX_PORT_NUMBER = 65535; -var MIN_PORT_NUMBER = 49151; +const MAX_PORT_NUMBER = 65535; +const MIN_PORT_NUMBER = 49151; module.exports = { name: 'ember-cli-deploy-ssh-tunnel', - - createDeployPlugin: function(options) { - var DeployPlugin = DeployPluginBase.extend({ + createDeployPlugin: function (options) { + const DeployPlugin = DeployPluginBase.extend({ name: options.name, defaultConfig: { - dstPort: 6379, - port: 22, - dstHost: 'localhost', - srcPort: function() { - var range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1; - return Math.floor(Math.random() * range) + MIN_PORT_NUMBER; - }, + dstPort: 6379, + port: 22, + dstHost: 'localhost', + srcPort: function () { + var range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1; + return Math.floor(Math.random() * range) + MIN_PORT_NUMBER; + } }, requiredConfig: ['host', 'username'], - setup: function(/* context */) { - var srcPort = this.readConfig('srcPort'); + setup: function (/* context */) { + const srcPort = this.readConfig('srcPort'); if (srcPort > MAX_PORT_NUMBER || srcPort < MIN_PORT_NUMBER) { - throw 'Port ' + srcPort + ' is not available to open a SSH connection on.\n' + 'Please choose a port between ' + MIN_PORT_NUMBER + ' and ' + MAX_PORT_NUMBER + '.'; + throw ( + 'Port ' + + srcPort + + ' is not available to open a SSH connection on.\n' + + 'Please choose a port between ' + + MIN_PORT_NUMBER + + ' and ' + + MAX_PORT_NUMBER + + '.' + ); } const tunnelOptions = { @@ -44,11 +52,19 @@ module.exports = { port: srcPort }; + let privateKey = this.readConfig('privateKey'); + + if (this.readConfig('privateKeyPath')) { + privateKey = fs.readFileSync(untildify(this.readConfig('privateKeyPath'))); + } + const sshOptions = { host: this.readConfig('host'), port: this.readConfig('port'), username: this.readConfig('username'), - privateKey: fs.readFileSync(untildify(this.readConfig('privateKeyPath'))) + password: this.readConfig('password'), + privateKey, + passphrase: this.readConfig('passphrase') }; const forwardOptions = { @@ -58,9 +74,9 @@ module.exports = { dstPort: this.readConfig('dstPort') }; - return new RSVP.Promise(function(resolve, reject) { + return new RSVP.Promise(function (resolve, reject) { createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions) - .then(([server, conn]) => { + .then(([server]) => { resolve({ tunnel: { handler: server, @@ -74,7 +90,7 @@ module.exports = { }); }, - teardown: function(context) { + teardown: function (context) { context.tunnel.handler.close(); } }); From 28236a2e79967edb9f4a71afbad7fc33f823c2fd Mon Sep 17 00:00:00 2001 From: Liam Potter Date: Mon, 25 Sep 2023 22:14:39 -0400 Subject: [PATCH 3/4] - add support for custom tunnel client --- index.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index d1affd5..6c70a50 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,17 @@ module.exports = { srcPort: function () { var range = MAX_PORT_NUMBER - MIN_PORT_NUMBER + 1; return Math.floor(Math.random() * range) + MIN_PORT_NUMBER; + }, + tunnelClient: function (context) { + // if you want to provide your own ssh client to be used instead of one from this plugin, + // must follow this signature + // createTunnel( + // tunnelOptions: TunnelOptions, + // serverOptions: ServerOptions, + // sshOptions: SshOptions, + // forwardOptions: ForwardOptions + // ): Promise<[Server, Client]>; + return context.tunnelClient || createTunnel; } }, @@ -44,6 +55,14 @@ module.exports = { ); } + const tunnel = this.readConfig('tunnelClient'); + + let privateKey = this.readConfig('privateKey'); + + if (this.readConfig('privateKeyPath')) { + privateKey = fs.readFileSync(untildify(this.readConfig('privateKeyPath'))); + } + const tunnelOptions = { autoClose: true }; @@ -52,12 +71,6 @@ module.exports = { port: srcPort }; - let privateKey = this.readConfig('privateKey'); - - if (this.readConfig('privateKeyPath')) { - privateKey = fs.readFileSync(untildify(this.readConfig('privateKeyPath'))); - } - const sshOptions = { host: this.readConfig('host'), port: this.readConfig('port'), @@ -75,7 +88,7 @@ module.exports = { }; return new RSVP.Promise(function (resolve, reject) { - createTunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions) + tunnel(tunnelOptions, serverOptions, sshOptions, forwardOptions) .then(([server]) => { resolve({ tunnel: { From 8f65f5aba297ed07e183cded0c40ea20d6e675fb Mon Sep 17 00:00:00 2001 From: Liam Potter Date: Mon, 25 Sep 2023 22:17:25 -0400 Subject: [PATCH 4/4] - add link to types for tunnel-ssh in comment --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 6c70a50..27f8d28 100644 --- a/index.js +++ b/index.js @@ -33,6 +33,7 @@ module.exports = { // sshOptions: SshOptions, // forwardOptions: ForwardOptions // ): Promise<[Server, Client]>; + // https://github.com/agebrock/tunnel-ssh/blob/master/types/index.d.ts return context.tunnelClient || createTunnel; } },