Skip to content
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

adding IBEJI_HOME env var for loading the invehicle digital twin config file #61

Merged
merged 8 commits into from
Oct 30, 2023

Conversation

odra
Copy link
Contributor

@odra odra commented Oct 25, 2023

Changes

  • Adds an optional "IBEJI_HOME" env var support to be used when using the invehicle-digital-twin binary

Verification

Running the binary with and without the env var should return the correct error path:

# without (should work as it is)
$ ./target/debug/invehicle-digital-twin 
[2023-10-25T15:13:40Z INFO  invehicle_digital_twin] The In-Vehicle Digital Twin Service has started.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: configuration file "invehicle_digital_twin_settings" not found', core/invehicle-digital-twin/src/invehicle_digital_twin_config.rs:25:98
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

# using the env var:
$ IBEJI_HOME=/etc/ibeji ./target/debug/invehicle-digital-twin 
[2023-10-25T15:13:53Z INFO  invehicle_digital_twin] The In-Vehicle Digital Twin Service has started.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: configuration file "/etc/ibeji/invehicle_digital_twin_settings" not found', core/invehicle-digital-twin/src/invehicle_digital_twin_config.rs:25:98
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Copy link
Contributor

@devkelley devkelley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting a PR @odra. Please take a look at the minor comments below.

@@ -15,8 +16,13 @@ pub struct Settings {

/// Load the settings.
pub fn load_settings() -> Settings {
let config_filename_path = match env::var("IBEJI_HOME") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make IBEJI_HOME a constant in "/core/common/src/utils.rs".

let config_filename_path = match env::var("IBEJI_HOME") {
Ok(s) => format!("{}/{}", s, CONFIG_FILENAME),
_ => CONFIG_FILENAME.to_owned()
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this IBEJI_HOME matching statement to "/core/common/src/utils.rs" in the load_settings<T>(config_filename: &str) method.

Copy link
Contributor

@ashbeitz ashbeitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment. Please take a look.

@@ -15,8 +16,13 @@ pub struct Settings {

/// Load the settings.
pub fn load_settings() -> Settings {
let config_filename_path = match env::var("IBEJI_HOME") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide details on the IBEJI_HOME environment variable in Ibeji's main README.

odra added 2 commits October 27, 2023 07:09
Signed-off-by: Leonardo Rossetti <[email protected]>
Signed-off-by: Leonardo Rossetti <[email protected]>
Copy link
Contributor

@ashbeitz ashbeitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on your recent changes.

BTW: I kicked off the checks for you. Please take a look at their results.

README.md Outdated
`./invehicle-digital-twin`<br>
Use the `IBEJI_HOME` env var to load configuration files from a specific directory: <br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use "variable" rather than "var". This will also fix the associated spelling check error.

@@ -15,10 +15,7 @@ pub struct Settings {

/// Load the settings.
pub fn load_settings() -> Settings {
let config =
Config::builder().add_source(File::new(CONFIG_FILENAME, FileFormat::Yaml)).build().unwrap();
let s = utils::load_settings(CONFIG_FILENAME).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to use a meaningful identifier name rather than single character.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were previously using "settings", rather than "s".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, sorry, forgot to rename it

Signed-off-by: Leonardo Rossetti <[email protected]>
README.md Outdated
`./invehicle-digital-twin`<br>
Use the `IBEJI_HOME` environment variable to load configuration files from a specific directory: <br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your change here is for one specific sample. You could discuss this environment variable before the details for each sample. Alternatively, you could copy your change into each sample's details.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a high level directive makes more sense and scales better. Let me move it upwards.

@ashbeitz
Copy link
Contributor

@odra - Please address the issues raised by the checks. You can ignore the "Alex Recommends - language" checks and the "Lint and Check Markdown" checks, as these are caused by known issues. The other checks must be resolved.

@ashbeitz
Copy link
Contributor

@odra - Please fix the issues that the "Rust CI / static_code_analysis" check detected. Thanks.

odra added 2 commits October 30, 2023 15:49
Signed-off-by: Leonardo Rossetti <[email protected]>
Signed-off-by: Leonardo Rossetti <[email protected]>
@odra
Copy link
Contributor Author

odra commented Oct 30, 2023

I've sent an update. Would you like for me to squash all my commits into a single one?

@ashbeitz
Copy link
Contributor

I've sent an update. Would you like for me to squash all my commits into a single one?

Please do this when you merge in your changes.

I'll kick off the checks again to see if everything looks clean.

@ashbeitz
Copy link
Contributor

@odra - The "Rust CI / static_code_analysis" check is still failing. You need to run "cargo fmt" on your PR branch and push the changes.

Signed-off-by: Leonardo Rossetti <[email protected]>
@odra
Copy link
Contributor Author

odra commented Oct 30, 2023

Just sent a fix :-)

Copy link
Contributor

@ashbeitz ashbeitz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@ashbeitz ashbeitz merged commit 27dffdb into eclipse-ibeji:main Oct 30, 2023
9 of 11 checks passed
@ashbeitz
Copy link
Contributor

@odra - Since you do not have committer privileges, I squashed and merged your changes for you.

@odra
Copy link
Contributor Author

odra commented Oct 30, 2023

No worries, thanks for the review :)

mobicatk pushed a commit to Mobica/EclipseSDV_ibeji that referenced this pull request Apr 24, 2024
…ig file (eclipse-ibeji#61)

* adding IBEJI_HOME env var for loading the invehicle digital twin config file

Signed-off-by: Leonardo Rossetti <[email protected]>

* use common::utils to load config file

Signed-off-by: Leonardo Rossetti <[email protected]>

* IBEJI_HOME env var docs

Signed-off-by: Leonardo Rossetti <[email protected]>

* fix variable name and readme typo

Signed-off-by: Leonardo Rossetti <[email protected]>

* move environment variable instructions

Signed-off-by: Leonardo Rossetti <[email protected]>

* adding code block language

Signed-off-by: Leonardo Rossetti <[email protected]>

* remove unecessary let

Signed-off-by: Leonardo Rossetti <[email protected]>

* static analysis fix

Signed-off-by: Leonardo Rossetti <[email protected]>

---------

Signed-off-by: Leonardo Rossetti <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants