From 8866f47805adac50ab72b866901ad86a72dc449b Mon Sep 17 00:00:00 2001 From: Eugene Mirotin Date: Wed, 26 Apr 2017 16:16:06 +0300 Subject: [PATCH] proxy support --- build/app.js | 14 +++- capitanodoc.coffee | 107 +++++++++++++++++++++++++++++++ capitanodoc.json | 109 -------------------------------- doc/cli.markdown | 14 ++++ extras/capitanodoc/index.coffee | 2 +- lib/app.coffee | 15 +++++ package.json | 2 + 7 files changed, 152 insertions(+), 111 deletions(-) create mode 100644 capitanodoc.coffee delete mode 100644 capitanodoc.json diff --git a/build/app.js b/build/app.js index 29574ef9..017dcff5 100644 --- a/build/app.js +++ b/build/app.js @@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -var Promise, Raven, _, actions, capitano, capitanoExecuteAsync, errors, events, plugins, resin, update; +var Promise, Raven, _, actions, capitano, capitanoExecuteAsync, errors, events, globalTunnel, plugins, proxy, resin, settings, update; Raven = require('raven'); @@ -29,6 +29,18 @@ Raven.config(require('./config').sentryDsn, { return process.exit(1); }); +globalTunnel = require('global-tunnel-ng'); + +settings = require('resin-settings-client'); + +try { + proxy = settings.get('proxy') || null; +} catch (error1) { + proxy = null; +} + +globalTunnel.initialize(proxy); + _ = require('lodash'); Promise = require('bluebird'); diff --git a/capitanodoc.coffee b/capitanodoc.coffee new file mode 100644 index 00000000..11b2fa46 --- /dev/null +++ b/capitanodoc.coffee @@ -0,0 +1,107 @@ +# coffeelint: disable=max_line_length + +module.exports = + title: 'Resin CLI Documentation' + introduction: ''' + This tool allows you to interact with the resin.io api from the comfort of your command line. + + Please make sure your system meets the requirements as specified in the [README](https://github.com/resin-io/resin-cli). + + To get started download the CLI from npm. + + $ npm install resin-cli -g + + Then authenticate yourself: + + $ resin login + + Now you have access to all the commands referenced below. + + ## Proxy support + + The CLI does support HTTP(S) proxies. + + You can configure the proxy using several methods (in order of their precedence): + + * set the `RESINRC_PROXY` environment variable in the URL format (with protocol, host, port, and optionally the basic auth), + * use the [resin config file](https://www.npmjs.com/package/resin-settings-client#documentation) (project-specific or user-level) + and set the `proxy` setting. This can be: + * a string in the URL format, + * or an object following [this format](https://www.npmjs.com/package/global-tunnel-ng#options), which allows more control, + * or set the conventional `https_proxy` / `HTTPS_PROXY` / `http_proxy` / `HTTP_PROXY` + environment variable (in the same standard URL format). + ''' + + categories: [ + { + title: 'Application' + files: [ 'lib/actions/app.coffee' ] + }, + { + title: 'Authentication', + files: [ 'lib/actions/auth.coffee' ] + }, + { + title: 'Device', + files: [ 'lib/actions/device.coffee' ] + }, + { + title: 'Environment Variables', + files: [ 'lib/actions/environment-variables.coffee' ] + }, + { + title: 'Help', + files: [ 'lib/actions/help.coffee' ] + }, + { + title: 'Information', + files: [ 'lib/actions/info.coffee' ] + }, + { + title: 'Keys', + files: [ 'lib/actions/keys.coffee' ] + }, + { + title: 'Logs', + files: [ 'lib/actions/logs.coffee' ] + }, + { + title: 'Sync', + files: [ 'lib/actions/sync.coffee' ] + }, + { + title: 'SSH', + files: [ 'lib/actions/ssh.coffee' ] + }, + { + title: 'Notes', + files: [ 'lib/actions/notes.coffee' ] + }, + { + title: 'OS', + files: [ 'lib/actions/os.coffee' ] + }, + { + title: 'Config', + files: [ 'lib/actions/config.coffee' ] + }, + { + title: 'Settings', + files: [ 'lib/actions/settings.coffee' ] + }, + { + title: 'Wizard', + files: [ 'lib/actions/wizard.coffee' ] + }, + { + title: 'Local', + files: [ 'lib/actions/local/index.coffee' ] + }, + { + title: 'Deploy', + files: [ + 'lib/actions/build.coffee' + 'lib/actions/deploy.coffee' + ] + } + ] diff --git a/capitanodoc.json b/capitanodoc.json deleted file mode 100644 index f0f8e932..00000000 --- a/capitanodoc.json +++ /dev/null @@ -1,109 +0,0 @@ -{ - "title": "Resin CLI Documentation", - "introduction": "This tool allows you to interact with the resin.io api from the comfort of your command line.\n\nPlease make sure your system meets the requirements as specified in the [README](https://github.com/resin-io/resin-cli).\n\nTo get started download the CLI from npm.\n\n\t$ npm install resin-cli -g\n\nThen authenticate yourself:\n\n\t$ resin login\n\nNow you have access to all the commands referenced below.", - "categories": [ - { - "title": "Application", - "files": [ - "lib/actions/app.coffee" - ] - }, - { - "title": "Authentication", - "files": [ - "lib/actions/auth.coffee" - ] - }, - { - "title": "Device", - "files": [ - "lib/actions/device.coffee" - ] - }, - { - "title": "Environment Variables", - "files": [ - "lib/actions/environment-variables.coffee" - ] - }, - { - "title": "Help", - "files": [ - "lib/actions/help.coffee" - ] - }, - { - "title": "Information", - "files": [ - "lib/actions/info.coffee" - ] - }, - { - "title": "Keys", - "files": [ - "lib/actions/keys.coffee" - ] - }, - { - "title": "Logs", - "files": [ - "lib/actions/logs.coffee" - ] - }, - { - "title": "Sync", - "files": [ - "lib/actions/sync.coffee" - ] - }, - { - "title": "SSH", - "files": [ - "lib/actions/ssh.coffee" - ] - }, - { - "title": "Notes", - "files": [ - "lib/actions/notes.coffee" - ] - }, - { - "title": "OS", - "files": [ - "lib/actions/os.coffee" - ] - }, - { - "title": "Config", - "files": [ - "lib/actions/config.coffee" - ] - }, - { - "title": "Settings", - "files": [ - "lib/actions/settings.coffee" - ] - }, - { - "title": "Wizard", - "files": [ - "lib/actions/wizard.coffee" - ] - }, - { - "title": "Local", - "files": [ - "lib/actions/local/index.coffee" - ] - }, - { - "title": "Deploy", - "files": [ - "lib/actions/build.coffee", - "lib/actions/deploy.coffee" - ] - } - ] -} diff --git a/doc/cli.markdown b/doc/cli.markdown index 1e93ea5b..385b42ae 100644 --- a/doc/cli.markdown +++ b/doc/cli.markdown @@ -14,6 +14,20 @@ Then authenticate yourself: Now you have access to all the commands referenced below. +## Proxy support + +The CLI does support HTTP(S) proxies. + +You can configure the proxy using several methods (in order of their precedence): + +* set the `RESINRC_PROXY` environment variable in the URL format (with protocol, host, port, and optionally the basic auth), +* use the [resin config file](https://www.npmjs.com/package/resin-settings-client#documentation) (project-specific or user-level) +and set the `proxy` setting. This can be: + * a string in the URL format, + * or an object following [this format](https://www.npmjs.com/package/global-tunnel-ng#options), which allows more control, +* or set the conventional `https_proxy` / `HTTPS_PROXY` / `http_proxy` / `HTTP_PROXY` +environment variable (in the same standard URL format). + # Table of contents - Application diff --git a/extras/capitanodoc/index.coffee b/extras/capitanodoc/index.coffee index ea68a1e3..c2f2223b 100644 --- a/extras/capitanodoc/index.coffee +++ b/extras/capitanodoc/index.coffee @@ -1,6 +1,6 @@ _ = require('lodash') path = require('path') -capitanodoc = require('../../capitanodoc.json') +capitanodoc = require('../../capitanodoc') markdown = require('./markdown') result = {} diff --git a/lib/app.coffee b/lib/app.coffee index 3fa78cbb..e1a07c38 100644 --- a/lib/app.coffee +++ b/lib/app.coffee @@ -23,6 +23,21 @@ Raven.config require('./config').sentryDsn, console.error(error) process.exit(1) + +# Doing this before requiring any other modules, +# including the 'resin-sdk', to prevent any module from reading the http proxy config +# before us +globalTunnel = require('global-tunnel-ng') +settings = require('resin-settings-client') +try + proxy = settings.get('proxy') or null +catch + proxy = null +# Init the tunnel even if the proxy is not configured +# because it can also get the proxy from the http(s)_proxy env var +# If that is not set as well the initialize will do nothing +globalTunnel.initialize(proxy) + _ = require('lodash') Promise = require('bluebird') capitano = require('capitano') diff --git a/package.json b/package.json index ce3b792c..d05afd8c 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "dockerode": "^2.4.2", "drivelist": "^5.0.16", "etcher-image-write": "^9.0.3", + "global-tunnel-ng": "^2.0.0", "inquirer": "^3.0.6", "is-root": "^1.0.0", "js-yaml": "^3.7.0", @@ -73,6 +74,7 @@ "resin-image-fs": "^2.1.2", "resin-image-manager": "^4.1.1", "resin-sdk-preconfigured": "^6.0.0", + "resin-settings-client": "^3.6.1", "resin-stream-logger": "^0.0.4", "resin-sync": "^7.0.0", "rimraf": "^2.4.3",