From b6bf64a14a978e94cd27ca826e6894f0f38b0e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Fri, 6 Dec 2024 15:10:19 +0100 Subject: [PATCH] Fix credential mode feature flag --- .../src/controller.rs | 2 +- .../nym-vpn-lib/src/platform/environment.rs | 4 +-- .../crates/nym-vpn-network-config/src/lib.rs | 25 +++++++++++++++---- .../nym-vpnd/src/service/vpn_service.rs | 15 +++-------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs b/nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs index 676fc932b4..a777ecc14e 100644 --- a/nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs +++ b/nym-vpn-core/crates/nym-vpn-account-controller/src/controller.rs @@ -96,7 +96,7 @@ where ) -> Result { let credentials_mode = credentials_mode.unwrap_or_else(|| { network_env - .get_feature_flag("zkNym", "credentialMode") + .get_feature_flag_credential_mode() .unwrap_or(false) }); diff --git a/nym-vpn-core/crates/nym-vpn-lib/src/platform/environment.rs b/nym-vpn-core/crates/nym-vpn-lib/src/platform/environment.rs index 07c3f6cb77..7fba83820d 100644 --- a/nym-vpn-core/crates/nym-vpn-lib/src/platform/environment.rs +++ b/nym-vpn-core/crates/nym-vpn-lib/src/platform/environment.rs @@ -85,9 +85,7 @@ pub(crate) async fn get_feature_flag_credential_mode() -> Result } 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 { diff --git a/nym-vpn-core/crates/nym-vpn-network-config/src/lib.rs b/nym-vpn-core/crates/nym-vpn-network-config/src/lib.rs index 78ce11e1ce..565831efc0 100644 --- a/nym-vpn-core/crates/nym-vpn-network-config/src/lib.rs +++ b/nym-vpn-core/crates/nym-vpn-network-config/src/lib.rs @@ -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"; @@ -117,29 +117,44 @@ impl Network { pub fn get_feature_flag(&self, group: &str, flag: &str) -> Option where - T: std::str::FromStr, + T: FromStr + Debug, + ::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::().ok()), + FlagValue::Group(group) => group.get(flag).and_then(|v| { + v.parse::() + .inspect_err(|e| tracing::warn!("Failed to parse flag value: {e:#?}")) + .ok() + }), _ => None, }) } pub fn get_simple_feature_flag(&self, flag: &str) -> Option where - T: std::str::FromStr, + T: FromStr + Debug, + ::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::().ok(), + FlagValue::Value(value) => value + .parse::() + .inspect_err(|e| tracing::warn!("Failed to parse flag value: {e:#?}")) + .ok(), _ => None, }) } + + pub fn get_feature_flag_credential_mode(&self) -> Option { + self.get_feature_flag("zkNyms", "credentialMode") + } } pub fn discover_networks(config_path: &Path) -> anyhow::Result { diff --git a/nym-vpn-core/crates/nym-vpnd/src/service/vpn_service.rs b/nym-vpn-core/crates/nym-vpnd/src/service/vpn_service.rs index 891a28de43..c08fa51b40 100644 --- a/nym-vpn-core/crates/nym-vpnd/src/service/vpn_service.rs +++ b/nym-vpn-core/crates/nym-vpnd/src/service/vpn_service.rs @@ -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, @@ -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 = @@ -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) -}