Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix credential mode feature flag #1737

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading