-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2105 from massalabs/repair_config_override
repair config override
- Loading branch information
Showing
2 changed files
with
18 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// Copyright (c) 2021 MASSA LABS <[email protected]> | ||
|
||
use std::path::Path; | ||
|
||
use directories::ProjectDirs; | ||
use massa_bootstrap::settings::BootstrapSettings; | ||
use massa_consensus::ConsensusSettings; | ||
|
@@ -16,15 +18,23 @@ lazy_static::lazy_static! { | |
// TODO: this code is duplicated from /massa-client/settings.rs and should be part of a custom crate | ||
pub static ref SETTINGS: Settings = { | ||
let mut settings = config::Config::default(); | ||
|
||
let config_path = std::env::var("MASSA_CONFIG_PATH").unwrap_or_else(|_| "base_config/config.toml".to_string()); | ||
settings.merge(config::File::with_name(&config_path)).unwrap_or_else(|_| panic!("failed to read {} config {}", config_path, std::env::current_dir().unwrap().as_path().to_str().unwrap())); | ||
|
||
let config_override_path = std::env::var("MASSA_CONFIG_OVERRIDE_PATH").unwrap_or_else(|_| "config/config.toml".to_string()); | ||
if Path::new(&config_override_path).is_file() { | ||
settings.merge(config::File::with_name(&config_override_path)).unwrap_or_else(|_| panic!("failed to read {} override config {}", config_override_path, std::env::current_dir().unwrap().as_path().to_str().unwrap())); | ||
} | ||
|
||
if let Some(proj_dirs) = ProjectDirs::from("com", "MassaLabs", "massa-node") { // Portable user config loading | ||
let user_config_path = proj_dirs.config_dir(); | ||
if user_config_path.exists() { | ||
let path_str = user_config_path.to_str().unwrap(); | ||
settings.merge(config::File::with_name(path_str)).unwrap_or_else(|_| panic!("failed to read {} user config", path_str)); | ||
} | ||
} | ||
|
||
settings.merge(config::Environment::with_prefix("MASSA_NODE")).unwrap(); | ||
settings.try_into().unwrap() | ||
}; | ||
|