Re-enable signer, even with no UI. (#8167)

* Re-enable signer, even with no UI.

* Fix message.
This commit is contained in:
Tomasz Drwięga 2018-03-20 18:57:37 +01:00 committed by André Silva
parent 6d5d419e14
commit 9e294d577a
4 changed files with 32 additions and 11 deletions

View File

@ -891,6 +891,12 @@ impl Configuration {
let ui = self.ui_config(); let ui = self.ui_config();
let http = self.http_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 { let conf = WsConfiguration {
enabled: self.ws_enabled(), enabled: self.ws_enabled(),
interface: self.ws_interface(), interface: self.ws_interface(),
@ -899,7 +905,7 @@ impl Configuration {
hosts: self.ws_hosts(), hosts: self.ws_hosts(),
origins: self.ws_origins(), origins: self.ws_origins(),
signer_path: self.directories().signer.into(), signer_path: self.directories().signer.into(),
support_token_api: !self.args.flag_public_node, support_token_api,
ui_address: ui.address(), ui_address: ui.address(),
dapps_address: http.address(), dapps_address: http.address(),
}; };

View File

@ -227,7 +227,7 @@ pub fn new_ws<D: rpc_apis::Dependencies>(
let allowed_hosts = into_domains(with_domain(conf.hosts, domain, &Some(url.clone().into()), &None)); let allowed_hosts = into_domains(with_domain(conf.hosts, domain, &Some(url.clone().into()), &None));
let signer_path; let signer_path;
let path = match conf.support_token_api && conf.ui_address.is_some() { let path = match conf.support_token_api {
true => { true => {
signer_path = ::signer::codes_path(&conf.signer_path); signer_path = ::signer::codes_path(&conf.signer_path);
Some(signer_path.as_path()) Some(signer_path.as_path())

View File

@ -319,7 +319,7 @@ fn execute_light_impl(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger
let rpc_stats = Arc::new(informant::RpcStats::default()); let rpc_stats = Arc::new(informant::RpcStats::default());
// the dapps server // the dapps server
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));
let (node_health, dapps_deps) = { let (node_health, dapps_deps) = {
let contract_client = ::dapps::LightRegistrar { let contract_client = ::dapps::LightRegistrar {
client: client.clone(), client: client.clone(),
@ -716,7 +716,7 @@ pub fn execute_impl(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>)
false => Some(account_provider.clone()) 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 // the dapps server
let (node_health, dapps_deps) = { let (node_health, dapps_deps) = {

View File

@ -32,10 +32,10 @@ pub struct NewToken {
pub message: String, pub message: String,
} }
pub fn new_service(ws_conf: &rpc::WsConfiguration, ui_conf: &rpc::UiConfiguration, logger_config: &LogConfig) -> rpc_apis::SignerService { pub fn new_service(ws_conf: &rpc::WsConfiguration, logger_config: &LogConfig) -> rpc_apis::SignerService {
let signer_path = ws_conf.signer_path.clone();
let logger_config_color = logger_config.color; 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 || { rpc_apis::SignerService::new(move || {
generate_new_token(&signer_path, logger_config_color).map_err(|e| format!("{:?}", e)) 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<NewToken, String> { pub fn generate_token_and_url(ws_conf: &rpc::WsConfiguration, ui_conf: &rpc::UiConfiguration, logger_config: &LogConfig) -> Result<NewToken, String> {
let code = generate_new_token(&ws_conf.signer_path, logger_config.color).map_err(|err| format!("Error generating token: {:?}", err))?; 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 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 // And print in to the console
Ok(NewToken { Ok(NewToken {
@ -67,10 +85,7 @@ Open: {}
to authorize your browser. to authorize your browser.
Or use the generated token: Or use the generated token:
{}"#, {}"#,
match logger_config.color { colored(auth_url),
true => format!("{}", White.bold().paint(auth_url)),
false => auth_url
},
code code
) )
}) })