Define configuration architecture #37
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#37
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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?
As mentioned briefly in PR#36.
Our web application has a configuration file (
Rocket.toml
) and we have also been considering implementing aPeach.toml
configuration file for all other Peach-related settings.The path to an alternate Rocket configuration file (
.toml
) can be defined using theROCKET_CONFIG
environment variable (Configuration: Default Provider docs).@notplants raised the idea of using Figment to manage our configuration landscape. I'd like to learn more about Figment and how it works. My initial thought is to avoid it if possible and aim for One Config To Rule Them All.
Here's an example
toml
file as a starting point for further config discussions:Further thoughts about this:
We can either ship the
.toml
file as part of the config or we could hardcode the default config and write it to file if not found (I'm leaning towards the second option...it also gives us the option of exposing a "restore defaults" action).Note currently we have Rocket.toml in /usr/share/peach-web/Rocket.toml (because /usr/share/peach-web was set as the working directory for Rocket),
and all other peach-configurations are in /var/lib/peachcloud.
I still think it will be good to ensure all configurations are in one folder, so we should aim to combine these in some way (either through a new config management scheme, as part of this issue, or by putting the peach-web working directory inside of /var/lib/peachcloud)
notplants' config comments from PR #70:
...
Another reason in support of figment is that Rocket already depends on Figment, so using Figment for our non-rocket configuration doesn't add an extra dependency.
I also don't think our current setup is that confusing, we would just need to document we have configurations stored in three places:
But there would be some gained extra clarity by combining these in some way.
another possibility short of using figment for everything (and thus having to also figure out how to make figment read/writeable), perhaps could also make PEACH_STANDALONE_MODE a rocket config, so there are two types of configurations instead of three:
the main strange thing about this would be that I think rocket configs require ROCKET_ before the env variable, which is kind of weird.
@notplants
This sounds like a neat option to me; all web-app-related config goes in the Rocket config file and all other peach-related config goes in
/var/lib/peachcloud.config.yml
We could even store the Rocket config in
/var/lib/Rocket.toml
so that it's alongside thepeachcloud
config file (if we wanted to keep them together), and then set theROCKET_CONFIG
env var to point to the file path.I personally don't mind having more than one config file if there is clear separation of intent / purpose and good documentation.
I believe this is a great usecase for Rocket's Managed State feature. So we'd load the config during the building phase to set the initial values (reading them into managed state and retrieving them via the
&State
request guard) and then each runtime change in state results in a) a write to the config file, and b) a write to the managed state.I'm not 100% sure that it's possible to write to managed state but my guess is that it must be possible if the initial state value is defined as
mut
.interesting about Managed State. it sounds like close, but I have trouble imagining exactly what it would look like, and how this would also interact with peach-config which is interacting with the configs outside of a Rocket context.
the other approach I was thinking about was to modify the load_peach_config and save_peach_config functions in config_manager, to use figment. Then theoretically all of the other code that currently interacts with configs, might not need to change. then, the RocketBuild phase could also call load_peach_config and pass this same config into Rocket (so that disable_auth and peach_standalone_mode are also there as needed). in other words, in this approach, load_peach_config gets called once during the rocket build phase, and these initially loaded values are not read-writeable (aka to change a value of PEACH_STANDALONE_MODE or disable_auth... you have to restart rocket after changing the value... which is fine), and all the other config values are read-writeable, but they get re-loaded whenever they are used, as load_peach_config gets called whenever they are accessed.
however, one could argue there is even a downside of the read-writeable configs being able to be alternatively set with ENV variables... its maybe a bit counter-intuitive... another argument to keep it as two configs... one for env variables which require a rocket restart to change (currently disable_auth and peach_standalone_mode)... and everything else which is read-writeable without a rocket restart in config.yml. In this two config model we don't really need to change anything, other than possibly moving peach_standalone_mode to be a rocket config like disable_auth.
This sounds like the simplest approach to me 👍