diff options
| author | Joakim Hulthe <joakim@hulthe.net> | 2024-04-09 16:30:55 +0200 |
|---|---|---|
| committer | Joakim Hulthe <joakim@hulthe.net> | 2024-04-12 14:53:12 +0200 |
| commit | 9be8fb440ebefad790e8a09bd0ce1252575852be (patch) | |
| tree | 1d3fc0600ff1dc8dc2852757df41333eb4b17dbc | |
| parent | 32ad869dd3074a3ef6f4f1427600ec0821aaaad6 (diff) | |
| download | mullvadvpn-9be8fb440ebefad790e8a09bd0ce1252575852be.tar.xz mullvadvpn-9be8fb440ebefad790e8a09bd0ce1252575852be.zip | |
Add ClearCustomApiAccessMethods rpc call
| -rw-r--r-- | mullvad-daemon/src/access_method.rs | 11 | ||||
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 11 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 10 | ||||
| -rw-r--r-- | mullvad-management-interface/proto/management_interface.proto | 1 | ||||
| -rw-r--r-- | mullvad-management-interface/src/client.rs | 9 | ||||
| -rw-r--r-- | mullvad-types/src/access_method.rs | 6 | ||||
| -rw-r--r-- | test/test-manager/src/tests/mod.rs | 11 |
7 files changed, 59 insertions, 0 deletions
diff --git a/mullvad-daemon/src/access_method.rs b/mullvad-daemon/src/access_method.rs index bc843f529e..edae229ae0 100644 --- a/mullvad-daemon/src/access_method.rs +++ b/mullvad-daemon/src/access_method.rs @@ -128,6 +128,17 @@ where Ok(()) } + /// Remove all custom [`AccessMethodSetting`]. + pub async fn clear_custom_api_access_methods(&mut self) -> Result<(), Error> { + self.settings + .update(|settings: &mut Settings| { + settings.api_access_methods.clear_custom(); + }) + .await?; + + Ok(()) + } + /// Return the [`AccessMethodSetting`] which is currently used to access the /// Mullvad API. pub async fn get_current_access_method(&self) -> Result<AccessMethodSetting, Error> { diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index c3c64ebacf..da02cb6ffc 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -292,6 +292,8 @@ pub enum DaemonCommand { SetApiAccessMethod(ResponseTx<(), Error>, mullvad_types::access_method::Id), /// Edit an API access method UpdateApiAccessMethod(ResponseTx<(), Error>, AccessMethodSetting), + /// Remove all custom API access methods + ClearCustomApiAccessMethods(ResponseTx<(), Error>), /// Get the currently used API access method GetCurrentAccessMethod(ResponseTx<AccessMethodSetting, Error>), /// Test an API access method @@ -1260,6 +1262,7 @@ where } RemoveApiAccessMethod(tx, method) => self.on_remove_api_access_method(tx, method).await, UpdateApiAccessMethod(tx, method) => self.on_update_api_access_method(tx, method).await, + ClearCustomApiAccessMethods(tx) => self.on_clear_custom_api_access_methods(tx).await, GetCurrentAccessMethod(tx) => self.on_get_current_api_access_method(tx), SetApiAccessMethod(tx, method) => self.on_set_api_access_method(tx, method).await, TestApiAccessMethodById(tx, method) => self.on_test_api_access_method(tx, method).await, @@ -2482,6 +2485,14 @@ where Self::oneshot_send(tx, result, "update_api_access_method response"); } + async fn on_clear_custom_api_access_methods(&mut self, tx: ResponseTx<(), Error>) { + let result = self + .clear_custom_api_access_methods() + .await + .map_err(Error::AccessMethodError); + Self::oneshot_send(tx, result, "clear_custom_api_access_methods response"); + } + fn on_get_current_api_access_method(&mut self, tx: ResponseTx<AccessMethodSetting, Error>) { let handle = self.access_mode_handler.clone(); tokio::spawn(async move { diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index ee0fadaa0e..52c2c50d4c 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -663,6 +663,16 @@ impl ManagementService for ManagementServiceImpl { .map_err(map_daemon_error) } + async fn clear_custom_api_access_methods(&self, _: Request<()>) -> ServiceResult<()> { + log::debug!("clear_custom_api_access_methods"); + let (tx, rx) = oneshot::channel(); + self.send_command_to_daemon(DaemonCommand::ClearCustomApiAccessMethods(tx))?; + self.wait_for_result(rx) + .await? + .map(Response::new) + .map_err(map_daemon_error) + } + /// Return the [`types::AccessMethodSetting`] which the daemon is using to /// connect to the Mullvad API. async fn get_current_api_access_method( diff --git a/mullvad-management-interface/proto/management_interface.proto b/mullvad-management-interface/proto/management_interface.proto index 7fbdb6eba6..cd3e6afaac 100644 --- a/mullvad-management-interface/proto/management_interface.proto +++ b/mullvad-management-interface/proto/management_interface.proto @@ -79,6 +79,7 @@ service ManagementService { rpc RemoveApiAccessMethod(UUID) returns (google.protobuf.Empty) {} rpc SetApiAccessMethod(UUID) returns (google.protobuf.Empty) {} rpc UpdateApiAccessMethod(AccessMethodSetting) returns (google.protobuf.Empty) {} + rpc ClearCustomApiAccessMethods(google.protobuf.Empty) returns (google.protobuf.Empty) {} rpc GetCurrentApiAccessMethod(google.protobuf.Empty) returns (AccessMethodSetting) {} rpc TestCustomApiAccessMethod(CustomProxy) returns (google.protobuf.BoolValue) {} rpc TestApiAccessMethodById(UUID) returns (google.protobuf.BoolValue) {} diff --git a/mullvad-management-interface/src/client.rs b/mullvad-management-interface/src/client.rs index fd6c56e19f..93a446cbc9 100644 --- a/mullvad-management-interface/src/client.rs +++ b/mullvad-management-interface/src/client.rs @@ -575,6 +575,15 @@ impl MullvadProxyClient { .map(drop) } + /// Remove all custom API access methods. + pub async fn clear_custom_access_methods(&mut self) -> Result<()> { + self.0 + .clear_custom_api_access_methods(()) + .await + .map_err(Error::Rpc) + .map(drop) + } + /// Set the [`AccessMethod`] which [`ApiConnectionModeProvider`] should /// pick. /// diff --git a/mullvad-types/src/access_method.rs b/mullvad-types/src/access_method.rs index c5f0b41859..c42b099bae 100644 --- a/mullvad-types/src/access_method.rs +++ b/mullvad-types/src/access_method.rs @@ -74,6 +74,12 @@ impl Settings { updated } + /// Remove all custom access methods. + pub fn clear_custom(&mut self) { + self.custom.clear(); + self.ensure_consistent_state(); + } + /// Check that `self` contains atleast one enabled access methods. If not, /// the `Direct` access method is re-enabled. fn ensure_consistent_state(&mut self) { diff --git a/test/test-manager/src/tests/mod.rs b/test/test-manager/src/tests/mod.rs index 0ccc900c5f..e99300232b 100644 --- a/test/test-manager/src/tests/mod.rs +++ b/test/test-manager/src/tests/mod.rs @@ -95,6 +95,17 @@ pub async fn cleanup_after_test(mullvad_client: &mut MullvadProxyClient) -> anyh } = Default::default(); mullvad_client + .clear_custom_access_methods() + .await + .context("Could not clear custom api access methods")?; + for access_method in api_access_methods.iter() { + mullvad_client + .update_access_method(access_method.clone()) + .await + .context("Could not reset default access method")?; + } + + mullvad_client .set_relay_settings(relay_settings) .await .context("Could not set relay settings")?; |
