From 2d45af26b68fa4954b1e14bbd94f97669d7cabae Mon Sep 17 00:00:00 2001 From: Philipp Kolberg Date: Sun, 17 Dec 2023 15:12:13 +0100 Subject: [PATCH] Rename feature_flags to experimental_client_feature_flags Additionally, use a caret (^) instead of an exclamation mark (!) to disable features --- src/api/core/mod.rs | 11 +++++------ src/config.rs | 15 +++++++-------- src/util.rs | 10 +++++----- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs index f415aade..8a17793b 100644 --- a/src/api/core/mod.rs +++ b/src/api/core/mod.rs @@ -54,7 +54,7 @@ use crate::{ auth::Headers, db::DbConn, error::Error, - util::{get_reqwest_client, parse_feature_flags}, + util::{get_reqwest_client, parse_experimental_client_feature_flags}, }; #[derive(Serialize, Deserialize, Debug)] @@ -192,8 +192,8 @@ fn version() -> Json<&'static str> { #[get("/config")] fn config() -> Json { let domain = crate::CONFIG.domain(); - let feature_states = parse_feature_flags(&crate::CONFIG.feature_flags()); - let mut config = json!({ + let feature_states = parse_experimental_client_feature_flags(&crate::CONFIG.experimental_client_feature_flags()); + Json(json!({ // Note: The clients use this version to handle backwards compatibility concerns // This means they expect a version that closely matches the Bitwarden server version // We should make sure that we keep this updated when we support the new server features @@ -213,10 +213,9 @@ fn config() -> Json { "notifications": format!("{domain}/notifications"), "sso": "", }, + "feature_states": feature_states, "object": "config", - }); - config["featureStates"] = serde_json::to_value(feature_states).unwrap(); - Json(config) + })) } pub fn catchers() -> Vec { diff --git a/src/config.rs b/src/config.rs index e0899831..4acacf9e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,7 +9,7 @@ use reqwest::Url; use crate::{ db::DbConnType, error::Error, - util::{get_env, get_env_bool, parse_feature_flags}, + util::{get_env, get_env_bool, parse_experimental_client_feature_flags}, }; static CONFIG_FILE: Lazy = Lazy::new(|| { @@ -548,9 +548,9 @@ make_config! { authenticator_disable_time_drift: bool, true, def, false; /// Customize the enabled feature flags on the clients |> This is a comma separated list of feature flags to en-/disable. - /// Features are enabled by default which can be overridden by prefixing the feature with a `!`. + /// Features are enabled by default which can be overridden by prefixing the feature with a `^`. /// Autofill v2 is disabled by default because it is causing issues https://github.com/dani-garcia/vaultwarden/discussions/4052 - feature_flags: String, false, def, "!autofill-v2,fido2-vault-credentials".to_string(); + experimental_client_feature_flags: String, false, def, "^autofill-v2,fido2-vault-credentials".to_string(); /// Require new device emails |> When a user logs in an email is required to be sent. /// If sending the email fails the login attempt will fail. @@ -756,16 +756,15 @@ fn validate_config(cfg: &ConfigItems) -> Result<(), Error> { ) } - const SUPPORTED_FLAGS: &[&str] = &[ + const KNOWN_FLAGS: &[&str] = &[ "autofill-overlay", "autofill-v2", "browser-fileless-import", - "display-kdf-iteration-warning", "fido2-vault-credentials", ]; - for flag in parse_feature_flags(&cfg.feature_flags).keys() { - if !SUPPORTED_FLAGS.contains(&flag.as_str()) { - err!(format!("Feature flag {flag:?} is not supported.")); + for flag in parse_experimental_client_feature_flags(&cfg.experimental_client_feature_flags).keys() { + if !KNOWN_FLAGS.contains(&flag.as_str()) { + err!(format!("The experimental client feature flag {flag:?} is unrecognized. Please ensure the feature flag is spelled correctly, a caret (^) is used for disabling and that it is supported in this version.")); } } diff --git a/src/util.rs b/src/util.rs index a2ca8acc..bc1ca11a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -749,14 +749,14 @@ pub fn convert_json_key_lcase_first(src_json: Value) -> Value { } } -/// Parses the feature flags string into a HashMap. -pub fn parse_feature_flags(feature_flags: &str) -> HashMap { - let feature_flags_lowercase = feature_flags.to_lowercase(); - let features = feature_flags_lowercase.split(',').map(|f| f.trim()).collect::>(); +/// Parses the experimental client feature flags string into a HashMap. +pub fn parse_experimental_client_feature_flags(experimental_client_feature_flags: &str) -> HashMap { + let experimental_client_feature_flags_lowercase = experimental_client_feature_flags.to_lowercase(); + let features = experimental_client_feature_flags_lowercase.split(',').map(|f| f.trim()).collect::>(); let mut feature_states: HashMap = HashMap::new(); for feature in features { - let is_enabled = !feature.starts_with('!'); + let is_enabled = !feature.starts_with('^'); let flag = if is_enabled { feature } else {