Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3380572
D6858.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D6858.diff
View Options
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
@@ -5,6 +5,7 @@
pub mod config;
pub mod constants;
pub mod database;
+pub mod service;
fn configure_logging() -> Result<()> {
let filter = EnvFilter::builder()
diff --git a/services/feature-flags/src/service.rs b/services/feature-flags/src/service.rs
new file mode 100644
--- /dev/null
+++ b/services/feature-flags/src/service.rs
@@ -0,0 +1,57 @@
+use crate::database::{DatabaseClient, FeatureConfig, Platform};
+use comm_services_lib::database::Error;
+use std::collections::HashSet;
+
+pub struct FeatureFlagsService {
+ _db: DatabaseClient,
+}
+
+impl FeatureFlagsService {
+ pub fn new(db_client: DatabaseClient) -> Self {
+ FeatureFlagsService { _db: db_client }
+ }
+
+ pub async fn _enabled_features_set(
+ db: &DatabaseClient,
+ platform: Platform,
+ code_version: i32,
+ is_staff: bool,
+ ) -> Result<HashSet<String>, Error> {
+ let features_config = db.get_features_configuration(platform).await?;
+ Ok(
+ features_config
+ .into_values()
+ .filter_map(|config| {
+ Self::_feature_name_if_enabled(code_version, is_staff, config)
+ })
+ .collect(),
+ )
+ }
+
+ fn _feature_name_if_enabled(
+ code_version: i32,
+ is_staff: bool,
+ feature_config: FeatureConfig,
+ ) -> Option<String> {
+ feature_config
+ .config
+ .keys()
+ .filter(|version| *version <= &code_version)
+ .max()
+ .and_then(|version| feature_config.config.get(version))
+ .map(|config| {
+ if is_staff {
+ config.staff
+ } else {
+ config.non_staff
+ }
+ })
+ .and_then(|is_enabled| {
+ if is_enabled {
+ Some(feature_config.name)
+ } else {
+ None
+ }
+ })
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 12:41 AM (21 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2595289
Default Alt Text
D6858.diff (1 KB)
Attached To
Mode
D6858: [services][feature-flags] Determine enabled features set
Attached
Detach File
Event Timeline
Log In to Comment