CLI for Signer interface (#1980)

* # This is a combination of 2 commits.
# The first commit's message is:

CLI to specify signer interface

# This is the 2nd commit message:

Fixing paths on windows

* CLI to specify signer interface
This commit is contained in:
Tomasz Drwięga 2016-08-23 16:53:24 +02:00 committed by Gav Wood
parent 9fc144cc2f
commit 59ede63eda
3 changed files with 50 additions and 7 deletions

View File

@ -73,6 +73,9 @@ Account Options:
Signer UIs. Signer UIs.
--signer-port PORT Specify the port of Trusted Signer server --signer-port PORT Specify the port of Trusted Signer server
[default: 8180]. [default: 8180].
--signer-interface IP Specify the hostname portion of the Trusted Signer
server, IP should be an interface's IP address,
or local [default: local].
--signer-path PATH Specify directory where Signer UIs tokens should --signer-path PATH Specify directory where Signer UIs tokens should
be stored. [default: $HOME/.parity/signer] be stored. [default: $HOME/.parity/signer]
--signer-no-validation Disable Origin and Host headers validation for --signer-no-validation Disable Origin and Host headers validation for
@ -349,6 +352,7 @@ pub struct Args {
pub flag_force_signer: bool, pub flag_force_signer: bool,
pub flag_no_signer: bool, pub flag_no_signer: bool,
pub flag_signer_port: u16, pub flag_signer_port: u16,
pub flag_signer_interface: String,
pub flag_signer_path: String, pub flag_signer_path: String,
pub flag_signer_no_validation: bool, pub flag_signer_no_validation: bool,
pub flag_force_sealing: bool, pub flag_force_sealing: bool,

View File

@ -345,6 +345,7 @@ impl Configuration {
SignerConfiguration { SignerConfiguration {
enabled: self.signer_enabled(), enabled: self.signer_enabled(),
port: self.args.flag_signer_port, port: self.args.flag_signer_port,
interface: self.signer_interface(),
signer_path: self.directories().signer, signer_path: self.directories().signer,
skip_origin_validation: self.args.flag_signer_no_validation, skip_origin_validation: self.args.flag_signer_no_validation,
} }
@ -573,6 +574,13 @@ impl Configuration {
} }
} }
fn signer_interface(&self) -> String {
match self.args.flag_signer_interface.as_str() {
"local" => "127.0.0.1",
x => x,
}.into()
}
fn rpc_interface(&self) -> String { fn rpc_interface(&self) -> String {
match self.network_settings().rpc_interface.as_str() { match self.network_settings().rpc_interface.as_str() {
"all" => "0.0.0.0", "all" => "0.0.0.0",
@ -614,6 +622,7 @@ mod tests {
use ethcore::client::{VMType, BlockID}; use ethcore::client::{VMType, BlockID};
use helpers::{replace_home, default_network_config}; use helpers::{replace_home, default_network_config};
use run::RunCmd; use run::RunCmd;
use signer::Configuration as SignerConfiguration;
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat}; use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat};
use presale::ImportWallet; use presale::ImportWallet;
use account::{AccountCmd, NewAccount, ImportAccounts}; use account::{AccountCmd, NewAccount, ImportAccounts};
@ -876,16 +885,44 @@ mod tests {
} }
#[test] #[test]
fn should_parse_signer_allow_all_flag() { fn should_parse_signer_configration() {
// given // given
// when // when
let conf0 = parse(&["parity", "--signer-no-validation"]); let conf0 = parse(&["parity", "--signer-path", "signer"]);
let conf1 = parse(&["parity"]); let conf1 = parse(&["parity", "--signer-path", "signer", "--signer-no-validation"]);
let conf2 = parse(&["parity", "--signer-path", "signer", "--signer-port", "3123"]);
let conf3 = parse(&["parity", "--signer-path", "signer", "--signer-interface", "test"]);
// then // then
assert_eq!(conf0.args.flag_signer_no_validation, true); assert_eq!(conf0.signer_config(), SignerConfiguration {
assert_eq!(conf1.args.flag_signer_no_validation, false); enabled: true,
port: 8180,
interface: "127.0.0.1".into(),
signer_path: "signer".into(),
skip_origin_validation: false,
});
assert_eq!(conf1.signer_config(), SignerConfiguration {
enabled: true,
port: 8180,
interface: "127.0.0.1".into(),
signer_path: "signer".into(),
skip_origin_validation: true,
});
assert_eq!(conf2.signer_config(), SignerConfiguration {
enabled: true,
port: 3123,
interface: "127.0.0.1".into(),
signer_path: "signer".into(),
skip_origin_validation: false,
});
assert_eq!(conf3.signer_config(), SignerConfiguration {
enabled: true,
port: 8180,
interface: "test".into(),
signer_path: "signer".into(),
skip_origin_validation: false,
});
} }
#[test] #[test]

View File

@ -31,6 +31,7 @@ const CODES_FILENAME: &'static str = "authcodes";
pub struct Configuration { pub struct Configuration {
pub enabled: bool, pub enabled: bool,
pub port: u16, pub port: u16,
pub interface: String,
pub signer_path: String, pub signer_path: String,
pub skip_origin_validation: bool, pub skip_origin_validation: bool,
} }
@ -40,6 +41,7 @@ impl Default for Configuration {
Configuration { Configuration {
enabled: true, enabled: true,
port: 8180, port: 8180,
interface: "127.0.0.1".into(),
signer_path: replace_home("$HOME/.parity/signer"), signer_path: replace_home("$HOME/.parity/signer"),
skip_origin_validation: false, skip_origin_validation: false,
} }
@ -82,7 +84,7 @@ fn generate_new_token(path: String) -> io::Result<String> {
} }
fn do_start(conf: Configuration, deps: Dependencies) -> Result<SignerServer, String> { fn do_start(conf: Configuration, deps: Dependencies) -> Result<SignerServer, String> {
let addr = try!(format!("127.0.0.1:{}", conf.port) let addr = try!(format!("{}:{}", conf.interface, conf.port)
.parse() .parse()
.map_err(|_| format!("Invalid port specified: {}", conf.port))); .map_err(|_| format!("Invalid port specified: {}", conf.port)));