Skip to content

Commit

Permalink
Fix credential mode feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
octol committed Dec 6, 2024
1 parent f58ad74 commit b6bf64a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ where
) -> Result<Self, Error> {
let credentials_mode = credentials_mode.unwrap_or_else(|| {
network_env
.get_feature_flag("zkNym", "credentialMode")
.get_feature_flag_credential_mode()
.unwrap_or(false)
});

Expand Down
4 changes: 1 addition & 3 deletions nym-vpn-core/crates/nym-vpn-lib/src/platform/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ pub(crate) async fn get_feature_flag_credential_mode() -> Result<bool, VpnError>
}

fn get_credential_mode(network: &nym_vpn_network_config::Network) -> bool {
network
.get_feature_flag("zkNym", "credentialMode")
.unwrap_or(false)
network.get_feature_flag_credential_mode().unwrap_or(false)
}

pub(crate) async fn fetch_environment(network_name: &str) -> Result<NetworkEnvironment, VpnError> {
Expand Down
25 changes: 20 additions & 5 deletions nym-vpn-core/crates/nym-vpn-network-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use envs::RegisteredNetworks;
use nym_config::defaults::NymNetworkDetails;
use tokio::join;

use std::{path::Path, time::Duration};
use std::{fmt::Debug, path::Path, str::FromStr, time::Duration};

const NETWORKS_SUBDIR: &str = "networks";

Expand Down Expand Up @@ -117,29 +117,44 @@ impl Network {

pub fn get_feature_flag<T>(&self, group: &str, flag: &str) -> Option<T>
where
T: std::str::FromStr,
T: FromStr + Debug,
<T as FromStr>::Err: Debug,
{
tracing::debug!("Getting feature flag: group={}, flag={}", group, flag);
self.feature_flags
.as_ref()
.and_then(|ff| ff.flags.get(group))
.and_then(|value| match value {
FlagValue::Group(group) => group.get(flag).and_then(|v| v.parse::<T>().ok()),
FlagValue::Group(group) => group.get(flag).and_then(|v| {
v.parse::<T>()
.inspect_err(|e| tracing::warn!("Failed to parse flag value: {e:#?}"))
.ok()
}),
_ => None,
})
}

pub fn get_simple_feature_flag<T>(&self, flag: &str) -> Option<T>
where
T: std::str::FromStr,
T: FromStr + Debug,
<T as FromStr>::Err: Debug,
{
tracing::debug!("Getting simple feature flag: flag={}", flag);
self.feature_flags
.as_ref()
.and_then(|ff| ff.flags.get(flag))
.and_then(|value| match value {
FlagValue::Value(value) => value.parse::<T>().ok(),
FlagValue::Value(value) => value
.parse::<T>()
.inspect_err(|e| tracing::warn!("Failed to parse flag value: {e:#?}"))
.ok(),
_ => None,
})
}

pub fn get_feature_flag_credential_mode(&self) -> Option<bool> {
self.get_feature_flag("zkNyms", "credentialMode")
}
}

pub fn discover_networks(config_path: &Path) -> anyhow::Result<RegisteredNetworks> {
Expand Down
15 changes: 4 additions & 11 deletions nym-vpn-core/crates/nym-vpnd/src/service/vpn_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,6 @@ where
})
}

fn get_feature_flag_credential_mode(&self) -> bool {
get_feature_flag_credential_mode(&self.network_env)
}

async fn wait_for_ready_to_connect(
&self,
credentials_mode: bool,
Expand Down Expand Up @@ -776,7 +772,10 @@ where
} = connect_args;

// Get feature flag
let enable_credentials_mode = self.get_feature_flag_credential_mode();
let enable_credentials_mode = self
.network_env
.get_feature_flag_credential_mode()
.unwrap_or(false);
tracing::debug!("feature flag: credential mode: {enable_credentials_mode}");

options.enable_credentials_mode =
Expand Down Expand Up @@ -1226,9 +1225,3 @@ where
api_client.get_devices(&account).await.map_err(Into::into)
}
}

fn get_feature_flag_credential_mode(network_env: &Network) -> bool {
network_env
.get_feature_flag("zkNym", "credentialMode")
.unwrap_or(false)
}

0 comments on commit b6bf64a

Please sign in to comment.