Skip to content

Commit

Permalink
Merge pull request #2105 from massalabs/repair_config_override
Browse files Browse the repository at this point in the history
repair config override
  • Loading branch information
damip authored Jan 9, 2022
2 parents c6926dc + 42adb59 commit 277c6a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion massa-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

use directories::ProjectDirs;
use serde::Deserialize;
use std::net::IpAddr;
use std::{net::IpAddr, path::Path};

lazy_static::lazy_static! {
// TODO: this code is duplicated from /massa-node/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-client") { // Portable user config loading
let user_config_path = proj_dirs.config_dir();
if user_config_path.exists() {
Expand Down
10 changes: 10 additions & 0 deletions massa-node/src/settings.rs
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;
Expand All @@ -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()
};
Expand Down

0 comments on commit 277c6a0

Please sign in to comment.