-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-6262] Add basic feature flags support to enable cipher key encryp…
…tion (#638) ## Type of change ``` - [ ] Bug fix - [x] New feature development - [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ``` ## Objective Implement support for some basic feature flagging for the mobile clients, the only flag supported is `enableCipherKeyEncryption`
- Loading branch information
1 parent
5d131f5
commit 29089c5
Showing
7 changed files
with
173 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#[derive(Debug, Default, Clone, serde::Deserialize)] | ||
pub struct Flags { | ||
#[serde(default, rename = "enableCipherKeyEncryption")] | ||
pub enable_cipher_key_encryption: bool, | ||
} | ||
|
||
impl Flags { | ||
pub fn load_from_map(map: std::collections::HashMap<String, bool>) -> Self { | ||
let map = map | ||
.into_iter() | ||
.map(|(k, v)| (k, serde_json::Value::Bool(v))) | ||
.collect(); | ||
serde_json::from_value(serde_json::Value::Object(map)).expect("Valid map") | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_load_empty_map() { | ||
let map = std::collections::HashMap::new(); | ||
let flags = Flags::load_from_map(map); | ||
assert!(!flags.enable_cipher_key_encryption); | ||
} | ||
|
||
#[test] | ||
fn test_load_valid_map() { | ||
let mut map = std::collections::HashMap::new(); | ||
map.insert("enableCipherKeyEncryption".into(), true); | ||
let flags = Flags::load_from_map(map); | ||
assert!(flags.enable_cipher_key_encryption); | ||
} | ||
|
||
#[test] | ||
fn test_load_invalid_map() { | ||
let mut map = std::collections::HashMap::new(); | ||
map.insert("thisIsNotAFlag".into(), true); | ||
let flags = Flags::load_from_map(map); | ||
assert!(!flags.enable_cipher_key_encryption); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters