-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(offline-mode): Add support for offline handler (#16)
* feat(offline-mode): Add support for offline handler * bump minor version
- Loading branch information
1 parent
38a115a
commit 793ca03
Showing
6 changed files
with
262 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "flagsmith" | ||
version = "1.3.0" | ||
version = "1.4.0" | ||
authors = ["Gagan Trivedi <[email protected]>"] | ||
edition = "2021" | ||
license = "BSD-3-Clause" | ||
|
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,44 @@ | ||
use flagsmith_flag_engine::environments::Environment; | ||
use std::fs; | ||
|
||
pub trait OfflineHandler { | ||
fn get_environment(&self) -> Environment; | ||
} | ||
|
||
pub struct LocalFileHandler { | ||
environment: Environment, | ||
} | ||
|
||
impl LocalFileHandler { | ||
pub fn new(environment_document_path: &str) -> Result<Self, std::io::Error> { | ||
// Read the environment document from the specified path | ||
let environment_document = fs::read(environment_document_path)?; | ||
|
||
// Deserialize the JSON into EnvironmentModel | ||
let environment: Environment = serde_json::from_slice(&environment_document)?; | ||
|
||
// Create and initialize the LocalFileHandler | ||
let handler = LocalFileHandler { environment }; | ||
|
||
Ok(handler) | ||
} | ||
} | ||
|
||
impl OfflineHandler for LocalFileHandler { | ||
fn get_environment(&self) -> Environment { | ||
self.environment.clone() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_local_file_handler() { | ||
let handler = LocalFileHandler::new("tests/fixtures/environment.json").unwrap(); | ||
|
||
let environment = handler.get_environment(); | ||
assert_eq!(environment.api_key, "B62qaMZNwfiqT76p38ggrQ"); | ||
} | ||
} |
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,58 @@ | ||
{ | ||
"api_key": "B62qaMZNwfiqT76p38ggrQ", | ||
"project": { | ||
"name": "Test project", | ||
"organisation": { | ||
"feature_analytics": false, | ||
"name": "Test Org", | ||
"id": 1, | ||
"persist_trait_data": true, | ||
"stop_serving_flags": false | ||
}, | ||
"id": 1, | ||
"hide_disabled_flags": false, | ||
"segments": [ | ||
{ | ||
"id": 1, | ||
"name": "Test Segment", | ||
"feature_states":[], | ||
"rules": [ | ||
{ | ||
"type": "ALL", | ||
"conditions": [], | ||
"rules": [ | ||
{ | ||
"type": "ALL", | ||
"rules": [], | ||
"conditions": [ | ||
{ | ||
"operator": "EQUAL", | ||
"property_": "foo", | ||
"value": "bar" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
"segment_overrides": [], | ||
"id": 1, | ||
"feature_states": [ | ||
{ | ||
"multivariate_feature_state_values": [], | ||
"feature_state_value": "some_value", | ||
"id": 1, | ||
"featurestate_uuid": "40eb539d-3713-4720-bbd4-829dbef10d51", | ||
"feature": { | ||
"name": "feature_1", | ||
"type": "STANDARD", | ||
"id": 1 | ||
}, | ||
"segment_id": null, | ||
"enabled": true | ||
} | ||
] | ||
} |
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