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-port PORT Specify the port of Trusted Signer server
[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
be stored. [default: $HOME/.parity/signer]
--signer-no-validation Disable Origin and Host headers validation for
@ -349,6 +352,7 @@ pub struct Args {
pub flag_force_signer: bool,
pub flag_no_signer: bool,
pub flag_signer_port: u16,
pub flag_signer_interface: String,
pub flag_signer_path: String,
pub flag_signer_no_validation: bool,
pub flag_force_sealing: bool,
@ -371,7 +375,7 @@ pub struct Args {
pub flag_version: bool,
pub flag_from: String,
pub flag_to: String,
pub flag_at: String,
pub flag_at: String,
pub flag_format: Option<String>,
pub flag_jitvm: bool,
pub flag_log_file: Option<String>,

View File

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

View File

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