summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2023-09-19 13:43:53 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-10-09 14:40:06 +0200
commitfc477f4e4df6db2973ff88fc4b6819d38d64d8cc (patch)
tree069b709abb09599b37f32716de679298095bc1c1 /mullvad-cli
parentbe5e93c32f3b3e9ec59da18215fad80457dd4d49 (diff)
downloadmullvadvpn-fc477f4e4df6db2973ff88fc4b6819d38d64d8cc.tar.xz
mullvadvpn-fc477f4e4df6db2973ff88fc4b6819d38d64d8cc.zip
Add `mullvad proxy use`
Allow for settings a specific Access Method to use
Diffstat (limited to 'mullvad-cli')
-rw-r--r--mullvad-cli/src/cmds/proxy.rs35
1 files changed, 31 insertions, 4 deletions
diff --git a/mullvad-cli/src/cmds/proxy.rs b/mullvad-cli/src/cmds/proxy.rs
index 48ef302c19..c876a25d2e 100644
--- a/mullvad-cli/src/cmds/proxy.rs
+++ b/mullvad-cli/src/cmds/proxy.rs
@@ -21,9 +21,11 @@ pub enum Proxy {
/// Remove an API proxy
Remove(RemoveCustomCommands),
/// Enable an API proxy
- Enable(ToggleCustomCommands),
+ Enable(SelectItem),
/// Disable an API proxy
- Disable(ToggleCustomCommands),
+ Disable(SelectItem),
+ /// Force the use of a specific API proxy.
+ Use(SelectItem),
}
impl Proxy {
@@ -57,6 +59,10 @@ impl Proxy {
let enabled = false;
Self::toggle(index, enabled).await?;
}
+ Proxy::Use(cmd) => {
+ let index = Self::zero_to_one_based_index(cmd.index)?;
+ Self::set(index).await?;
+ }
};
Ok(())
}
@@ -193,6 +199,25 @@ impl Proxy {
Ok(())
}
+ /// Force the use of a specific access method when trying to reach the
+ /// Mullvad API. If this method fails, the daemon will resume the automatic
+ /// roll-over behavior (which is the default).
+ async fn set(index: usize) -> Result<()> {
+ let mut rpc = MullvadProxyClient::new().await?;
+ let access_method = rpc
+ .get_api_access_methods()
+ .await?
+ .get(index)
+ .ok_or(anyhow!(format!(
+ "Access method {} does not exist",
+ index + 1
+ )))?
+ .clone();
+
+ rpc.set_access_method(access_method).await?;
+ Ok(())
+ }
+
fn zero_to_one_based_index(index: usize) -> Result<usize> {
index
.checked_sub(1)
@@ -224,9 +249,11 @@ pub enum AddCustomCommands {
},
}
+/// A minimal wrapper type allowing the user to supply a list index to some
+/// Access Method.
#[derive(Args, Debug, Clone)]
-pub struct ToggleCustomCommands {
- /// Which access method to enable/disable
+pub struct SelectItem {
+ /// Which access method to pick
index: usize,
}