summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src/cmds
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2023-09-27 09:39:44 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-10-09 14:40:15 +0200
commit998fd39aaebc1435065f1f4886f4bd40f5889e5a (patch)
treeaf2816f531a38a65e494d0376001eff7666756f2 /mullvad-cli/src/cmds
parent189c8d0273c036681142f73dfe3a5c619a0e0d28 (diff)
downloadmullvadvpn-998fd39aaebc1435065f1f4886f4bd40f5889e5a.tar.xz
mullvadvpn-998fd39aaebc1435065f1f4886f4bd40f5889e5a.zip
Code cleanup
- Get rid of extraneous calls to `clone` - Address nit: combine similar match arms into a single match arm - Fix `clippy` lint "unused `async` for function with no await statements" - Fix protobuf field numbers should start from 1 - This was not the case for `Socks5Local` & `Shadowsocks` - Refactor code for opening proxy connections - Cut down on duplicated code for setting up a proxied connection in `mullvad-api`. The difference between different connection modes is how they wrap the underlying `TCP` stream. - Remove `enable_access_method` & `disable_access_method` from RPC-client
Diffstat (limited to 'mullvad-cli/src/cmds')
-rw-r--r--mullvad-cli/src/cmds/api_access.rs31
1 files changed, 14 insertions, 17 deletions
diff --git a/mullvad-cli/src/cmds/api_access.rs b/mullvad-cli/src/cmds/api_access.rs
index 4c1594b1fe..a3b17aca0b 100644
--- a/mullvad-cli/src/cmds/api_access.rs
+++ b/mullvad-cli/src/cmds/api_access.rs
@@ -77,7 +77,7 @@ impl ApiAccess {
/// Add a custom API access method.
async fn add(cmd: AddCustomCommands) -> Result<()> {
let mut rpc = MullvadProxyClient::new().await?;
- let name = cmd.name();
+ let name = cmd.name().to_string();
let enabled = cmd.enabled();
let access_method = AccessMethod::try_from(cmd)?;
rpc.add_access_method(name, enabled, access_method).await?;
@@ -143,16 +143,18 @@ impl ApiAccess {
/// Enable a custom API access method.
async fn enable(item: SelectItem) -> Result<()> {
let mut rpc = MullvadProxyClient::new().await?;
- let access_method = Self::get_access_method(&mut rpc, &item).await?;
- rpc.enable_access_method(access_method.get_id()).await?;
+ let mut access_method = Self::get_access_method(&mut rpc, &item).await?;
+ access_method.enable();
+ rpc.update_access_method(access_method).await?;
Ok(())
}
/// Disable a custom API access method.
async fn disable(item: SelectItem) -> Result<()> {
let mut rpc = MullvadProxyClient::new().await?;
- let access_method = Self::get_access_method(&mut rpc, &item).await?;
- rpc.disable_access_method(access_method.get_id()).await?;
+ let mut access_method = Self::get_access_method(&mut rpc, &item).await?;
+ access_method.disable();
+ rpc.update_access_method(access_method).await?;
Ok(())
}
@@ -262,24 +264,19 @@ pub enum AddSocks5Commands {
}
impl AddCustomCommands {
- fn name(&self) -> String {
+ fn name(&self) -> &str {
match self {
- AddCustomCommands::Shadowsocks { name, .. } => name,
- AddCustomCommands::Socks5(socks) => match socks {
- AddSocks5Commands::Remote { name, .. } => name,
- AddSocks5Commands::Local { name, .. } => name,
- },
+ AddCustomCommands::Shadowsocks { name, .. }
+ | AddCustomCommands::Socks5(AddSocks5Commands::Remote { name, .. })
+ | AddCustomCommands::Socks5(AddSocks5Commands::Local { name, .. }) => name,
}
- .clone()
}
fn enabled(&self) -> bool {
match self {
- AddCustomCommands::Shadowsocks { disabled, .. } => !disabled,
- AddCustomCommands::Socks5(socks) => match socks {
- AddSocks5Commands::Remote { disabled, .. } => !disabled,
- AddSocks5Commands::Local { disabled, .. } => !disabled,
- },
+ AddCustomCommands::Shadowsocks { disabled, .. }
+ | AddCustomCommands::Socks5(AddSocks5Commands::Remote { disabled, .. })
+ | AddCustomCommands::Socks5(AddSocks5Commands::Local { disabled, .. }) => !disabled,
}
}
}