Tokens retention policy

This commit is contained in:
Tomasz Drwięga
2016-11-14 11:56:01 +01:00
parent 6957634ee7
commit 7f011afacb
5 changed files with 181 additions and 43 deletions

View File

@@ -35,7 +35,7 @@ use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras};
use ethcore_logger::Config as LogConfig;
use dir::Directories;
use dapps::Configuration as DappsConfiguration;
use signer::{Configuration as SignerConfiguration, SignerCommand};
use signer::{Configuration as SignerConfiguration};
use run::RunCmd;
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat};
use presale::ImportWallet;
@@ -49,7 +49,7 @@ pub enum Cmd {
Account(AccountCmd),
ImportPresaleWallet(ImportWallet),
Blockchain(BlockchainCmd),
SignerToken(SignerCommand),
SignerToken(SignerConfiguration),
Snapshot(SnapshotCommand),
Hash(Option<String>),
}
@@ -103,11 +103,7 @@ impl Configuration {
let cmd = if self.args.flag_version {
Cmd::Version
} else if self.args.cmd_signer && self.args.cmd_new_token {
Cmd::SignerToken(SignerCommand {
path: dirs.signer,
signer_interface: signer_conf.interface,
signer_port: signer_conf.port,
})
Cmd::SignerToken(signer_conf)
} else if self.args.cmd_tools && self.args.cmd_hash {
Cmd::Hash(self.args.arg_file)
} else if self.args.cmd_account {
@@ -692,7 +688,7 @@ mod tests {
use ethcore::miner::{MinerOptions, PrioritizationStrategy};
use helpers::{replace_home, default_network_config};
use run::RunCmd;
use signer::{Configuration as SignerConfiguration, SignerCommand};
use signer::{Configuration as SignerConfiguration};
use blockchain::{BlockchainCmd, ImportBlockchain, ExportBlockchain, DataFormat};
use presale::ImportWallet;
use account::{AccountCmd, NewAccount, ImportAccounts};
@@ -829,8 +825,12 @@ mod tests {
let args = vec!["parity", "signer", "new-token"];
let conf = parse(&args);
let expected = replace_home("$HOME/.parity/signer");
assert_eq!(conf.into_command().unwrap().cmd, Cmd::SignerToken(SignerCommand {
path: expected,
assert_eq!(conf.into_command().unwrap().cmd, Cmd::SignerToken(SignerConfiguration {
enabled: true,
signer_path: expected,
interface: "127.0.0.1".into(),
port: 8180,
skip_origin_validation: false,
}));
}

View File

@@ -48,7 +48,6 @@ use signer;
use modules;
use rpc_apis;
use rpc;
use url;
// how often to take periodic snapshots.
const SNAPSHOT_PERIOD: u64 = 10000;
@@ -93,13 +92,26 @@ pub struct RunCmd {
pub check_seal: bool,
}
pub fn open_ui(dapps_conf: &dapps::Configuration, signer_conf: &signer::Configuration) -> Result<(), String> {
if !dapps_conf.enabled {
return Err("Cannot use UI command with Dapps turned off.".into())
}
if !signer_conf.enabled {
return Err("Cannot use UI command with UI turned off.".into())
}
let token = try!(signer::generate_token_and_open_ui(signer_conf));
println!("{}", token);
Ok(())
}
pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
if cmd.ui && cmd.dapps_conf.enabled {
// Check if Parity is already running
let addr = format!("{}:{}", cmd.dapps_conf.interface, cmd.dapps_conf.port);
if !TcpListener::bind(&addr as &str).is_ok() {
url::open(&format!("http://{}:{}/", cmd.dapps_conf.interface, cmd.dapps_conf.port));
return Ok(());
return open_ui(&cmd.dapps_conf, &cmd.signer_conf);
}
}
@@ -309,7 +321,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
};
// start signer server
let signer_server = try!(signer::start(cmd.signer_conf, signer_deps));
let signer_server = try!(signer::start(cmd.signer_conf.clone(), signer_deps));
let informant = Arc::new(Informant::new(
service.client(),
@@ -363,10 +375,7 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<(), String> {
// start ui
if cmd.ui {
if !cmd.dapps_conf.enabled {
return Err("Cannot use UI command with Dapps turned off.".into())
}
url::open(&format!("http://{}:{}/", cmd.dapps_conf.interface, cmd.dapps_conf.port));
try!(open_ui(&cmd.dapps_conf, &cmd.signer_conf));
}
// Handle exit

View File

@@ -28,7 +28,7 @@ pub use ethcore_signer::Server as SignerServer;
const CODES_FILENAME: &'static str = "authcodes";
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct Configuration {
pub enabled: bool,
pub port: u16,
@@ -69,16 +69,13 @@ fn codes_path(path: String) -> PathBuf {
p
}
#[derive(Debug, PartialEq)]
pub struct SignerCommand {
pub path: String,
pub signer_interface: String,
pub signer_port: u16,
pub fn execute(cmd: Configuration) -> Result<String, String> {
generate_token_and_open_ui(&cmd)
}
pub fn execute(cmd: SignerCommand) -> Result<String, String> {
let code = try!(generate_new_token(cmd.path).map_err(|err| format!("Error generating token: {:?}", err)));
let auth_url = format!("http://{}:{}/#/auth?token={}", cmd.signer_interface, cmd.signer_port, code);
pub fn generate_token_and_open_ui(conf: &Configuration) -> Result<String, String> {
let code = try!(generate_new_token(conf.signer_path.clone()).map_err(|err| format!("Error generating token: {:?}", err)));
let auth_url = format!("http://{}:{}/#/auth?token={}", conf.interface, conf.port, code);
// Open a browser
url::open(&auth_url);
// And print in to the console
@@ -96,6 +93,7 @@ Or use the code:
pub fn generate_new_token(path: String) -> io::Result<String> {
let path = codes_path(path);
let mut codes = try!(signer::AuthCodes::from_file(&path));
codes.clear_garbage();
let code = try!(codes.generate_new());
try!(codes.to_file(&path));
trace!("New key code created: {}", Colour::White.bold().paint(&code[..]));