Update config_manager to check from three sources of configuration #105
No reviewers
Labels
No Label
bug
documentation
duplicate
enhancement
help wanted
invalid
maintenance
peach-lib
peach-network
peach-oled
peach-stats
peach-web
question
refactor
wontfix
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: PeachCloud/peach-workspace#105
Loading…
Reference in New Issue
No description provided.
Delete Branch "config"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
based on #104
todo:
This PR is tested and working via an example I made in
peach-lib/examples/config.rs
.With this config system it checks config keys in this order:
/var/lib/peachcloud/config.yml
but this path is itself configurable via setting an env variable PEACH_CONFIG_PATH)The primary interfaces for reading and saving config values are:
get_config_value(key: &str) -> Result<String, PeachError>
save_config_value(key: &str, value: &str) -> Result<HashMap<String, String>, PeachError>
get_config_value does the appropriate lookup checking the three places.
save_config_value saves the given key, value to the configuration yaml.
Notes:
WIP: Working on updating config_managerto Working on updating config_managerWorking on updating config_managerto Update config_manager to check from three sources of configurationBeautiful! I love the layered structure you've created; it feels very robust and the API for interacting with the config is clear and concise.
I just made one small suggestion with the dependency version and pointed out a tiny typo in a comment.
@ -21,3 +21,4 @@ serde_json = "1.0"
serde_yaml = "0.8"
toml = "0.5"
sha3 = "0.10"
lazy_static = "1.4.0"
Could we change this to
1.4
? I got into a bad habit of pinning dependencies (specifying them all the way down to the patch version, ie.x.x.x
) but I've been trying to undo that.Pinning dependencies increases the likelihood that the compiler needs to compile several versions of the same crate. For example, if we have
lazy_static = "1.4.0"
and one of our dependencies useslazy_static = "1.4.1"
then both of those will need to be compiled and bundled in our binary.interesting!
in other languages, I've assumed that pinning more precisely is preferrable, because then the library won't "shift under your feet" and change without you realizing (even though with minor number updates its supposed to not be breaking changes, any change is still a possible new bug),
but that makes sense in the rust case specifically it helps reduce compilation time and binary size
@ -0,0 +1,11 @@
use peach_lib::config_manager::{get_config_value, save_config_value};
It's a neat pattern to include a code usage pattern as an example like this.
yes I think so too!
I originally made this file just out of convenience of needing a way to test my code, but then thought it was kind of a neat pattern to keep little code examples around here.
@ -103,0 +159,4 @@
// insert new key/value
peach_config.insert(key.to_string(), value.to_string());
// save hte modified hashmap to disc
Tiny typo here on
save hte
.