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
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ Make sure that you replace "{repo-root-dir}" with the repository root directory
---- provider_settings.yaml ----<br>
`provider_authority: "0.0.0.0:4010"`<br>
`invehicle_digital_twin_uri: "http://0.0.0.0:5010"`<br><br>
1. In the top window, run:<br><br>
1. In the top window, run (config files will be loaded from the current working directory):<br><br>
`./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.

`IBEJI_HOME=/etc/ibeji ./invehicle-digital-twin`<br>
1. In the middle window, run:<br><br>
`./seat-massager-provider`<br>
1. In the bottom window, run:<br><br>
Expand Down
9 changes: 8 additions & 1 deletion core/common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use strum_macros::Display;
use tokio::time::{sleep, Duration};
use tonic::{Request, Status};

const IBEJI_HOME_VAR_NAME: &str = "IBEJI_HOME";

/// An identifier used when discovering a service through Chariott.
#[derive(Debug, Deserialize)]
pub struct ServiceIdentifier {
Expand Down Expand Up @@ -41,8 +43,13 @@ pub fn load_settings<T>(config_filename: &str) -> Result<T, ConfigError>
where
T: for<'de> serde::Deserialize<'de>,
{
let config_filename_path = match std::env::var(IBEJI_HOME_VAR_NAME) {
Ok(s) => format!("{}/{}", s, config_filename),
_ => config_filename.to_owned()
};

let config =
Config::builder().add_source(File::new(config_filename, FileFormat::Yaml)).build()?;
Config::builder().add_source(File::new(config_filename_path.as_str(), FileFormat::Yaml)).build()?;

config.try_deserialize()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.
// SPDX-License-Identifier: MIT

use config::{Config, File, FileFormat};
use common::utils;
use serde_derive::Deserialize;

const CONFIG_FILENAME: &str = "invehicle_digital_twin_settings";
Expand All @@ -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 settings: Settings = config.try_deserialize().unwrap();
let settings = utils::load_settings(CONFIG_FILENAME).unwrap();

settings
}