From 34f5f97b28cdac5ac165354c52a8a0ac209872d1 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 10 Jan 2019 10:47:23 +0000 Subject: [PATCH] feat: add option --no-single-use-cockpit-token This option is added to run and console. This can be usefull while developing on cockpit, the auto reload don't always ask to authenticate --- src/cmd/cmd.js | 6 +++++- src/cmd/cmd_controller.js | 2 ++ src/lib/core/engine.js | 3 ++- src/lib/modules/authenticator/index.js | 16 +++++++++++----- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/cmd/cmd.js b/src/cmd/cmd.js index ba0efe133..5b745eabe 100644 --- a/src/cmd/cmd.js +++ b/src/cmd/cmd.js @@ -142,6 +142,7 @@ class Cmd { .option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug') .option('--locale [locale]', __('language to use (default: en)')) .option('--pipeline [pipeline]', __('webpack config to use (default: development)')) + .option('--no-single-use-auth-token', __('disable the single use of token in cockpit')) .description(__('run dapp (default: %s)', 'development')) .action(function(env, options) { i18n.setOrDetectLocale(options.locale); @@ -156,7 +157,8 @@ class Cmd { logFile: options.logfile, logLevel: options.loglevel, webpackConfigName: options.pipeline || 'development', - openBrowser: !options.nobrowser ? null : false + openBrowser: !options.nobrowser ? null : false, + singleUseAuthToken: options.singleUseAuthToken }); }); } @@ -169,6 +171,7 @@ class Cmd { .option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug') .option('--locale [locale]', __('language to use (default: en)')) .option('--pipeline [pipeline]', __('webpack config to use (default: development)')) + .option('--no-single-use-auth-token', __('disable the single use of token in cockpit')) .description(__('Start the Embark console')) .action(function(env, options) { i18n.setOrDetectLocale(options.locale); @@ -178,6 +181,7 @@ class Cmd { locale: options.locale, logFile: options.logfile, logLevel: options.loglevel, + singleUseAuthToken: options.singleUseAuthToken, webpackConfigName: options.pipeline || 'development' }); }); diff --git a/src/cmd/cmd_controller.js b/src/cmd/cmd_controller.js index 273556872..db4793818 100644 --- a/src/cmd/cmd_controller.js +++ b/src/cmd/cmd_controller.js @@ -94,6 +94,7 @@ class EmbarkController { useDashboard: options.useDashboard, webServerConfig: webServerConfig, webpackConfigName: options.webpackConfigName, + singleUseAuthToken: options.singleUseAuthToken, ipcRole: 'server' }); @@ -273,6 +274,7 @@ class EmbarkController { logFile: options.logFile, logLevel: options.logLevel, context: this.context, + singleUseAuthToken: options.singleUseAuthToken, webpackConfigName: options.webpackConfigName }); diff --git a/src/lib/core/engine.js b/src/lib/core/engine.js index 850ea64b7..793b771de 100644 --- a/src/lib/core/engine.js +++ b/src/lib/core/engine.js @@ -18,6 +18,7 @@ class Engine { this.useDashboard = options.useDashboard; this.webServerConfig = options.webServerConfig; this.webpackConfigName = options.webpackConfigName; + this.singleUseAuthToken = options.singleUseAuthToken; this.ipcRole = options.ipcRole || 'client'; } @@ -258,7 +259,7 @@ class Engine { } cockpitService() { - this.registerModule('authenticator'); + this.registerModule('authenticator', {singleUseAuthToken: this.singleUseAuthToken}); this.registerModule('api', {plugins: this.plugins}); } diff --git a/src/lib/modules/authenticator/index.js b/src/lib/modules/authenticator/index.js index 29f8990d3..8b2b6b12e 100644 --- a/src/lib/modules/authenticator/index.js +++ b/src/lib/modules/authenticator/index.js @@ -5,10 +5,11 @@ const keccak = require('keccakjs'); const ERROR_OBJ = {error: __('Wrong authentication token. Get your token from the Embark console by typing `token`')}; class Authenticator { - constructor(embark, _options) { + constructor(embark, options) { this.embark = embark; this.logger = embark.logger; this.events = embark.events; + this.singleUseToken = options.singleUseAuthToken; this.authToken = uuid(); this.emittedTokens = {}; @@ -58,12 +59,17 @@ class Authenticator { return res.send(ERROR_OBJ); } - // Generate another authentication token. - this.authToken = uuid(); - this.events.request('authenticator:displayUrl', false); + let emittedToken; + if (this.singleUseToken) { + // Generate another authentication token. + this.authToken = uuid(); + this.events.request('authenticator:displayUrl', false); + emittedToken = uuid(); + } else { + emittedToken = this.authToken; + } // Register token for this connection, and send it through. - const emittedToken = uuid(); const remoteAddress = this.getRemoteAddress(req); this.emittedTokens[remoteAddress] = emittedToken; res.send({token: emittedToken});