Skip to content

Commit

Permalink
Deprecate the name ApiAccessMethod in favor of AccessMethodSetting
Browse files Browse the repository at this point in the history
To decrease the confusion between `AccessMethod` & `ApiAccessMethod`.
`AccessMethodSetting` adds some app-specific settings details on top of
an `AccessMethod`, which is not too far fetched with the new naming convention.
  • Loading branch information
MarkusPettersson98 committed Sep 26, 2023
1 parent e8b8a96 commit 93be86e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion mullvad-daemon/src/access_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ where
connection_modes.update_access_methods(
self.settings
.api_access_methods
.api_access_methods
.access_method_settings
.iter()
.filter(|api_access_method| api_access_method.enabled())
.map(|api_access_method| api_access_method.access_method.clone())
Expand Down
2 changes: 1 addition & 1 deletion mullvad-daemon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ where
relay_selector.clone(),
settings
.api_access_methods
.api_access_methods
.access_method_settings
.iter()
// We only care about the access methods which are set to 'enabled' by the user.
.filter(|api_access_method| api_access_method.enabled())
Expand Down
4 changes: 2 additions & 2 deletions mullvad-daemon/src/management_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ impl ManagementService for ManagementServiceImpl {

async fn add_api_access_method(
&self,
request: Request<types::ApiAccessMethodAdd>,
request: Request<types::AccessMethodSettingAdd>,
) -> ServiceResult<types::Uuid> {
log::debug!("add_api_access_method");
let request = request.into_inner();
Expand Down Expand Up @@ -657,7 +657,7 @@ impl ManagementService for ManagementServiceImpl {

async fn update_api_access_method(
&self,
request: Request<types::ApiAccessMethod>,
request: Request<types::AccessMethodSetting>,
) -> ServiceResult<()> {
log::debug!("update_api_access_method");
let access_method_update =
Expand Down
14 changes: 7 additions & 7 deletions mullvad-management-interface/proto/management_interface.proto
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ service ManagementService {
rpc RenameCustomList(CustomListRename) returns (google.protobuf.Empty) {}

// API Access methods
rpc AddApiAccessMethod(ApiAccessMethodAdd) returns (UUID) {}
rpc AddApiAccessMethod(AccessMethodSettingAdd) returns (UUID) {}
rpc RemoveApiAccessMethod(UUID) returns (google.protobuf.Empty) {}
rpc SetApiAccessMethod(UUID) returns (google.protobuf.Empty) {}
rpc UpdateApiAccessMethod(ApiAccessMethod) returns (google.protobuf.Empty) {}
rpc UpdateApiAccessMethod(AccessMethodSetting) returns (google.protobuf.Empty) {}

// Split tunneling (Linux)
rpc GetSplitTunnelProcesses(google.protobuf.Empty) returns (stream google.protobuf.Int32Value) {}
Expand Down Expand Up @@ -380,25 +380,25 @@ message AccessMethod {
}
}

message ApiAccessMethod {
message AccessMethodSetting {
UUID id = 1;
string name = 2;
bool enabled = 3;
AccessMethod access_method = 4;
}

message ApiAccessMethodAdd {
message AccessMethodSettingAdd {
string name = 1;
bool enabled = 2;
AccessMethod access_method = 3;
}

message ApiAccessMethodUpdate {
message AccessMethodSettingUpdate {
UUID id = 1;
ApiAccessMethod access_method = 2;
AccessMethodSetting access_method_setting = 2;
}

message ApiAccessMethodSettings { repeated ApiAccessMethod api_access_methods = 1; }
message ApiAccessMethodSettings { repeated AccessMethodSetting access_method_settings = 1; }

message Settings {
RelaySettings relay_settings = 1;
Expand Down
6 changes: 3 additions & 3 deletions mullvad-management-interface/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl MullvadProxyClient {
.into_inner()
.api_access_methods
.ok_or(Error::ApiAccessMethodSettingsNotFound)?
.api_access_methods
.access_method_settings
.into_iter()
.map(|api_access_method| {
AccessMethodSetting::try_from(api_access_method).map_err(Error::InvalidResponse)
Expand Down Expand Up @@ -528,7 +528,7 @@ impl MullvadProxyClient {
enabled: bool,
access_method: AccessMethod,
) -> Result<()> {
let request = types::ApiAccessMethodAdd {
let request = types::AccessMethodSettingAdd {
name,
enabled,
access_method: Some(types::AccessMethod::from(access_method)),
Expand Down Expand Up @@ -574,7 +574,7 @@ impl MullvadProxyClient {
access_method_update: AccessMethodSetting,
) -> Result<()> {
self.0
.update_api_access_method(types::ApiAccessMethod::from(access_method_update))
.update_api_access_method(types::AccessMethodSetting::from(access_method_update))
.await
.map_err(Error::Rpc)
.map(drop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mod settings {
impl From<&api_access::Settings> for proto::ApiAccessMethodSettings {
fn from(settings: &api_access::Settings) -> Self {
Self {
api_access_methods: settings
.api_access_methods
access_method_settings: settings
.access_method_settings
.iter()
.map(|method| method.clone().into())
.collect(),
Expand All @@ -28,8 +28,8 @@ mod settings {

fn try_from(settings: proto::ApiAccessMethodSettings) -> Result<Self, Self::Error> {
Ok(Self {
api_access_methods: settings
.api_access_methods
access_method_settings: settings
.access_method_settings
.iter()
.map(api_access::AccessMethodSetting::try_from)
.collect::<Result<Vec<api_access::AccessMethodSetting>, _>>()?,
Expand All @@ -48,10 +48,10 @@ mod data {
CustomAccessMethod, Shadowsocks, Socks5, Socks5Local, Socks5Remote,
};

impl TryFrom<proto::ApiAccessMethod> for AccessMethodSetting {
impl TryFrom<proto::AccessMethodSetting> for AccessMethodSetting {
type Error = FromProtobufTypeError;

fn try_from(value: proto::ApiAccessMethod) -> Result<Self, Self::Error> {
fn try_from(value: proto::AccessMethodSetting) -> Result<Self, Self::Error> {
let id = value
.id
.ok_or(FromProtobufTypeError::InvalidArgument(
Expand All @@ -76,12 +76,12 @@ mod data {
}
}

impl From<AccessMethodSetting> for proto::ApiAccessMethod {
impl From<AccessMethodSetting> for proto::AccessMethodSetting {
fn from(value: AccessMethodSetting) -> Self {
let id = proto::Uuid::from(value.get_id());
let name = value.get_name();
let enabled = value.enabled();
proto::ApiAccessMethod {
proto::AccessMethodSetting {
id: Some(id),
name,
enabled,
Expand Down Expand Up @@ -248,10 +248,10 @@ mod data {
}
}

impl TryFrom<&proto::ApiAccessMethod> for AccessMethodSetting {
impl TryFrom<&proto::AccessMethodSetting> for AccessMethodSetting {
type Error = FromProtobufTypeError;

fn try_from(value: &proto::ApiAccessMethod) -> Result<Self, Self::Error> {
fn try_from(value: &proto::AccessMethodSetting) -> Result<Self, Self::Error> {
AccessMethodSetting::try_from(value.clone())
}
}
Expand Down
2 changes: 1 addition & 1 deletion mullvad-management-interface/src/types/conversions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;

mod access_method;
mod account;
mod api_access_method;
mod custom_list;
mod custom_tunnel;
mod device;
Expand Down
14 changes: 7 additions & 7 deletions mullvad-types/src/api_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
/// Daemon settings for API access methods.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Settings {
pub api_access_methods: Vec<AccessMethodSetting>,
pub access_method_settings: Vec<AccessMethodSetting>,
}

impl Settings {
/// Append an [`AccessMethod`] to the end of `api_access_methods`.
pub fn append(&mut self, api_access_method: AccessMethodSetting) {
self.api_access_methods.push(api_access_method)
self.access_method_settings.push(api_access_method)
}

/// Remove an [`ApiAccessMethod`] from `api_access_methods`.
Expand All @@ -22,7 +22,7 @@ impl Settings {

/// Search for a particular [`AccessMethod`] in `api_access_methods`.
pub fn find(&self, element: &ApiAccessMethodId) -> Option<&AccessMethodSetting> {
self.api_access_methods
self.access_method_settings
.iter()
.find(|api_access_method| *element == api_access_method.get_id())
}
Expand All @@ -33,7 +33,7 @@ impl Settings {
/// mutable reference to that inner element is returned. Otherwise, `None`
/// is returned.
pub fn find_mut(&mut self, element: &ApiAccessMethodId) -> Option<&mut AccessMethodSetting> {
self.api_access_methods
self.access_method_settings
.iter_mut()
.find(|api_access_method| *element == api_access_method.get_id())
}
Expand All @@ -43,19 +43,19 @@ impl Settings {
where
F: FnMut(&AccessMethodSetting) -> bool,
{
self.api_access_methods.retain(f)
self.access_method_settings.retain(f)
}

/// Clone the content of `api_access_methods`.
pub fn cloned(&self) -> Vec<AccessMethodSetting> {
self.api_access_methods.clone()
self.access_method_settings.clone()
}
}

impl Default for Settings {
fn default() -> Self {
Self {
api_access_methods: vec![BuiltInAccessMethod::Direct, BuiltInAccessMethod::Bridge]
access_method_settings: vec![BuiltInAccessMethod::Direct, BuiltInAccessMethod::Bridge]
.into_iter()
.map(|built_in| {
AccessMethodSetting::new(
Expand Down

0 comments on commit 93be86e

Please sign in to comment.