Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3380754
D6856.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6856.diff
View Options
diff --git a/services/feature-flags/src/database.rs b/services/feature-flags/src/database.rs
new file mode 100644
--- /dev/null
+++ b/services/feature-flags/src/database.rs
@@ -0,0 +1,60 @@
+use crate::constants::{
+ FEATURE_FLAGS_CONFIG_FIELD, FEATURE_FLAGS_FEATURE_FIELD,
+ FEATURE_FLAGS_NON_STAFF_FIELD, FEATURE_FLAGS_STAFF_FIELD,
+};
+use aws_sdk_dynamodb::model::AttributeValue;
+use comm_services_lib::database::{self, DBItemError};
+use std::collections::HashMap;
+
+#[derive(Debug)]
+pub struct CodeVersionSpecificFeatureConfig {
+ pub staff: bool,
+ pub non_staff: bool,
+}
+
+fn _parse_code_version_specific_feature_config(
+ value: Option<AttributeValue>,
+) -> Result<CodeVersionSpecificFeatureConfig, DBItemError> {
+ let mut code_version_config_map =
+ database::parse_map_attribute(FEATURE_FLAGS_CONFIG_FIELD, value)?;
+ let staff = database::parse_bool_attribute(
+ FEATURE_FLAGS_STAFF_FIELD,
+ code_version_config_map.remove(FEATURE_FLAGS_STAFF_FIELD),
+ )?;
+ let non_staff = database::parse_bool_attribute(
+ FEATURE_FLAGS_NON_STAFF_FIELD,
+ code_version_config_map.remove(FEATURE_FLAGS_NON_STAFF_FIELD),
+ )?;
+ Ok(CodeVersionSpecificFeatureConfig { staff, non_staff })
+}
+
+#[derive(Debug)]
+pub struct FeatureConfig {
+ pub name: String,
+ pub config: HashMap<i32, CodeVersionSpecificFeatureConfig>,
+}
+
+fn _parse_feature_config(
+ mut attribute_value: HashMap<String, AttributeValue>,
+) -> Result<FeatureConfig, DBItemError> {
+ let feature_name = database::parse_string_attribute(
+ FEATURE_FLAGS_FEATURE_FIELD,
+ attribute_value.remove(FEATURE_FLAGS_FEATURE_FIELD),
+ )?;
+ let config_map = database::parse_map_attribute(
+ FEATURE_FLAGS_CONFIG_FIELD,
+ attribute_value.remove(FEATURE_FLAGS_CONFIG_FIELD),
+ )?;
+ let mut config = HashMap::new();
+ for (code_version_string, code_version_config) in config_map {
+ let code_version: i32 =
+ database::parse_number("code_version", code_version_string.as_str())?;
+ let version_config =
+ _parse_code_version_specific_feature_config(Some(code_version_config))?;
+ config.insert(code_version, version_config);
+ }
+ Ok(FeatureConfig {
+ name: feature_name,
+ config,
+ })
+}
diff --git a/services/feature-flags/src/main.rs b/services/feature-flags/src/main.rs
--- a/services/feature-flags/src/main.rs
+++ b/services/feature-flags/src/main.rs
@@ -4,6 +4,7 @@
pub mod config;
pub mod constants;
+pub mod database;
fn configure_logging() -> Result<()> {
let filter = EnvFilter::builder()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 1:55 AM (21 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2595423
Default Alt Text
D6856.diff (2 KB)
Attached To
Mode
D6856: [services][feature-flags] Parse feature flags response from DynamoDB
Attached
Detach File
Event Timeline
Log In to Comment