summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src/cmds
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2023-09-11 11:55:02 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-10-09 14:40:03 +0200
commit411f80d4cd227686a57e9dcc39dd30a01f728575 (patch)
treeaf123ab34b0fef2ca06f8180d3fc3b7b5f6029cc /mullvad-cli/src/cmds
parent585a820373abea33e3338e97fb727028667968bb (diff)
downloadmullvadvpn-411f80d4cd227686a57e9dcc39dd30a01f728575.tar.xz
mullvadvpn-411f80d4cd227686a57e9dcc39dd30a01f728575.zip
Add `mullvad proxy api remove` command
Allow the user to manually remove a custom api proxy.
Diffstat (limited to 'mullvad-cli/src/cmds')
-rw-r--r--mullvad-cli/src/cmds/proxy.rs42
1 files changed, 37 insertions, 5 deletions
diff --git a/mullvad-cli/src/cmds/proxy.rs b/mullvad-cli/src/cmds/proxy.rs
index fec4a6f966..583accef1e 100644
--- a/mullvad-cli/src/cmds/proxy.rs
+++ b/mullvad-cli/src/cmds/proxy.rs
@@ -1,9 +1,9 @@
-use anyhow::Result;
+use anyhow::{anyhow, Result};
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::api_access_method::AccessMethod;
use std::net::IpAddr;
-use clap::Subcommand;
+use clap::{Args, Subcommand};
use talpid_types::net::openvpn::SHADOWSOCKS_CIPHERS;
#[derive(Subcommand, Debug)]
@@ -25,6 +25,14 @@ impl Proxy {
//println!("Adding custom proxy");
Self::add(cmd).await?;
}
+ ApiCommands::Edit(_) => todo!(),
+ ApiCommands::Remove(cmd) => {
+ // Transform human-readable index to 0-based indexing.
+ match cmd.index.checked_sub(1) {
+ Some(index) => Self::remove(RemoveCustomCommands { index, ..cmd }).await?,
+ None => println!("Access method 0 does not exist"),
+ }
+ }
},
};
Ok(())
@@ -33,9 +41,8 @@ impl Proxy {
/// Show all API access methods.
async fn list() -> Result<()> {
let mut rpc = MullvadProxyClient::new().await?;
- println!("Calling [rpc::get_api_access_methods] ..");
- for api_access_method in rpc.get_api_access_methods().await? {
- println!("{:?}", api_access_method);
+ for (index, api_access_method) in rpc.get_api_access_methods().await?.iter().enumerate() {
+ println!("{}. {:?}", index + 1, api_access_method);
}
Ok(())
}
@@ -47,6 +54,23 @@ impl Proxy {
rpc.add_access_method(proxy).await?;
Ok(())
}
+
+ /// Remove an API access method.
+ async fn remove(cmd: RemoveCustomCommands) -> Result<()> {
+ let mut rpc = MullvadProxyClient::new().await?;
+ let access_method = rpc
+ .get_api_access_methods()
+ .await?
+ .get(cmd.index)
+ .ok_or(anyhow!(format!(
+ "Access method {} does not exist",
+ cmd.index + 1
+ )))?
+ .clone();
+ rpc.remove_access_method(access_method)
+ .await
+ .map_err(Into::<anyhow::Error>::into)
+ }
}
#[derive(Subcommand, Debug, Clone)]
@@ -56,6 +80,8 @@ pub enum ApiCommands {
/// Add a custom API proxy
#[clap(subcommand)]
Add(AddCustomCommands),
+ /// Remove an API proxy
+ Remove(RemoveCustomCommands),
}
#[derive(Subcommand, Debug, Clone)]
@@ -80,6 +106,12 @@ pub enum AddCustomCommands {
},
}
+#[derive(Args, Debug, Clone)]
+pub struct RemoveCustomCommands {
+ /// Which API proxy to remove
+ index: usize,
+}
+
#[derive(Subcommand, Debug, Clone)]
pub enum Socks5AddCommands {
/// Configure a local SOCKS5 proxy