Bugfix/compat auto config (#812)

* account for no dependent config when auto configuring

* fix config path

* add check for config file to dependency check command
This commit is contained in:
Lucy C
2021-11-18 14:18:12 -07:00
committed by Aiden McClelland
parent 1d1844e092
commit 018b7e972c
2 changed files with 26 additions and 17 deletions

View File

@@ -46,7 +46,7 @@ pub fn validate_configuration(
pub fn validate_dependency_configuration(
name: &str,
config: Config,
config: &Option<Config>,
parent_name: &str,
parent_config: Config,
rules_path: &Path,
@@ -54,7 +54,11 @@ pub fn validate_dependency_configuration(
let rules: Vec<ConfigRuleEntry> = serde_yaml::from_reader(std::fs::File::open(rules_path)?)?;
let mut cfgs = LinearMap::new();
cfgs.insert(parent_name, Cow::Borrowed(&parent_config));
cfgs.insert(name, Cow::Borrowed(&config));
if let Some(config) = config {
cfgs.insert(name, Cow::Borrowed(&config))
} else {
cfgs.insert(name, Cow::Owned(serde_json::Map::new()))
};
let rule_check = rules
.into_iter()
.map(|r| r.check(&parent_config, &cfgs))
@@ -67,7 +71,7 @@ pub fn validate_dependency_configuration(
pub fn apply_dependency_configuration(
package_id: &str,
config: Config,
config: Option<Config>,
dependency_id: &str,
mut dep_config: Config,
rules_path: &Path,
@@ -76,7 +80,10 @@ pub fn apply_dependency_configuration(
serde_yaml::from_reader(std::fs::File::open(rules_path)?)?;
let mut cfgs = LinearMap::new();
cfgs.insert(dependency_id, Cow::Owned(dep_config.clone()));
cfgs.insert(package_id, Cow::Owned(config.clone()));
match config {
Some(config) => cfgs.insert(package_id, Cow::Owned(config.clone())),
None => cfgs.insert(package_id, Cow::Owned(serde_json::Map::new())),
};
let rule_check = rules
.into_iter()
.map(|r| r.apply(dependency_id, &mut dep_config, &mut cfgs))

View File

@@ -201,18 +201,19 @@ fn inner_main() -> Result<(), anyhow::Error> {
("dependency", Some(sub_m)) => match sub_m.subcommand() {
("check", Some(sub_m)) => {
let parent_config = serde_yaml::from_reader(stdin())?;
let config = serde_yaml::from_reader(
File::open(
Path::new(sub_m.value_of("mountpoint").unwrap()).join("start9/config.yaml"),
)
.unwrap(),
)?;
let cfg_path =
Path::new(sub_m.value_of("mountpoint").unwrap()).join("start9/config.yaml");
let config = if cfg_path.exists() {
Some(serde_yaml::from_reader(File::open(cfg_path).unwrap()).unwrap())
} else {
None
};
let rules_path = Path::new(sub_m.value_of("assets").unwrap());
let name = sub_m.value_of("dependent_package_id").unwrap();
let parent_name = sub_m.value_of("dependency_package_id").unwrap();
match validate_dependency_configuration(
name,
config,
&config,
parent_name,
parent_config,
rules_path,
@@ -229,12 +230,13 @@ fn inner_main() -> Result<(), anyhow::Error> {
}
("auto-configure", Some(sub_m)) => {
let dep_config = serde_yaml::from_reader(stdin())?;
let config = serde_yaml::from_reader(
File::open(
Path::new(sub_m.value_of("mountpoint").unwrap()).join("start9/config.yaml"),
)
.unwrap(),
)?;
let cfg_path =
Path::new(sub_m.value_of("mountpoint").unwrap()).join("start9/config.yaml");
let config = if cfg_path.exists() {
Some(serde_yaml::from_reader(File::open(cfg_path).unwrap()).unwrap())
} else {
None
};
let rules_path = Path::new(sub_m.value_of("assets").unwrap());
let package_id = sub_m.value_of("dependent_package_id").unwrap();
let dependency_id = sub_m.value_of("dependency_package_id").unwrap();