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 /mullvad-daemon/src | |
| parent | 32ad869dd3074a3ef6f4f1427600ec0821aaaad6 (diff) | |
| download | mullvadvpn-9be8fb440ebefad790e8a09bd0ce1252575852be.tar.xz mullvadvpn-9be8fb440ebefad790e8a09bd0ce1252575852be.zip | |
Add ClearCustomApiAccessMethods rpc call
Diffstat (limited to 'mullvad-daemon/src')
| -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 |
3 files changed, 32 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( |
