diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-10-11 15:53:26 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2022-03-14 12:08:37 +0100 |
| commit | b98c366f8647b17c21bfffd903582a1dc09158fb (patch) | |
| tree | fa8b4ba6265767f4a82afb8f9a50e4f3a6f57ecc /mullvad-cli/src | |
| parent | 78dc4644a82d7b3fb904ef3cbac8a1f705f0a213 (diff) | |
| download | mullvadvpn-b98c366f8647b17c21bfffd903582a1dc09158fb.tar.xz mullvadvpn-b98c366f8647b17c21bfffd903582a1dc09158fb.zip | |
Implement device concept
Diffstat (limited to 'mullvad-cli/src')
| -rw-r--r-- | mullvad-cli/src/cmds/account.rs | 66 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/status.rs | 5 | ||||
| -rw-r--r-- | mullvad-cli/src/cmds/tunnel.rs | 11 |
3 files changed, 36 insertions, 46 deletions
diff --git a/mullvad-cli/src/cmds/account.rs b/mullvad-cli/src/cmds/account.rs index 0bbbc28024..fae3b39396 100644 --- a/mullvad-cli/src/cmds/account.rs +++ b/mullvad-cli/src/cmds/account.rs @@ -16,23 +16,17 @@ impl Command for Account { clap::App::new(self.name()) .about("Control and display information about your Mullvad account") .setting(clap::AppSettings::SubcommandRequiredElseHelp) + .subcommand(clap::App::new("create").about("Create and log in to a new account")) .subcommand( - clap::App::new("set").about("Change account").arg( + clap::App::new("login").about("Log in to an account").arg( clap::Arg::new("token") .help("The Mullvad account token to configure the client with") .required(false), ), ) + .subcommand(clap::App::new("logout").about("Log out of the current account")) .subcommand( - clap::App::new("get") - .about("Display information about the currently configured account"), - ) - .subcommand( - clap::App::new("unset").about("Removes the account number from the settings"), - ) - .subcommand( - clap::App::new("create") - .about("Creates a new account and sets it as the active one"), + clap::App::new("get").about("Display information about the current account"), ) .subcommand( clap::App::new("redeem").about("Redeems a voucher").arg( @@ -44,7 +38,9 @@ impl Command for Account { } async fn run(&self, matches: &clap::ArgMatches) -> Result<()> { - if let Some(set_matches) = matches.subcommand_matches("set") { + if let Some(_matches) = matches.subcommand_matches("create") { + self.create().await + } else if let Some(set_matches) = matches.subcommand_matches("login") { let mut token = match set_matches.value_of("token") { Some(token) => token.to_string(), None => { @@ -60,13 +56,11 @@ impl Command for Account { } }; token = token.split_whitespace().join("").to_string(); - self.set(Some(token)).await + self.login(token).await + } else if let Some(_matches) = matches.subcommand_matches("logout") { + self.logout().await } else if let Some(_matches) = matches.subcommand_matches("get") { self.get().await - } else if let Some(_matches) = matches.subcommand_matches("unset") { - self.set(None).await - } else if let Some(_matches) = matches.subcommand_matches("create") { - self.create().await } else if let Some(matches) = matches.subcommand_matches("redeem") { let voucher = matches.value_of_t_or_exit("voucher"); self.redeem_voucher(voucher).await @@ -77,24 +71,35 @@ impl Command for Account { } impl Account { - async fn set(&self, token: Option<AccountToken>) -> Result<()> { + async fn create(&self) -> Result<()> { let mut rpc = new_rpc_client().await?; - rpc.set_account(token.clone().unwrap_or_default()).await?; - if let Some(token) = token { - println!("Mullvad account \"{}\" set", token); - } else { - println!("Mullvad account removed"); - } + rpc.create_new_account(()).await?; + println!("New account created!"); + self.get().await + } + + async fn login(&self, token: AccountToken) -> Result<()> { + let mut rpc = new_rpc_client().await?; + rpc.login_account(token.clone()).await?; + println!("Mullvad account \"{}\" set", token); + Ok(()) + } + + async fn logout(&self) -> Result<()> { + let mut rpc = new_rpc_client().await?; + rpc.logout_account(()).await?; + println!("Removed device from Mullvad account"); Ok(()) } async fn get(&self) -> Result<()> { let mut rpc = new_rpc_client().await?; - let settings = rpc.get_settings(()).await?.into_inner(); - if settings.account_token != "" { - println!("Mullvad account: {}", settings.account_token); + let device = rpc.get_device(()).await?.into_inner(); + if !device.account_token.is_empty() { + println!("Mullvad account: {}", device.account_token); + println!("Device name : {}", device.device.unwrap().name); let expiry = rpc - .get_account_data(settings.account_token) + .get_account_data(device.account_token) .await .map_err(|error| Error::RpcFailedExt("Failed to fetch account data", error))? .into_inner(); @@ -108,13 +113,6 @@ impl Account { Ok(()) } - async fn create(&self) -> Result<()> { - let mut rpc = new_rpc_client().await?; - rpc.create_new_account(()).await?; - println!("New account created!"); - self.get().await - } - async fn redeem_voucher(&self, mut voucher: String) -> Result<()> { let mut rpc = new_rpc_client().await?; voucher.retain(|c| c.is_alphanumeric()); diff --git a/mullvad-cli/src/cmds/status.rs b/mullvad-cli/src/cmds/status.rs index 8c4a929c30..f5a681e36c 100644 --- a/mullvad-cli/src/cmds/status.rs +++ b/mullvad-cli/src/cmds/status.rs @@ -74,10 +74,9 @@ impl Command for Status { println!("New app version info: {:#?}", app_version_info); } } - EventType::KeyEvent(key_event) => { + EventType::Device(device) => { if verbose { - print!("Key event: "); - print_keygen_event(&key_event); + println!("Device event: {:#?}", device); } } } diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs index f3b218648e..f27e29d147 100644 --- a/mullvad-cli/src/cmds/tunnel.rs +++ b/mullvad-cli/src/cmds/tunnel.rs @@ -246,20 +246,13 @@ impl Tunnel { println!("No key is set"); return Ok(()); } - - let is_valid = rpc - .verify_wireguard_key(()) - .await - .map_err(|error| Error::RpcFailedExt("Failed to verify key", error))? - .into_inner(); - println!("Key is valid for use with current account: {}", is_valid); Ok(()) } async fn process_wireguard_key_generate() -> Result<()> { let mut rpc = new_rpc_client().await?; - let keygen_event = rpc.generate_wireguard_key(()).await?; - print_keygen_event(&keygen_event.into_inner()); + let keygen_event = rpc.rotate_wireguard_key(()).await?; + println!("Rotated WireGuard key"); Ok(()) } |
