-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configuration to be passed in using TEDGE_ environment variables #1790
Conversation
Robot Results
Passed Tests
|
3d49797
to
eb387b7
Compare
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
eb387b7
to
2c5dab5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved. Nice cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really surprised by the fact a write access to the config is required by the tedge connect
command. Only tedge config set
and tedge config reset
should have this access.
config_repository: context.config_repository, | ||
config_repository: context.config_repository.skip_environment_variables(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the tedge connect
require write access to the config?
This seems to an issue:
- I don't see what can be the point here.
- Using
tegde connect
in combination with $ENV setting is one of the main point of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tedge connect
updates tedge.toml with updated MQTT settings. It obviously also updates the mosquitto config with the relevant settings, but making that work in the context of thin-edge running in a container requires some sort of persistence for /etc/tedge
anyway, so I'm not entirely sure what we gain by avoiding using /etc/tedge/tedge.toml
in that case? @reubenmiller can you provide some insight as to how you're expecting this feature to be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering whether instead of opt-out of environment variables entirely when storing values, we should replace the store
method with an update_toml
method that takes an argument impl FnOnce(Config) -> Config
. The repository calls that with only the TOML config, and saves whatever is returned back to the TOML file. This allows us to better scope the updates to the TOML config in cases like this where we may want to refer to environment variables but also update the persistent configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tedge connect updates tedge.toml with updated MQTT settings.
This comes as a surprise to me. I really don't understand what's the point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tedge connect
updates tedge.toml with updated MQTT settings. It obviously also updates the mosquitto config with the relevant settings, but making that work in the context of thin-edge running in a container requires some sort of persistence for/etc/tedge
anyway, so I'm not entirely sure what we gain by avoiding using/etc/tedge/tedge.toml
in that case? @reubenmiller can you provide some insight as to how you're expecting this feature to be used?
Idea is to create multiple containers where each container runs one component of thin-edge, e.g. one container for tedge-agent, one for tedge-mapper-c8y, one for mosquitto. Each container will be configured to use an external mqtt broker by setting the mqtt client settings to point to the mosquitto broker (via environment variables). The actual values inside the tedge.toml don't need to store the values set in the environment variables.
The tedge connect
command will only be used to setup the mosquitto broker bridge settings (or in some cases it will not be used at all, as technically the user can create the bridge settings themselves).
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
a2986fa
to
128a77a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved.
The new way to update the file is simpler as well as the types used to distinguish the FileOnly
behavior from FileAndEnvironment
.
fn store(&self, config: &TEdgeConfig) -> Result<(), TEdgeConfigError> { | ||
let toml = toml::to_string_pretty(&config.data)?; | ||
|
||
// Create `$HOME/.tedge` or `/etc/tedge` directory in case it does not exist yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea to use $HOME/.tedge
has been fully deprecated. Now, the default tedge config directory is /etc/tedge
and can be provided on the command line using the --tedge-config
option.
Signed-off-by: James Rhodes <jarhodes314@gmail.com>
b598782
to
9e72593
Compare
Proposed changes
Add support for reading
TEDGE_
prefixed environment variables, as detailed in #1783.e.g.
Types of changes
Paste Link to the issue
#1783
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments
The main change, using figment instead of deserialising directly from the TOML file is quite simple, but generating error messages which contain the relevant environment variable names requires quite a bit of effort. When using things like this though, I think it's really helpful to understand where an incorrect configuration came from, so I think this is ultimately worth the effort. I've also refactored the warnings to use
serde_ignored
(again, in an annoyingly complex way), but this does mean we no longer needtedge-derive
or thedisplay_unknown_for
macro which had to be called manually for every field.