diff options
Diffstat (limited to 'mullvad-cli/src')
| -rw-r--r-- | mullvad-cli/src/cmds/proxy.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/proxy.rs b/mullvad-cli/src/cmds/proxy.rs index c876a25d2e..fa05081f89 100644 --- a/mullvad-cli/src/cmds/proxy.rs +++ b/mullvad-cli/src/cmds/proxy.rs @@ -24,6 +24,8 @@ pub enum Proxy { Enable(SelectItem), /// Disable an API proxy Disable(SelectItem), + /// Test an API proxy + Test(SelectItem), /// Force the use of a specific API proxy. Use(SelectItem), } @@ -59,6 +61,10 @@ impl Proxy { let enabled = false; Self::toggle(index, enabled).await?; } + Proxy::Test(cmd) => { + let index = Self::zero_to_one_based_index(cmd.index)?; + Self::test(index).await?; + } Proxy::Use(cmd) => { let index = Self::zero_to_one_based_index(cmd.index)?; Self::set(index).await?; @@ -199,6 +205,34 @@ impl Proxy { Ok(()) } + /// Test an access method to see if it successfully reaches the Mullvad API. + async fn test(index: usize) -> Result<()> { + let mut rpc = MullvadProxyClient::new().await?; + // TODO: Refactor this into some helper function. This code has been copy-pastead a lot already .. + // Step 1. + let access_method = rpc + .get_api_access_methods() + .await? + .get(index) + .ok_or(anyhow!(format!( + "Access method {} does not exist", + index + 1 + )))? + .clone(); + + // Step 2. + rpc.set_access_method(access_method).await?; + // Step 3. + let api_call = rpc.test_api().await; + // Step 4. + match api_call { + Ok(_) => println!("API call succeeded!"), + Err(_) => println!("API call failed :-("), + } + + 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). |
