Remove UI related settings from CLI (#8783)
* Remove all ui reference in dapps interface * Pass primary cli build * Add back parity wallet dapp as builtin * Clean up ui settings * Fix all tests in cli * Missed ui files to commit * Add parity-utils endpoint back * Fix non-dapp feature compiling * Inline styles * Remove parity-utils endpoint * Remove ui precompiled crate * Remove parity-ui alltogether * Remove ui feature flags * Move errors to static methods * Fix tests * Remove all reference to utils endpoint and remove server side injection According to https://github.com/paritytech/parity/pull/8539, inject.js is already handled by Parity UI.
This commit is contained in:
@@ -26,10 +26,6 @@ usage! {
|
||||
// Arguments must start with arg_
|
||||
// Flags must start with flag_
|
||||
|
||||
CMD cmd_ui {
|
||||
"Manage ui",
|
||||
}
|
||||
|
||||
CMD cmd_dapp
|
||||
{
|
||||
"Manage dapps",
|
||||
@@ -376,35 +372,10 @@ usage! {
|
||||
"Provide a file containing passwords for unlocking accounts (signer, private account, validators).",
|
||||
|
||||
["UI options"]
|
||||
FLAG flag_force_ui: (bool) = false, or |c: &Config| c.ui.as_ref()?.force.clone(),
|
||||
"--force-ui",
|
||||
"Enable Trusted UI WebSocket endpoint, even when --unlock is in use.",
|
||||
|
||||
FLAG flag_no_ui: (bool) = false, or |c: &Config| c.ui.as_ref()?.disable.clone(),
|
||||
"--no-ui",
|
||||
"Disable Trusted UI WebSocket endpoint.",
|
||||
|
||||
// NOTE [todr] For security reasons don't put this to config files
|
||||
FLAG flag_ui_no_validation: (bool) = false, or |_| None,
|
||||
"--ui-no-validation",
|
||||
"Disable Origin and Host headers validation for Trusted UI. WARNING: INSECURE. Used only for development.",
|
||||
|
||||
ARG arg_ui_interface: (String) = "local", or |c: &Config| c.ui.as_ref()?.interface.clone(),
|
||||
"--ui-interface=[IP]",
|
||||
"Specify the hostname portion of the Trusted UI server, IP should be an interface's IP address, or local.",
|
||||
|
||||
ARG arg_ui_hosts: (String) = "none", or |c: &Config| c.ui.as_ref()?.hosts.as_ref().map(|vec| vec.join(",")),
|
||||
"--ui-hosts=[HOSTS]",
|
||||
"List of allowed Host header values. This option will validate the Host header sent by the browser, it is additional security against some attack vectors. Special options: \"all\", \"none\",.",
|
||||
|
||||
ARG arg_ui_path: (String) = "$BASE/signer", or |c: &Config| c.ui.as_ref()?.path.clone(),
|
||||
"--ui-path=[PATH]",
|
||||
"Specify directory where Trusted UIs tokens should be stored.",
|
||||
|
||||
ARG arg_ui_port: (u16) = 8180u16, or |c: &Config| c.ui.as_ref()?.port.clone(),
|
||||
"--ui-port=[PORT]",
|
||||
"Specify the port of Trusted UI server.",
|
||||
|
||||
["Networking options"]
|
||||
FLAG flag_no_warp: (bool) = false, or |c: &Config| c.network.as_ref()?.warp.clone().map(|w| !w),
|
||||
"--no-warp",
|
||||
@@ -948,6 +919,30 @@ usage! {
|
||||
"--public-node",
|
||||
"Does nothing; Public node is removed from Parity.",
|
||||
|
||||
FLAG flag_force_ui: (bool) = false, or |_| None,
|
||||
"--force-ui",
|
||||
"Does nothing; UI is now a separate project.",
|
||||
|
||||
FLAG flag_no_ui: (bool) = false, or |_| None,
|
||||
"--no-ui",
|
||||
"Does nothing; UI is now a separate project.",
|
||||
|
||||
FLAG flag_ui_no_validation: (bool) = false, or |_| None,
|
||||
"--ui-no-validation",
|
||||
"Does nothing; UI is now a separate project.",
|
||||
|
||||
ARG arg_ui_interface: (String) = "local", or |_| None,
|
||||
"--ui-interface=[IP]",
|
||||
"Does nothing; UI is now a separate project.",
|
||||
|
||||
ARG arg_ui_hosts: (String) = "none", or |_| None,
|
||||
"--ui-hosts=[HOSTS]",
|
||||
"Does nothing; UI is now a separate project.",
|
||||
|
||||
ARG arg_ui_port: (u16) = 8180u16, or |_| None,
|
||||
"--ui-port=[PORT]",
|
||||
"Does nothing; UI is now a separate project.",
|
||||
|
||||
ARG arg_dapps_port: (Option<u16>) = None, or |c: &Config| c.dapps.as_ref()?.port.clone(),
|
||||
"--dapps-port=[PORT]",
|
||||
"Dapps server is merged with RPC server. Use --jsonrpc-port.",
|
||||
@@ -1111,12 +1106,18 @@ struct PrivateTransactions {
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct Ui {
|
||||
force: Option<bool>,
|
||||
disable: Option<bool>,
|
||||
port: Option<u16>,
|
||||
interface: Option<String>,
|
||||
hosts: Option<Vec<String>>,
|
||||
path: Option<String>,
|
||||
|
||||
#[serde(rename="force")]
|
||||
_legacy_force: Option<bool>,
|
||||
#[serde(rename="disable")]
|
||||
_legacy_disable: Option<bool>,
|
||||
#[serde(rename="port")]
|
||||
_legacy_port: Option<u16>,
|
||||
#[serde(rename="interface")]
|
||||
_legacy_interface: Option<String>,
|
||||
#[serde(rename="hosts")]
|
||||
_legacy_hosts: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, PartialEq, Deserialize)]
|
||||
@@ -1404,15 +1405,13 @@ mod tests {
|
||||
let args = Args::parse(&["parity", "--secretstore-nodes", "abc@127.0.0.1:3333,cde@10.10.10.10:4444"]).unwrap();
|
||||
assert_eq!(args.arg_secretstore_nodes, "abc@127.0.0.1:3333,cde@10.10.10.10:4444");
|
||||
|
||||
let args = Args::parse(&["parity", "--password", "~/.safe/1", "--password", "~/.safe/2", "--ui-port", "8123", "ui"]).unwrap();
|
||||
let args = Args::parse(&["parity", "--password", "~/.safe/1", "--password", "~/.safe/2", "--ui-port", "8123"]).unwrap();
|
||||
assert_eq!(args.arg_password, vec!["~/.safe/1".to_owned(), "~/.safe/2".to_owned()]);
|
||||
assert_eq!(args.arg_ui_port, 8123);
|
||||
assert_eq!(args.cmd_ui, true);
|
||||
|
||||
let args = Args::parse(&["parity", "--password", "~/.safe/1,~/.safe/2", "--ui-port", "8123", "ui"]).unwrap();
|
||||
let args = Args::parse(&["parity", "--password", "~/.safe/1,~/.safe/2", "--ui-port", "8123"]).unwrap();
|
||||
assert_eq!(args.arg_password, vec!["~/.safe/1".to_owned(), "~/.safe/2".to_owned()]);
|
||||
assert_eq!(args.arg_ui_port, 8123);
|
||||
assert_eq!(args.cmd_ui, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1476,7 +1475,6 @@ mod tests {
|
||||
// then
|
||||
assert_eq!(args, Args {
|
||||
// Commands
|
||||
cmd_ui: false,
|
||||
cmd_dapp: false,
|
||||
cmd_daemon: false,
|
||||
cmd_account: false,
|
||||
@@ -1566,7 +1564,7 @@ mod tests {
|
||||
flag_force_ui: false,
|
||||
flag_no_ui: false,
|
||||
arg_ui_port: 8180u16,
|
||||
arg_ui_interface: "127.0.0.1".into(),
|
||||
arg_ui_interface: "local".into(),
|
||||
arg_ui_hosts: "none".into(),
|
||||
arg_ui_path: "$HOME/.parity/signer".into(),
|
||||
flag_ui_no_validation: false,
|
||||
@@ -1820,12 +1818,12 @@ mod tests {
|
||||
fast_unlock: None,
|
||||
}),
|
||||
ui: Some(Ui {
|
||||
force: None,
|
||||
disable: Some(true),
|
||||
port: None,
|
||||
interface: None,
|
||||
hosts: None,
|
||||
path: None,
|
||||
_legacy_force: None,
|
||||
_legacy_disable: Some(true),
|
||||
_legacy_port: None,
|
||||
_legacy_interface: None,
|
||||
_legacy_hosts: None,
|
||||
}),
|
||||
network: Some(Network {
|
||||
warp: Some(false),
|
||||
|
||||
@@ -20,7 +20,6 @@ use std::net::SocketAddr;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::collections::BTreeMap;
|
||||
use std::cmp;
|
||||
use std::str::FromStr;
|
||||
use cli::{Args, ArgsError};
|
||||
use hash::keccak;
|
||||
use ethereum_types::{U256, H256, Address};
|
||||
@@ -34,7 +33,7 @@ use ethcore::miner::{stratum, MinerOptions};
|
||||
use ethcore::verification::queue::VerifierSettings;
|
||||
use miner::pool;
|
||||
|
||||
use rpc::{IpcConfiguration, HttpConfiguration, WsConfiguration, UiConfiguration};
|
||||
use rpc::{IpcConfiguration, HttpConfiguration, WsConfiguration};
|
||||
use parity_rpc::NetworkSettings;
|
||||
use cache::CacheConfig;
|
||||
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_queue_strategy, to_queue_penalization, passwords_from_files};
|
||||
@@ -65,7 +64,7 @@ pub enum Cmd {
|
||||
Account(AccountCmd),
|
||||
ImportPresaleWallet(ImportWallet),
|
||||
Blockchain(BlockchainCmd),
|
||||
SignerToken(WsConfiguration, UiConfiguration, LogConfig),
|
||||
SignerToken(WsConfiguration, LogConfig),
|
||||
SignerSign {
|
||||
id: Option<usize>,
|
||||
pwfile: Option<PathBuf>,
|
||||
@@ -130,7 +129,6 @@ impl Configuration {
|
||||
let http_conf = self.http_config()?;
|
||||
let ipc_conf = self.ipc_config()?;
|
||||
let net_conf = self.net_config()?;
|
||||
let ui_conf = self.ui_config();
|
||||
let network_id = self.network_id();
|
||||
let cache_config = self.cache_config();
|
||||
let tracing = self.args.arg_tracing.parse()?;
|
||||
@@ -150,7 +148,7 @@ impl Configuration {
|
||||
let authfile = ::signer::codes_path(&ws_conf.signer_path);
|
||||
|
||||
if self.args.cmd_signer_new_token {
|
||||
Cmd::SignerToken(ws_conf, ui_conf, logger_config.clone())
|
||||
Cmd::SignerToken(ws_conf, logger_config.clone())
|
||||
} else if self.args.cmd_signer_sign {
|
||||
let pwfile = self.accounts_config()?.password_files.first().map(|pwfile| {
|
||||
PathBuf::from(pwfile)
|
||||
@@ -381,13 +379,11 @@ impl Configuration {
|
||||
net_settings: self.network_settings()?,
|
||||
dapps_conf: dapps_conf,
|
||||
ipfs_conf: ipfs_conf,
|
||||
ui_conf: ui_conf,
|
||||
secretstore_conf: secretstore_conf,
|
||||
private_provider_conf: private_provider_conf,
|
||||
private_encryptor_conf: private_enc_conf,
|
||||
private_tx_enabled,
|
||||
dapp: self.dapp_to_open()?,
|
||||
ui: self.args.cmd_ui,
|
||||
name: self.args.arg_identity,
|
||||
custom_bootnodes: self.args.arg_bootnodes.is_some(),
|
||||
no_periodic_snapshot: self.args.flag_no_periodic_snapshot,
|
||||
@@ -588,29 +584,11 @@ impl Configuration {
|
||||
})
|
||||
}
|
||||
|
||||
fn ui_port(&self) -> u16 {
|
||||
self.args.arg_ports_shift + self.args.arg_ui_port
|
||||
}
|
||||
|
||||
fn ntp_servers(&self) -> Vec<String> {
|
||||
self.args.arg_ntp_servers.split(",").map(str::to_owned).collect()
|
||||
}
|
||||
|
||||
fn ui_config(&self) -> UiConfiguration {
|
||||
let ui = self.ui_enabled();
|
||||
UiConfiguration {
|
||||
enabled: ui.enabled,
|
||||
interface: self.ui_interface(),
|
||||
port: self.ui_port(),
|
||||
hosts: self.ui_hosts(),
|
||||
info_page_only: ui.info_page_only,
|
||||
}
|
||||
}
|
||||
|
||||
fn dapps_config(&self) -> DappsConfiguration {
|
||||
let dev_ui = if self.args.flag_ui_no_validation { vec![("127.0.0.1".to_owned(), 3000)] } else { vec![] };
|
||||
let ui_port = self.ui_port();
|
||||
|
||||
DappsConfiguration {
|
||||
enabled: self.dapps_enabled(),
|
||||
dapps_path: PathBuf::from(self.directories().dapps),
|
||||
@@ -619,31 +597,6 @@ impl Configuration {
|
||||
} else {
|
||||
vec![]
|
||||
},
|
||||
extra_embed_on: {
|
||||
let mut extra_embed = dev_ui.clone();
|
||||
match self.ui_hosts() {
|
||||
// In case host validation is disabled allow all frame ancestors
|
||||
None => {
|
||||
// NOTE Chrome does not seem to support "*:<port>"
|
||||
// we use `http(s)://*:<port>` instead.
|
||||
extra_embed.push(("http://*".to_owned(), ui_port));
|
||||
extra_embed.push(("https://*".to_owned(), ui_port));
|
||||
},
|
||||
Some(hosts) => extra_embed.extend(hosts.into_iter().filter_map(|host| {
|
||||
let mut it = host.split(":");
|
||||
let host = it.next();
|
||||
let port = it.next().and_then(|v| u16::from_str(v).ok());
|
||||
|
||||
match (host, port) {
|
||||
(Some(host), Some(port)) => Some((host.into(), port)),
|
||||
(Some(host), None) => Some((host.into(), ui_port)),
|
||||
_ => None,
|
||||
}
|
||||
})),
|
||||
}
|
||||
extra_embed
|
||||
},
|
||||
extra_script_src: dev_ui,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -863,10 +816,6 @@ impl Configuration {
|
||||
Some(hosts)
|
||||
}
|
||||
|
||||
fn ui_hosts(&self) -> Option<Vec<String>> {
|
||||
self.hosts(&self.args.arg_ui_hosts, &self.ui_interface())
|
||||
}
|
||||
|
||||
fn rpc_hosts(&self) -> Option<Vec<String>> {
|
||||
self.hosts(&self.args.arg_jsonrpc_hosts, &self.rpc_interface())
|
||||
}
|
||||
@@ -876,7 +825,7 @@ impl Configuration {
|
||||
}
|
||||
|
||||
fn ws_origins(&self) -> Option<Vec<String>> {
|
||||
if self.args.flag_unsafe_expose || self.args.flag_ui_no_validation {
|
||||
if self.args.flag_unsafe_expose {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -925,7 +874,6 @@ impl Configuration {
|
||||
}
|
||||
|
||||
fn ws_config(&self) -> Result<WsConfiguration, String> {
|
||||
let ui = self.ui_config();
|
||||
let http = self.http_config()?;
|
||||
|
||||
let support_token_api =
|
||||
@@ -941,7 +889,6 @@ impl Configuration {
|
||||
origins: self.ws_origins(),
|
||||
signer_path: self.directories().signer.into(),
|
||||
support_token_api,
|
||||
ui_address: ui.address(),
|
||||
dapps_address: http.address(),
|
||||
max_connections: self.args.arg_ws_max_connections,
|
||||
};
|
||||
@@ -1065,10 +1012,6 @@ impl Configuration {
|
||||
}.into()
|
||||
}
|
||||
|
||||
fn ui_interface(&self) -> String {
|
||||
self.interface(&self.args.arg_ui_interface)
|
||||
}
|
||||
|
||||
fn rpc_interface(&self) -> String {
|
||||
let rpc_interface = self.args.arg_rpcaddr.clone().unwrap_or(self.args.arg_jsonrpc_interface.clone());
|
||||
self.interface(&rpc_interface)
|
||||
@@ -1184,24 +1127,6 @@ impl Configuration {
|
||||
into_secretstore_service_contract_address(self.args.arg_secretstore_doc_sretr_contract.as_ref())
|
||||
}
|
||||
|
||||
fn ui_enabled(&self) -> UiEnabled {
|
||||
if self.args.flag_force_ui {
|
||||
return UiEnabled {
|
||||
enabled: true,
|
||||
info_page_only: false,
|
||||
};
|
||||
}
|
||||
|
||||
let ui_disabled = self.args.arg_unlock.is_some() ||
|
||||
self.args.flag_geth ||
|
||||
self.args.flag_no_ui;
|
||||
|
||||
return UiEnabled {
|
||||
enabled: (self.args.cmd_ui || !ui_disabled) && cfg!(feature = "ui-enabled"),
|
||||
info_page_only: !self.args.cmd_ui,
|
||||
}
|
||||
}
|
||||
|
||||
fn verifier_settings(&self) -> VerifierSettings {
|
||||
let mut settings = VerifierSettings::default();
|
||||
settings.scale_verifiers = self.args.flag_scale_verifiers;
|
||||
@@ -1220,12 +1145,6 @@ impl Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
struct UiEnabled {
|
||||
pub enabled: bool,
|
||||
pub info_page_only: bool,
|
||||
}
|
||||
|
||||
fn into_secretstore_service_contract_address(s: &str) -> Result<Option<SecretStoreContractAddress>, String> {
|
||||
match s {
|
||||
"none" => Ok(None),
|
||||
@@ -1254,7 +1173,7 @@ mod tests {
|
||||
use helpers::{default_network_config};
|
||||
use params::SpecType;
|
||||
use presale::ImportWallet;
|
||||
use rpc::{WsConfiguration, UiConfiguration};
|
||||
use rpc::WsConfiguration;
|
||||
use rpc_apis::ApiSet;
|
||||
use run::RunCmd;
|
||||
|
||||
@@ -1438,16 +1357,9 @@ mod tests {
|
||||
origins: Some(vec!["parity://*".into(),"chrome-extension://*".into(), "moz-extension://*".into()]),
|
||||
hosts: Some(vec![]),
|
||||
signer_path: expected.into(),
|
||||
ui_address: Some("127.0.0.1:8180".into()),
|
||||
dapps_address: Some("127.0.0.1:8545".into()),
|
||||
support_token_api: true,
|
||||
max_connections: 100,
|
||||
}, UiConfiguration {
|
||||
enabled: true,
|
||||
interface: "127.0.0.1".into(),
|
||||
port: 8180,
|
||||
hosts: Some(vec![]),
|
||||
info_page_only: true,
|
||||
}, LogConfig {
|
||||
color: true,
|
||||
mode: None,
|
||||
@@ -1516,12 +1428,10 @@ mod tests {
|
||||
net_settings: Default::default(),
|
||||
dapps_conf: Default::default(),
|
||||
ipfs_conf: Default::default(),
|
||||
ui_conf: Default::default(),
|
||||
secretstore_conf: Default::default(),
|
||||
private_provider_conf: Default::default(),
|
||||
private_encryptor_conf: Default::default(),
|
||||
private_tx_enabled: false,
|
||||
ui: false,
|
||||
dapp: None,
|
||||
name: "".into(),
|
||||
custom_bootnodes: false,
|
||||
@@ -1704,49 +1614,6 @@ mod tests {
|
||||
assert_eq!(conf2.ipfs_cors(), Some(vec!["http://parity.io".into(),"http://something.io".into()]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_disable_signer_in_geth_compat() {
|
||||
// given
|
||||
|
||||
// when
|
||||
let conf0 = parse(&["parity", "--geth"]);
|
||||
let conf1 = parse(&["parity", "--geth", "--force-ui"]);
|
||||
let conf2 = parse(&["parity", "--geth", "ui"]);
|
||||
let conf3 = parse(&["parity"]);
|
||||
|
||||
// then
|
||||
assert_eq!(conf0.ui_enabled(), UiEnabled {
|
||||
enabled: false,
|
||||
info_page_only: true,
|
||||
});
|
||||
assert_eq!(conf1.ui_enabled(), UiEnabled {
|
||||
enabled: true,
|
||||
info_page_only: false,
|
||||
});
|
||||
assert_eq!(conf2.ui_enabled(), UiEnabled {
|
||||
enabled: true,
|
||||
info_page_only: false,
|
||||
});
|
||||
assert_eq!(conf3.ui_enabled(), UiEnabled {
|
||||
enabled: true,
|
||||
info_page_only: true,
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_disable_signer_when_account_is_unlocked() {
|
||||
// given
|
||||
|
||||
// when
|
||||
let conf0 = parse(&["parity", "--unlock", "0x0"]);
|
||||
|
||||
// then
|
||||
assert_eq!(conf0.ui_enabled(), UiEnabled {
|
||||
enabled: false,
|
||||
info_page_only: true,
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_parse_ui_configuration() {
|
||||
// given
|
||||
@@ -1757,69 +1624,22 @@ mod tests {
|
||||
let conf2 = parse(&["parity", "--ui-path=signer", "--ui-port", "3123"]);
|
||||
let conf3 = parse(&["parity", "--ui-path=signer", "--ui-interface", "test"]);
|
||||
let conf4 = parse(&["parity", "--ui-path=signer", "--force-ui"]);
|
||||
let conf5 = parse(&["parity", "--ui-path=signer", "ui"]);
|
||||
|
||||
// then
|
||||
assert_eq!(conf0.directories().signer, "signer".to_owned());
|
||||
assert_eq!(conf0.ui_config(), UiConfiguration {
|
||||
enabled: true,
|
||||
interface: "127.0.0.1".into(),
|
||||
port: 8180,
|
||||
hosts: Some(vec![]),
|
||||
info_page_only: true,
|
||||
});
|
||||
|
||||
assert!(conf1.ws_config().unwrap().hosts.is_some());
|
||||
assert_eq!(conf1.ws_config().unwrap().origins, None);
|
||||
assert_eq!(conf1.ws_config().unwrap().origins, Some(vec!["parity://*".into(), "chrome-extension://*".into(), "moz-extension://*".into()]));
|
||||
assert_eq!(conf1.directories().signer, "signer".to_owned());
|
||||
assert_eq!(conf1.ui_config(), UiConfiguration {
|
||||
enabled: true,
|
||||
interface: "127.0.0.1".into(),
|
||||
port: 8180,
|
||||
hosts: Some(vec![]),
|
||||
info_page_only: true,
|
||||
});
|
||||
assert_eq!(conf1.dapps_config().extra_embed_on, vec![("127.0.0.1".to_owned(), 3000)]);
|
||||
|
||||
assert!(conf2.ws_config().unwrap().hosts.is_some());
|
||||
assert_eq!(conf2.directories().signer, "signer".to_owned());
|
||||
assert_eq!(conf2.ui_config(), UiConfiguration {
|
||||
enabled: true,
|
||||
interface: "127.0.0.1".into(),
|
||||
port: 3123,
|
||||
hosts: Some(vec![]),
|
||||
info_page_only: true,
|
||||
});
|
||||
|
||||
assert!(conf3.ws_config().unwrap().hosts.is_some());
|
||||
assert_eq!(conf3.directories().signer, "signer".to_owned());
|
||||
assert_eq!(conf3.ui_config(), UiConfiguration {
|
||||
enabled: true,
|
||||
interface: "test".into(),
|
||||
port: 8180,
|
||||
hosts: Some(vec![]),
|
||||
info_page_only: true,
|
||||
});
|
||||
|
||||
assert!(conf4.ws_config().unwrap().hosts.is_some());
|
||||
assert_eq!(conf4.directories().signer, "signer".to_owned());
|
||||
assert_eq!(conf4.ui_config(), UiConfiguration {
|
||||
enabled: true,
|
||||
interface: "127.0.0.1".into(),
|
||||
port: 8180,
|
||||
hosts: Some(vec![]),
|
||||
info_page_only: false,
|
||||
});
|
||||
|
||||
assert!(conf5.ws_config().unwrap().hosts.is_some());
|
||||
assert_eq!(conf5.directories().signer, "signer".to_owned());
|
||||
assert_eq!(conf5.ui_config(), UiConfiguration {
|
||||
enabled: true,
|
||||
interface: "127.0.0.1".into(),
|
||||
port: 8180,
|
||||
hosts: Some(vec![]),
|
||||
info_page_only: false,
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1976,7 +1796,6 @@ mod tests {
|
||||
assert_eq!(conf0.network_settings().unwrap().rpc_port, 8546);
|
||||
assert_eq!(conf0.http_config().unwrap().port, 8546);
|
||||
assert_eq!(conf0.ws_config().unwrap().port, 8547);
|
||||
assert_eq!(conf0.ui_config().port, 8181);
|
||||
assert_eq!(conf0.secretstore_config().unwrap().port, 8084);
|
||||
assert_eq!(conf0.secretstore_config().unwrap().http_port, 8083);
|
||||
assert_eq!(conf0.ipfs_config().port, 5002);
|
||||
@@ -1987,7 +1806,6 @@ mod tests {
|
||||
assert_eq!(conf1.network_settings().unwrap().rpc_port, 8545);
|
||||
assert_eq!(conf1.http_config().unwrap().port, 8545);
|
||||
assert_eq!(conf1.ws_config().unwrap().port, 8547);
|
||||
assert_eq!(conf1.ui_config().port, 8181);
|
||||
assert_eq!(conf1.secretstore_config().unwrap().port, 8084);
|
||||
assert_eq!(conf1.secretstore_config().unwrap().http_port, 8083);
|
||||
assert_eq!(conf1.ipfs_config().port, 5002);
|
||||
@@ -2007,8 +1825,6 @@ mod tests {
|
||||
assert_eq!(&conf0.ws_config().unwrap().interface, "0.0.0.0");
|
||||
assert_eq!(conf0.ws_config().unwrap().hosts, None);
|
||||
assert_eq!(conf0.ws_config().unwrap().origins, None);
|
||||
assert_eq!(&conf0.ui_config().interface, "0.0.0.0");
|
||||
assert_eq!(conf0.ui_config().hosts, None);
|
||||
assert_eq!(&conf0.secretstore_config().unwrap().interface, "0.0.0.0");
|
||||
assert_eq!(&conf0.secretstore_config().unwrap().http_interface, "0.0.0.0");
|
||||
assert_eq!(&conf0.ipfs_config().interface, "0.0.0.0");
|
||||
|
||||
@@ -39,8 +39,6 @@ pub struct Configuration {
|
||||
pub enabled: bool,
|
||||
pub dapps_path: PathBuf,
|
||||
pub extra_dapps: Vec<PathBuf>,
|
||||
pub extra_embed_on: Vec<(String, u16)>,
|
||||
pub extra_script_src: Vec<(String, u16)>,
|
||||
}
|
||||
|
||||
impl Default for Configuration {
|
||||
@@ -50,8 +48,6 @@ impl Default for Configuration {
|
||||
enabled: true,
|
||||
dapps_path: replace_home(&data_dir, "$BASE/dapps").into(),
|
||||
extra_dapps: vec![],
|
||||
extra_embed_on: vec![],
|
||||
extra_script_src: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,8 +159,6 @@ pub struct Dependencies {
|
||||
pub fetch: FetchClient,
|
||||
pub pool: CpuPool,
|
||||
pub signer: Arc<SignerService>,
|
||||
pub ui_address: Option<(String, u16)>,
|
||||
pub info_page_only: bool,
|
||||
}
|
||||
|
||||
pub fn new(configuration: Configuration, deps: Dependencies) -> Result<Option<Middleware>, String> {
|
||||
@@ -177,19 +171,6 @@ pub fn new(configuration: Configuration, deps: Dependencies) -> Result<Option<Mi
|
||||
configuration.dapps_path,
|
||||
configuration.extra_dapps,
|
||||
rpc::DAPPS_DOMAIN,
|
||||
configuration.extra_embed_on,
|
||||
configuration.extra_script_src,
|
||||
).map(Some)
|
||||
}
|
||||
|
||||
pub fn new_ui(enabled: bool, deps: Dependencies) -> Result<Option<Middleware>, String> {
|
||||
if !enabled {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
server::ui_middleware(
|
||||
deps,
|
||||
rpc::DAPPS_DOMAIN,
|
||||
).map(Some)
|
||||
}
|
||||
|
||||
@@ -215,19 +196,10 @@ mod server {
|
||||
_dapps_path: PathBuf,
|
||||
_extra_dapps: Vec<PathBuf>,
|
||||
_dapps_domain: &str,
|
||||
_extra_embed_on: Vec<(String, u16)>,
|
||||
_extra_script_src: Vec<(String, u16)>,
|
||||
) -> Result<Middleware, String> {
|
||||
Err("Your Parity version has been compiled without WebApps support.".into())
|
||||
}
|
||||
|
||||
pub fn ui_middleware(
|
||||
_deps: Dependencies,
|
||||
_dapps_domain: &str,
|
||||
) -> Result<Middleware, String> {
|
||||
Err("Your Parity version has been compiled without UI support.".into())
|
||||
}
|
||||
|
||||
pub fn service(_: &Option<Middleware>) -> Option<Arc<rpc_apis::DappsService>> {
|
||||
None
|
||||
}
|
||||
@@ -249,8 +221,6 @@ mod server {
|
||||
dapps_path: PathBuf,
|
||||
extra_dapps: Vec<PathBuf>,
|
||||
dapps_domain: &str,
|
||||
extra_embed_on: Vec<(String, u16)>,
|
||||
extra_script_src: Vec<(String, u16)>,
|
||||
) -> Result<Middleware, String> {
|
||||
let signer = deps.signer;
|
||||
let web_proxy_tokens = Arc::new(move |token| signer.web_proxy_access_token_domain(&token));
|
||||
@@ -258,9 +228,6 @@ mod server {
|
||||
Ok(parity_dapps::Middleware::dapps(
|
||||
deps.pool,
|
||||
deps.node_health,
|
||||
deps.ui_address,
|
||||
extra_embed_on,
|
||||
extra_script_src,
|
||||
dapps_path,
|
||||
extra_dapps,
|
||||
dapps_domain,
|
||||
@@ -271,21 +238,6 @@ mod server {
|
||||
))
|
||||
}
|
||||
|
||||
pub fn ui_middleware(
|
||||
deps: Dependencies,
|
||||
dapps_domain: &str,
|
||||
) -> Result<Middleware, String> {
|
||||
Ok(parity_dapps::Middleware::ui(
|
||||
deps.pool,
|
||||
deps.node_health,
|
||||
dapps_domain,
|
||||
deps.contract_client,
|
||||
deps.sync_status,
|
||||
deps.fetch,
|
||||
deps.info_page_only,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn service(middleware: &Option<Middleware>) -> Option<Arc<rpc_apis::DappsService>> {
|
||||
middleware.as_ref().map(|m| Arc::new(DappsServiceWrapper {
|
||||
endpoints: m.endpoints().clone(),
|
||||
|
||||
@@ -118,15 +118,13 @@ mod user_defaults;
|
||||
mod whisper;
|
||||
mod db;
|
||||
|
||||
use std::net::{TcpListener};
|
||||
use std::io::BufReader;
|
||||
use std::fs::File;
|
||||
use ansi_term::Style;
|
||||
use hash::keccak_buffer;
|
||||
use cli::Args;
|
||||
use configuration::{Cmd, Execute};
|
||||
use deprecated::find_deprecated;
|
||||
use ethcore_logger::{Config as LogConfig, setup_log};
|
||||
use ethcore_logger::setup_log;
|
||||
|
||||
pub use self::configuration::Configuration;
|
||||
pub use self::run::RunningClient;
|
||||
@@ -195,24 +193,6 @@ fn execute<Cr, Rr>(command: Execute, on_client_rq: Cr, on_updater_rq: Rr) -> Res
|
||||
|
||||
match command.cmd {
|
||||
Cmd::Run(run_cmd) => {
|
||||
if run_cmd.ui_conf.enabled && !run_cmd.ui_conf.info_page_only {
|
||||
warn!("{}", Style::new().bold().paint("Parity browser interface is deprecated. It's going to be removed in the next version, use standalone Parity UI instead."));
|
||||
warn!("{}", Style::new().bold().paint("Standalone Parity UI: https://github.com/Parity-JS/shell/releases"));
|
||||
}
|
||||
|
||||
if run_cmd.ui && run_cmd.dapps_conf.enabled {
|
||||
// Check if Parity is already running
|
||||
let addr = format!("{}:{}", run_cmd.ui_conf.interface, run_cmd.ui_conf.port);
|
||||
if !TcpListener::bind(&addr as &str).is_ok() {
|
||||
return open_ui(&run_cmd.ws_conf, &run_cmd.ui_conf, &run_cmd.logger_config).map(|_| ExecutionAction::Instant(None));
|
||||
}
|
||||
}
|
||||
|
||||
// start ui
|
||||
if run_cmd.ui {
|
||||
open_ui(&run_cmd.ws_conf, &run_cmd.ui_conf, &run_cmd.logger_config)?;
|
||||
}
|
||||
|
||||
if let Some(ref dapp) = run_cmd.dapp {
|
||||
open_dapp(&run_cmd.dapps_conf, &run_cmd.http_conf, dapp)?;
|
||||
}
|
||||
@@ -225,7 +205,7 @@ fn execute<Cr, Rr>(command: Execute, on_client_rq: Cr, on_updater_rq: Rr) -> Res
|
||||
Cmd::Account(account_cmd) => account::execute(account_cmd).map(|s| ExecutionAction::Instant(Some(s))),
|
||||
Cmd::ImportPresaleWallet(presale_cmd) => presale::execute(presale_cmd).map(|s| ExecutionAction::Instant(Some(s))),
|
||||
Cmd::Blockchain(blockchain_cmd) => blockchain::execute(blockchain_cmd).map(|_| ExecutionAction::Instant(None)),
|
||||
Cmd::SignerToken(ws_conf, ui_conf, logger_config) => signer::execute(ws_conf, ui_conf, logger_config).map(|s| ExecutionAction::Instant(Some(s))),
|
||||
Cmd::SignerToken(ws_conf, logger_config) => signer::execute(ws_conf, logger_config).map(|s| ExecutionAction::Instant(Some(s))),
|
||||
Cmd::SignerSign { id, pwfile, port, authfile } => rpc_cli::signer_sign(id, pwfile, port, authfile).map(|s| ExecutionAction::Instant(Some(s))),
|
||||
Cmd::SignerList { port, authfile } => rpc_cli::signer_list(port, authfile).map(|s| ExecutionAction::Instant(Some(s))),
|
||||
Cmd::SignerReject { id, port, authfile } => rpc_cli::signer_reject(id, port, authfile).map(|s| ExecutionAction::Instant(Some(s))),
|
||||
@@ -257,19 +237,6 @@ pub fn start<Cr, Rr>(conf: Configuration, on_client_rq: Cr, on_updater_rq: Rr) -
|
||||
execute(conf.into_command()?, on_client_rq, on_updater_rq)
|
||||
}
|
||||
|
||||
fn open_ui(ws_conf: &rpc::WsConfiguration, ui_conf: &rpc::UiConfiguration, logger_config: &LogConfig) -> Result<(), String> {
|
||||
if !ui_conf.enabled {
|
||||
return Err("Cannot use UI command with UI turned off.".into())
|
||||
}
|
||||
|
||||
let token = signer::generate_token_and_url(ws_conf, ui_conf, logger_config)?;
|
||||
// Open a browser
|
||||
url::open(&token.url).map_err(|e| format!("{}", e))?;
|
||||
// Print a message
|
||||
println!("{}", token.message);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn open_dapp(dapps_conf: &dapps::Configuration, rpc_conf: &rpc::HttpConfiguration, dapp: &str) -> Result<(), String> {
|
||||
if !dapps_conf.enabled {
|
||||
return Err("Cannot use DAPP command with Dapps turned off.".into())
|
||||
|
||||
@@ -68,58 +68,6 @@ impl Default for HttpConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct UiConfiguration {
|
||||
pub enabled: bool,
|
||||
pub interface: String,
|
||||
pub port: u16,
|
||||
pub hosts: Option<Vec<String>>,
|
||||
pub info_page_only: bool,
|
||||
}
|
||||
|
||||
impl UiConfiguration {
|
||||
pub fn address(&self) -> Option<rpc::Host> {
|
||||
address(self.enabled, &self.interface, self.port, &self.hosts)
|
||||
}
|
||||
|
||||
pub fn redirection_address(&self) -> Option<(String, u16)> {
|
||||
self.address().map(|host| {
|
||||
let mut it = host.split(':');
|
||||
let hostname: Option<String> = it.next().map(|s| s.to_owned());
|
||||
let port: Option<u16> = it.next().and_then(|s| s.parse().ok());
|
||||
|
||||
(hostname.unwrap_or_else(|| "localhost".into()), port.unwrap_or(8180))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UiConfiguration> for HttpConfiguration {
|
||||
fn from(conf: UiConfiguration) -> Self {
|
||||
HttpConfiguration {
|
||||
enabled: conf.enabled,
|
||||
interface: conf.interface,
|
||||
port: conf.port,
|
||||
apis: rpc_apis::ApiSet::UnsafeContext,
|
||||
cors: Some(vec![]),
|
||||
hosts: conf.hosts,
|
||||
server_threads: 1,
|
||||
processing_threads: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for UiConfiguration {
|
||||
fn default() -> Self {
|
||||
UiConfiguration {
|
||||
enabled: cfg!(feature = "ui-enabled"),
|
||||
port: 8180,
|
||||
interface: "127.0.0.1".into(),
|
||||
hosts: Some(vec![]),
|
||||
info_page_only: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct IpcConfiguration {
|
||||
pub enabled: bool,
|
||||
@@ -153,7 +101,6 @@ pub struct WsConfiguration {
|
||||
pub hosts: Option<Vec<String>>,
|
||||
pub signer_path: PathBuf,
|
||||
pub support_token_api: bool,
|
||||
pub ui_address: Option<rpc::Host>,
|
||||
pub dapps_address: Option<rpc::Host>,
|
||||
}
|
||||
|
||||
@@ -170,7 +117,6 @@ impl Default for WsConfiguration {
|
||||
hosts: Some(Vec::new()),
|
||||
signer_path: replace_home(&data_dir, "$BASE/signer").into(),
|
||||
support_token_api: true,
|
||||
ui_address: Some("127.0.0.1:8180".into()),
|
||||
dapps_address: Some("127.0.0.1:8545".into()),
|
||||
}
|
||||
}
|
||||
@@ -225,9 +171,8 @@ pub fn new_ws<D: rpc_apis::Dependencies>(
|
||||
};
|
||||
|
||||
let remote = deps.remote.clone();
|
||||
let ui_address = conf.ui_address.clone();
|
||||
let allowed_origins = into_domains(with_domain(conf.origins, domain, &ui_address, &conf.dapps_address));
|
||||
let allowed_hosts = into_domains(with_domain(conf.hosts, domain, &Some(url.clone().into()), &None));
|
||||
let allowed_origins = into_domains(with_domain(conf.origins, domain, &conf.dapps_address));
|
||||
let allowed_hosts = into_domains(with_domain(conf.hosts, domain, &Some(url.clone().into())));
|
||||
|
||||
let signer_path;
|
||||
let path = match conf.support_token_api {
|
||||
@@ -276,7 +221,7 @@ pub fn new_http<D: rpc_apis::Dependencies>(
|
||||
let remote = deps.remote.clone();
|
||||
|
||||
let cors_domains = into_domains(conf.cors);
|
||||
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())));
|
||||
|
||||
let start_result = rpc::start_http(
|
||||
&addr,
|
||||
@@ -328,7 +273,7 @@ fn into_domains<T: From<String>>(items: Option<Vec<String>>) -> DomainsValidatio
|
||||
items.map(|vals| vals.into_iter().map(T::from).collect()).into()
|
||||
}
|
||||
|
||||
fn with_domain(items: Option<Vec<String>>, domain: &str, ui_address: &Option<rpc::Host>, dapps_address: &Option<rpc::Host>) -> Option<Vec<String>> {
|
||||
fn with_domain(items: Option<Vec<String>>, domain: &str, dapps_address: &Option<rpc::Host>) -> Option<Vec<String>> {
|
||||
fn extract_port(s: &str) -> Option<u16> {
|
||||
s.split(':').nth(1).and_then(|s| s.parse().ok())
|
||||
}
|
||||
@@ -347,7 +292,6 @@ fn with_domain(items: Option<Vec<String>>, domain: &str, ui_address: &Option<rpc
|
||||
}
|
||||
};
|
||||
|
||||
add_hosts(ui_address);
|
||||
add_hosts(dapps_address);
|
||||
}
|
||||
items.into_iter().collect()
|
||||
|
||||
@@ -112,13 +112,11 @@ pub struct RunCmd {
|
||||
pub net_settings: NetworkSettings,
|
||||
pub dapps_conf: dapps::Configuration,
|
||||
pub ipfs_conf: ipfs::Configuration,
|
||||
pub ui_conf: rpc::UiConfiguration,
|
||||
pub secretstore_conf: secretstore::Configuration,
|
||||
pub private_provider_conf: ProviderConfig,
|
||||
pub private_encryptor_conf: EncryptorConfig,
|
||||
pub private_tx_enabled: bool,
|
||||
pub dapp: Option<String>,
|
||||
pub ui: bool,
|
||||
pub name: String,
|
||||
pub custom_bootnodes: bool,
|
||||
pub stratum: Option<stratum::Options>,
|
||||
@@ -185,7 +183,7 @@ fn execute_light_impl(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<Runnin
|
||||
execute_upgrades(&cmd.dirs.base, &db_dirs, algorithm, &cmd.compaction)?;
|
||||
|
||||
// create dirs used by parity
|
||||
cmd.dirs.create_dirs(cmd.dapps_conf.enabled, cmd.ui_conf.enabled, cmd.secretstore_conf.enabled)?;
|
||||
cmd.dirs.create_dirs(cmd.dapps_conf.enabled, cmd.acc_conf.unlocked_accounts.len() == 0, cmd.secretstore_conf.enabled)?;
|
||||
|
||||
//print out running parity environment
|
||||
print_running_environment(&spec.name, &cmd.dirs, &db_dirs, &cmd.dapps_conf);
|
||||
@@ -323,13 +321,10 @@ fn execute_light_impl(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<Runnin
|
||||
fetch: fetch.clone(),
|
||||
pool: cpu_pool.clone(),
|
||||
signer: signer_service.clone(),
|
||||
ui_address: cmd.ui_conf.redirection_address(),
|
||||
info_page_only: cmd.ui_conf.info_page_only,
|
||||
})
|
||||
};
|
||||
|
||||
let dapps_middleware = dapps::new(cmd.dapps_conf.clone(), dapps_deps.clone())?;
|
||||
let ui_middleware = dapps::new_ui(cmd.ui_conf.enabled, dapps_deps)?;
|
||||
|
||||
// start RPCs
|
||||
let dapps_service = dapps::service(&dapps_middleware);
|
||||
@@ -373,7 +368,6 @@ fn execute_light_impl(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<Runnin
|
||||
let ws_server = rpc::new_ws(cmd.ws_conf, &dependencies)?;
|
||||
let http_server = rpc::new_http("HTTP JSON-RPC", "jsonrpc", cmd.http_conf.clone(), &dependencies, dapps_middleware)?;
|
||||
let ipc_server = rpc::new_ipc(cmd.ipc_conf, &dependencies)?;
|
||||
let ui_server = rpc::new_http("Parity Wallet (UI)", "ui", cmd.ui_conf.clone().into(), &dependencies, ui_middleware)?;
|
||||
|
||||
// the informant
|
||||
let informant = Arc::new(Informant::new(
|
||||
@@ -394,7 +388,7 @@ fn execute_light_impl(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<Runnin
|
||||
rpc: rpc_direct,
|
||||
informant,
|
||||
client,
|
||||
keep_alive: Box::new((event_loop, service, ws_server, http_server, ipc_server, ui_server)),
|
||||
keep_alive: Box::new((event_loop, service, ws_server, http_server, ipc_server)),
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -444,7 +438,7 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
|
||||
execute_upgrades(&cmd.dirs.base, &db_dirs, algorithm, &cmd.compaction)?;
|
||||
|
||||
// create dirs used by parity
|
||||
cmd.dirs.create_dirs(cmd.dapps_conf.enabled, cmd.ui_conf.enabled, cmd.secretstore_conf.enabled)?;
|
||||
cmd.dirs.create_dirs(cmd.dapps_conf.enabled, cmd.acc_conf.unlocked_accounts.len() == 0, cmd.secretstore_conf.enabled)?;
|
||||
|
||||
// run in daemon mode
|
||||
if let Some(pid_file) = cmd.daemon {
|
||||
@@ -756,12 +750,9 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
|
||||
fetch: fetch.clone(),
|
||||
pool: cpu_pool.clone(),
|
||||
signer: signer_service.clone(),
|
||||
ui_address: cmd.ui_conf.redirection_address(),
|
||||
info_page_only: cmd.ui_conf.info_page_only,
|
||||
})
|
||||
};
|
||||
let dapps_middleware = dapps::new(cmd.dapps_conf.clone(), dapps_deps.clone())?;
|
||||
let ui_middleware = dapps::new_ui(cmd.ui_conf.enabled, dapps_deps)?;
|
||||
|
||||
let dapps_service = dapps::service(&dapps_middleware);
|
||||
let deps_for_rpc_apis = Arc::new(rpc_apis::FullDependencies {
|
||||
@@ -807,8 +798,6 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
|
||||
let ws_server = rpc::new_ws(cmd.ws_conf.clone(), &dependencies)?;
|
||||
let ipc_server = rpc::new_ipc(cmd.ipc_conf, &dependencies)?;
|
||||
let http_server = rpc::new_http("HTTP JSON-RPC", "jsonrpc", cmd.http_conf.clone(), &dependencies, dapps_middleware)?;
|
||||
// the ui server
|
||||
let ui_server = rpc::new_http("UI WALLET", "ui", cmd.ui_conf.clone().into(), &dependencies, ui_middleware)?;
|
||||
|
||||
// secret store key server
|
||||
let secretstore_deps = secretstore::Dependencies {
|
||||
@@ -881,7 +870,7 @@ fn execute_impl<Cr, Rr>(cmd: RunCmd, logger: Arc<RotatingLogger>, on_client_rq:
|
||||
informant,
|
||||
client,
|
||||
client_service: Arc::new(service),
|
||||
keep_alive: Box::new((watcher, updater, ws_server, http_server, ipc_server, ui_server, secretstore_key_server, ipfs_server, event_loop)),
|
||||
keep_alive: Box::new((watcher, updater, ws_server, http_server, ipc_server, secretstore_key_server, ipfs_server, event_loop)),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ pub const CODES_FILENAME: &'static str = "authcodes";
|
||||
|
||||
pub struct NewToken {
|
||||
pub token: String,
|
||||
pub url: String,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
@@ -49,45 +48,26 @@ pub fn codes_path(path: &Path) -> PathBuf {
|
||||
p
|
||||
}
|
||||
|
||||
pub fn execute(ws_conf: rpc::WsConfiguration, ui_conf: rpc::UiConfiguration, logger_config: LogConfig) -> Result<String, String> {
|
||||
Ok(generate_token_and_url(&ws_conf, &ui_conf, &logger_config)?.message)
|
||||
pub fn execute(ws_conf: rpc::WsConfiguration, logger_config: LogConfig) -> Result<String, String> {
|
||||
Ok(generate_token_and_url(&ws_conf, &logger_config)?.message)
|
||||
}
|
||||
|
||||
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, 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 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#"
|
||||
Ok(NewToken {
|
||||
token: code.clone(),
|
||||
message: format!(
|
||||
r#"
|
||||
Generated token:
|
||||
{}
|
||||
"#,
|
||||
colored(code)
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
// And print in to the console
|
||||
Ok(NewToken {
|
||||
token: code.clone(),
|
||||
url: auth_url.clone(),
|
||||
message: format!(
|
||||
r#"
|
||||
Open: {}
|
||||
to authorize your browser.
|
||||
Or use the generated token:
|
||||
{}"#,
|
||||
colored(auth_url),
|
||||
code
|
||||
)
|
||||
colored(code)
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user