Generating browser link on signer new-token

This commit is contained in:
Tomasz Drwięga 2016-11-11 17:38:45 +01:00
parent d5d1c1b674
commit aa147461b0
2 changed files with 17 additions and 4 deletions

View File

@ -104,7 +104,9 @@ impl Configuration {
Cmd::Version
} else if self.args.cmd_signer && self.args.cmd_new_token {
Cmd::SignerToken(SignerCommand {
path: dirs.signer
path: dirs.signer,
signer_interface: signer_conf.interface,
signer_port: signer_conf.port,
})
} else if self.args.cmd_tools && self.args.cmd_hash {
Cmd::Hash(self.args.arg_file)

View File

@ -71,12 +71,23 @@ fn codes_path(path: String) -> PathBuf {
#[derive(Debug, PartialEq)]
pub struct SignerCommand {
pub path: String,
pub signer_interface: String,
pub signer_port: u16,
}
pub fn execute(cmd: SignerCommand) -> Result<String, String> {
generate_new_token(cmd.path)
.map(|code| format!("This key code will authorise your System Signer UI: {}", Colour::White.bold().paint(code)))
.map_err(|err| format!("Error generating token: {:?}", err))
let code = try!(generate_new_token(cmd.path).map_err(|err| format!("Error generating token: {:?}", err)));
let url = format!("http://{}:{}/#/auth?token={}", cmd.signer_interface, cmd.signer_port, code);
Ok(format!(
r#"
Open: {}
to authorize your browser.
Or use the code: {}
"#,
Colour::White.bold().paint(url),
code
))
}
pub fn generate_new_token(path: String) -> io::Result<String> {