From 9e294d577a2e7d21892d2c08b4b9b23702db22f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Tue, 20 Mar 2018 18:57:37 +0100 Subject: [PATCH] Re-enable signer, even with no UI. (#8167) * Re-enable signer, even with no UI. * Fix message. --- parity/configuration.rs | 8 +++++++- parity/rpc.rs | 2 +- parity/run.rs | 4 ++-- parity/signer.rs | 29 ++++++++++++++++++++++------- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/parity/configuration.rs b/parity/configuration.rs index bbf27601e..e0b76ef95 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -891,6 +891,12 @@ impl Configuration { let ui = self.ui_config(); let http = self.http_config()?; + let support_token_api = + // never enabled for public node + !self.args.flag_public_node + // enabled when not unlocking unless the ui is forced + && (self.args.arg_unlock.is_none() || ui.enabled); + let conf = WsConfiguration { enabled: self.ws_enabled(), interface: self.ws_interface(), @@ -899,7 +905,7 @@ impl Configuration { hosts: self.ws_hosts(), origins: self.ws_origins(), signer_path: self.directories().signer.into(), - support_token_api: !self.args.flag_public_node, + support_token_api, ui_address: ui.address(), dapps_address: http.address(), }; diff --git a/parity/rpc.rs b/parity/rpc.rs index 2940e178e..41b10ba87 100644 --- a/parity/rpc.rs +++ b/parity/rpc.rs @@ -227,7 +227,7 @@ pub fn new_ws( let allowed_hosts = into_domains(with_domain(conf.hosts, domain, &Some(url.clone().into()), &None)); let signer_path; - let path = match conf.support_token_api && conf.ui_address.is_some() { + let path = match conf.support_token_api { true => { signer_path = ::signer::codes_path(&conf.signer_path); Some(signer_path.as_path()) diff --git a/parity/run.rs b/parity/run.rs index 03a5d6f80..033d92213 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -319,7 +319,7 @@ fn execute_light_impl(cmd: RunCmd, can_restart: bool, logger: Arc) false => Some(account_provider.clone()) }; - let signer_service = Arc::new(signer::new_service(&cmd.ws_conf, &cmd.ui_conf, &cmd.logger_config)); + let signer_service = Arc::new(signer::new_service(&cmd.ws_conf, &cmd.logger_config)); // the dapps server let (node_health, dapps_deps) = { diff --git a/parity/signer.rs b/parity/signer.rs index 8bdf18bd0..ab476ef9d 100644 --- a/parity/signer.rs +++ b/parity/signer.rs @@ -32,10 +32,10 @@ pub struct NewToken { pub message: String, } -pub fn new_service(ws_conf: &rpc::WsConfiguration, ui_conf: &rpc::UiConfiguration, logger_config: &LogConfig) -> rpc_apis::SignerService { - let signer_path = ws_conf.signer_path.clone(); +pub fn new_service(ws_conf: &rpc::WsConfiguration, logger_config: &LogConfig) -> rpc_apis::SignerService { let logger_config_color = logger_config.color; - let signer_enabled = ui_conf.enabled; + let signer_path = ws_conf.signer_path.clone(); + let signer_enabled = ws_conf.support_token_api; rpc_apis::SignerService::new(move || { generate_new_token(&signer_path, logger_config_color).map_err(|e| format!("{:?}", e)) @@ -56,6 +56,24 @@ pub fn execute(ws_conf: rpc::WsConfiguration, ui_conf: rpc::UiConfiguration, log pub fn generate_token_and_url(ws_conf: &rpc::WsConfiguration, ui_conf: &rpc::UiConfiguration, logger_config: &LogConfig) -> Result { let code = generate_new_token(&ws_conf.signer_path, logger_config.color).map_err(|err| format!("Error generating token: {:?}", err))?; let auth_url = format!("http://{}:{}/#/auth?token={}", ui_conf.interface, ui_conf.port, code); + let colored = |s: String| match logger_config.color { + true => format!("{}", White.bold().paint(s)), + false => s, + }; + + if !ui_conf.enabled { + return Ok(NewToken { + token: code.clone(), + url: auth_url.clone(), + message: format!( + r#" +Generated token: +{} +"#, + colored(code) + ), + }) + } // And print in to the console Ok(NewToken { @@ -67,10 +85,7 @@ Open: {} to authorize your browser. Or use the generated token: {}"#, - match logger_config.color { - true => format!("{}", White.bold().paint(auth_url)), - false => auth_url - }, + colored(auth_url), code ) })