signer new-token doesn't open the browser
This commit is contained in:
parent
2795f40464
commit
29271383dd
@ -48,6 +48,7 @@ use signer;
|
|||||||
use modules;
|
use modules;
|
||||||
use rpc_apis;
|
use rpc_apis;
|
||||||
use rpc;
|
use rpc;
|
||||||
|
use url;
|
||||||
|
|
||||||
// how often to take periodic snapshots.
|
// how often to take periodic snapshots.
|
||||||
const SNAPSHOT_PERIOD: u64 = 10000;
|
const SNAPSHOT_PERIOD: u64 = 10000;
|
||||||
@ -101,8 +102,11 @@ pub fn open_ui(dapps_conf: &dapps::Configuration, signer_conf: &signer::Configur
|
|||||||
return Err("Cannot use UI command with UI turned off.".into())
|
return Err("Cannot use UI command with UI turned off.".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
let token = try!(signer::generate_token_and_open_ui(signer_conf));
|
let token = try!(signer::generate_token_and_url(signer_conf));
|
||||||
println!("{}", token);
|
// Open a browser
|
||||||
|
url::open(&token.url);
|
||||||
|
// Print a message
|
||||||
|
println!("{}", token.message);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ use std::path::PathBuf;
|
|||||||
use ansi_term::Colour;
|
use ansi_term::Colour;
|
||||||
use io::{ForwardPanic, PanicHandler};
|
use io::{ForwardPanic, PanicHandler};
|
||||||
use util::path::restrict_permissions_owner;
|
use util::path::restrict_permissions_owner;
|
||||||
use url;
|
|
||||||
use rpc_apis;
|
use rpc_apis;
|
||||||
use ethcore_signer as signer;
|
use ethcore_signer as signer;
|
||||||
use helpers::replace_home;
|
use helpers::replace_home;
|
||||||
@ -54,6 +53,12 @@ pub struct Dependencies {
|
|||||||
pub apis: Arc<rpc_apis::Dependencies>,
|
pub apis: Arc<rpc_apis::Dependencies>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct NewToken {
|
||||||
|
pub token: String,
|
||||||
|
pub url: String,
|
||||||
|
pub message: String,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn start(conf: Configuration, deps: Dependencies) -> Result<Option<SignerServer>, String> {
|
pub fn start(conf: Configuration, deps: Dependencies) -> Result<Option<SignerServer>, String> {
|
||||||
if !conf.enabled {
|
if !conf.enabled {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@ -70,24 +75,26 @@ fn codes_path(path: String) -> PathBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn execute(cmd: Configuration) -> Result<String, String> {
|
pub fn execute(cmd: Configuration) -> Result<String, String> {
|
||||||
generate_token_and_open_ui(&cmd)
|
Ok(try!(generate_token_and_url(&cmd)).message)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_token_and_open_ui(conf: &Configuration) -> Result<String, String> {
|
pub fn generate_token_and_url(conf: &Configuration) -> Result<NewToken, String> {
|
||||||
let code = try!(generate_new_token(conf.signer_path.clone()).map_err(|err| format!("Error generating token: {:?}", err)));
|
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);
|
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
|
// And print in to the console
|
||||||
Ok(format!(
|
Ok(NewToken {
|
||||||
|
token: code.clone(),
|
||||||
|
url: auth_url.clone(),
|
||||||
|
message: format!(
|
||||||
r#"
|
r#"
|
||||||
Open: {}
|
Open: {}
|
||||||
to authorize your browser.
|
to authorize your browser.
|
||||||
Or use the code:
|
Or use the generated token:
|
||||||
{}"#,
|
{}"#,
|
||||||
Colour::White.bold().paint(auth_url),
|
Colour::White.bold().paint(auth_url),
|
||||||
code
|
code
|
||||||
))
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_new_token(path: String) -> io::Result<String> {
|
pub fn generate_new_token(path: String) -> io::Result<String> {
|
||||||
|
Loading…
Reference in New Issue
Block a user