diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-03-18 20:46:18 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-03-25 13:41:59 +0100 |
| commit | f9808f1dce4f7b80ced1e88d8c94844fe2e34e73 (patch) | |
| tree | ea89c79ba4df8eaa5efd5176ab311cdfbbf642b6 | |
| parent | 2bf39941c92624fa950308787a76d705f8669530 (diff) | |
| download | mullvadvpn-f9808f1dce4f7b80ced1e88d8c94844fe2e34e73.tar.xz mullvadvpn-f9808f1dce4f7b80ced1e88d8c94844fe2e34e73.zip | |
Display default rotation interval in CLI
| -rw-r--r-- | mullvad-cli/src/cmds/tunnel.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs index 556f5bfc9f..08306b70eb 100644 --- a/mullvad-cli/src/cmds/tunnel.rs +++ b/mullvad-cli/src/cmds/tunnel.rs @@ -1,6 +1,7 @@ use crate::{format::print_keygen_event, new_rpc_client, Command, Error, Result}; use clap::value_t; use mullvad_management_interface::types::{self, Timestamp, TunnelOptions}; +use mullvad_types::wireguard::DEFAULT_ROTATION_INTERVAL; use std::{convert::TryFrom, time::Duration}; pub struct Tunnel; @@ -223,21 +224,24 @@ impl Tunnel { let tunnel_options = Self::get_tunnel_options().await?; match tunnel_options.wireguard.unwrap().rotation_interval { Some(interval) => { - let hours = Duration::try_from(interval).unwrap().as_secs() / 60 / 60; + let hours = duration_hours(&Duration::try_from(interval).unwrap()); println!("Rotation interval: {} hour(s)", hours); } - None => println!("Rotation interval: default"), + None => println!( + "Rotation interval: default ({} hours)", + duration_hours(&DEFAULT_ROTATION_INTERVAL) + ), } Ok(()) } async fn process_wireguard_rotation_interval_set(matches: &clap::ArgMatches<'_>) -> Result<()> { let rotate_interval = - value_t!(matches.value_of("interval"), u32).unwrap_or_else(|e| e.exit()); + value_t!(matches.value_of("interval"), u64).unwrap_or_else(|e| e.exit()); let mut rpc = new_rpc_client().await?; - rpc.set_wireguard_rotation_interval(types::Duration::from(Duration::from_secs(u64::from( + rpc.set_wireguard_rotation_interval(types::Duration::from(Duration::from_secs( 60 * 60 * rotate_interval, - )))) + ))) .await?; println!("Set key rotation interval: {} hour(s)", rotate_interval); Ok(()) @@ -246,7 +250,10 @@ impl Tunnel { async fn process_wireguard_rotation_interval_reset() -> Result<()> { let mut rpc = new_rpc_client().await?; rpc.reset_wireguard_rotation_interval(()).await?; - println!("Set key rotation interval: default"); + println!( + "Set key rotation interval: default ({} hours)", + duration_hours(&DEFAULT_ROTATION_INTERVAL) + ); Ok(()) } @@ -331,3 +338,7 @@ impl Tunnel { utc.with_timezone(&chrono::Local).to_string() } } + +fn duration_hours(duration: &Duration) -> u64 { + duration.as_secs() / 60 / 60 +} |
