summaryrefslogtreecommitdiffhomepage
path: root/mullvad-daemon/src
diff options
context:
space:
mode:
authorMarkus Pettersson <markus.pettersson@mullvad.net>2023-09-11 15:20:20 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-10-09 14:40:03 +0200
commitc899c1b63858c12c9367318c19120fe899b31394 (patch)
tree746ac544c0a7aa35fb6cd9275efd9328deecd7e9 /mullvad-daemon/src
parent411f80d4cd227686a57e9dcc39dd30a01f728575 (diff)
downloadmullvadvpn-c899c1b63858c12c9367318c19120fe899b31394.tar.xz
mullvadvpn-c899c1b63858c12c9367318c19120fe899b31394.zip
Add `mullvad proxy api edit` command
Allow a user to edit an existing custom api proxy method
Diffstat (limited to 'mullvad-daemon/src')
-rw-r--r--mullvad-daemon/src/access_methods.rs24
-rw-r--r--mullvad-daemon/src/lib.rs19
2 files changed, 41 insertions, 2 deletions
diff --git a/mullvad-daemon/src/access_methods.rs b/mullvad-daemon/src/access_methods.rs
index 12d8f10f26..e778cd2eeb 100644
--- a/mullvad-daemon/src/access_methods.rs
+++ b/mullvad-daemon/src/access_methods.rs
@@ -1,5 +1,5 @@
use crate::{new_selector_config, settings, Daemon, EventListener};
-use mullvad_types::api_access_method::AccessMethod;
+use mullvad_types::api_access_method::{AccessMethod, ApiAccessMethodReplace};
#[derive(err_derive::Error, Debug)]
pub enum Error {
@@ -54,4 +54,26 @@ where
})
.map_err(Error::Settings)
}
+
+ pub async fn replace_access_method(
+ &mut self,
+ access_method_replace: ApiAccessMethodReplace,
+ ) -> Result<(), Error> {
+ self.settings
+ .update(|settings| {
+ let access_methods = &mut settings.api_access_methods.api_access_methods;
+ access_methods.push(access_method_replace.access_method);
+ access_methods.swap_remove(access_method_replace.index);
+ })
+ .await
+ .map(|changed| {
+ if changed {
+ self.event_listener
+ .notify_settings(self.settings.to_settings());
+ self.relay_selector
+ .set_config(new_selector_config(&self.settings));
+ };
+ })
+ .map_err(Error::Settings)
+ }
}
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index 6ebb7f828e..9528aa1d5e 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -40,7 +40,7 @@ use mullvad_relay_selector::{
};
use mullvad_types::{
account::{AccountData, AccountToken, VoucherSubmission},
- api_access_method::AccessMethod,
+ api_access_method::{AccessMethod, ApiAccessMethodReplace},
auth_failed::AuthFailed,
custom_list::CustomList,
device::{Device, DeviceEvent, DeviceEventCause, DeviceId, DeviceState, RemoveDeviceEvent},
@@ -266,6 +266,8 @@ pub enum DaemonCommand {
AddApiAccessMethod(ResponseTx<(), Error>, AccessMethod),
/// Remove an API access method
RemoveApiAccessMethod(ResponseTx<(), Error>, AccessMethod),
+ /// Edit an API access method
+ ReplaceApiAccessMethod(ResponseTx<(), Error>, ApiAccessMethodReplace),
/// Get information about the currently running and latest app versions
GetVersionInfo(oneshot::Sender<Option<AppVersionInfo>>),
/// Return whether the daemon is performing post-upgrade tasks
@@ -1044,6 +1046,9 @@ where
GetApiAccessMethods(tx) => self.on_get_api_access_methods(tx),
AddApiAccessMethod(tx, method) => self.on_add_api_access_method(tx, method).await,
RemoveApiAccessMethod(tx, method) => self.on_remove_api_access_method(tx, method).await,
+ ReplaceApiAccessMethod(tx, method) => {
+ self.on_replace_api_access_method(tx, method).await
+ }
IsPerformingPostUpgrade(tx) => self.on_is_performing_post_upgrade(tx),
GetCurrentVersion(tx) => self.on_get_current_version(tx),
#[cfg(not(target_os = "android"))]
@@ -2243,6 +2248,18 @@ where
Self::oneshot_send(tx, result, "remove_api_access_method response");
}
+ async fn on_replace_api_access_method(
+ &mut self,
+ tx: ResponseTx<(), Error>,
+ method: ApiAccessMethodReplace,
+ ) {
+ let result = self
+ .replace_access_method(method)
+ .await
+ .map_err(Error::AccessMethodError);
+ Self::oneshot_send(tx, result, "edit_api_access_method response");
+ }
+
fn on_get_settings(&self, tx: oneshot::Sender<Settings>) {
Self::oneshot_send(tx, self.settings.to_settings(), "get_settings response");
}