compat: fix dependency command and update indexmap to btreemap

This commit is contained in:
Chris Guida
2021-09-28 16:27:11 -05:00
committed by Aiden McClelland
parent 7622616856
commit 11a7a3737b
4 changed files with 137 additions and 70 deletions

141
compat/Cargo.lock generated
View File

@@ -61,9 +61,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.43"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf"
checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1"
dependencies = [
"backtrace",
]
@@ -291,7 +291,7 @@ dependencies = [
"serde_json",
"serde_urlencoded",
"thiserror",
"tokio 1.11.0",
"tokio 1.12.0",
"tokio-util",
"url",
"winapi",
@@ -833,6 +833,7 @@ dependencies = [
"libc",
"log",
"nix 0.22.1",
"num",
"openssh-keys",
"openssl",
"patch-db",
@@ -849,6 +850,7 @@ dependencies = [
"rpc-toolkit",
"rust-argon2",
"scopeguard",
"sequence_trie",
"serde",
"serde_json",
"serde_yaml",
@@ -858,7 +860,7 @@ dependencies = [
"stderrlog",
"tar",
"thiserror",
"tokio 1.11.0",
"tokio 1.12.0",
"tokio-compat-02",
"tokio-stream",
"tokio-tar",
@@ -1208,7 +1210,7 @@ dependencies = [
"http",
"indexmap",
"slab",
"tokio 1.11.0",
"tokio 1.12.0",
"tokio-util",
"tracing",
]
@@ -1273,9 +1275,9 @@ dependencies = [
[[package]]
name = "http"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "527e8c9ac747e28542699a951517aa9a6945af506cd1f2e1b53a576c17b6cc11"
checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b"
dependencies = [
"bytes 1.1.0",
"fnv",
@@ -1329,7 +1331,7 @@ dependencies = [
"itoa",
"pin-project-lite 0.2.7",
"socket2",
"tokio 1.11.0",
"tokio 1.12.0",
"tower-service",
"tracing",
"want",
@@ -1344,7 +1346,7 @@ dependencies = [
"bytes 1.1.0",
"hyper",
"native-tls",
"tokio 1.11.0",
"tokio 1.12.0",
"tokio-native-tls",
]
@@ -1360,7 +1362,7 @@ dependencies = [
"hyper",
"log",
"sha-1 0.9.8",
"tokio 1.11.0",
"tokio 1.12.0",
"tokio-tungstenite",
]
@@ -1374,7 +1376,7 @@ dependencies = [
"hex",
"hyper",
"pin-project",
"tokio 1.11.0",
"tokio 1.12.0",
]
[[package]]
@@ -1570,9 +1572,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.101"
version = "0.2.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21"
checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6"
[[package]]
name = "libsqlite3-sys"
@@ -1737,19 +1739,6 @@ dependencies = [
"libc",
]
[[package]]
name = "nix"
version = "0.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df8e5e343312e7fbeb2a52139114e9e702991ef9c2aea6817ff2440b35647d56"
dependencies = [
"bitflags",
"cc",
"cfg-if",
"libc",
"memoffset",
]
[[package]]
name = "nix"
version = "0.22.1"
@@ -1796,6 +1785,40 @@ dependencies = [
"winapi",
]
[[package]]
name = "num"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606"
dependencies = [
"num-bigint",
"num-complex",
"num-integer",
"num-iter",
"num-rational",
"num-traits",
]
[[package]]
name = "num-bigint"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74e768dff5fb39a41b3bcd30bb25cf989706c90d028d1ad71971987aa309d535"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-complex"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085"
dependencies = [
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.44"
@@ -1806,6 +1829,29 @@ dependencies = [
"num-traits",
]
[[package]]
name = "num-iter"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a"
dependencies = [
"autocfg",
"num-bigint",
"num-integer",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.14"
@@ -1951,18 +1997,17 @@ dependencies = [
"async-trait",
"fd-lock-rs",
"futures",
"indexmap",
"json-patch",
"json-ptr",
"lazy_static",
"log",
"nix 0.20.1",
"nix 0.22.1",
"patch-db-macro",
"serde",
"serde_cbor 0.11.1",
"serde_json",
"thiserror",
"tokio 1.11.0",
"tokio 1.12.0",
]
[[package]]
@@ -2452,7 +2497,7 @@ dependencies = [
"serde_json",
"serde_urlencoded",
"time 0.2.27",
"tokio 1.11.0",
"tokio 1.12.0",
"tokio-native-tls",
"tokio-socks",
"url",
@@ -2514,7 +2559,7 @@ dependencies = [
"serde_cbor 0.11.2",
"serde_json",
"thiserror",
"tokio 1.11.0",
"tokio 1.12.0",
"url",
"yajrc",
]
@@ -2692,6 +2737,12 @@ dependencies = [
"pest",
]
[[package]]
name = "sequence_trie"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ee22067b7ccd072eeb64454b9c6e1b33b61cd0d49e895fd48676a184580e0c3"
[[package]]
name = "serde"
version = "1.0.130"
@@ -2741,9 +2792,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.67"
version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950"
checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8"
dependencies = [
"indexmap",
"itoa",
@@ -3022,7 +3073,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14302b678d9c76b28f2e60115211e25e0aabc938269991745a169753dc00e35c"
dependencies = [
"once_cell",
"tokio 1.11.0",
"tokio 1.12.0",
"tokio-rustls",
]
@@ -3375,9 +3426,9 @@ dependencies = [
[[package]]
name = "tokio"
version = "1.11.0"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4efe6fc2395938c8155973d7be49fe8d03a843726e285e100a8a383cc0154ce"
checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc"
dependencies = [
"autocfg",
"bytes 1.1.0",
@@ -3403,7 +3454,7 @@ dependencies = [
"once_cell",
"pin-project-lite 0.2.7",
"tokio 0.2.25",
"tokio 1.11.0",
"tokio 1.12.0",
"tokio-stream",
]
@@ -3425,7 +3476,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
dependencies = [
"native-tls",
"tokio 1.11.0",
"tokio 1.12.0",
]
[[package]]
@@ -3435,7 +3486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6"
dependencies = [
"rustls",
"tokio 1.11.0",
"tokio 1.12.0",
"webpki",
]
@@ -3448,7 +3499,7 @@ dependencies = [
"either",
"futures-util",
"thiserror",
"tokio 1.11.0",
"tokio 1.12.0",
]
[[package]]
@@ -3459,7 +3510,7 @@ checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f"
dependencies = [
"futures-core",
"pin-project-lite 0.2.7",
"tokio 1.11.0",
"tokio 1.12.0",
"tokio-util",
]
@@ -3472,7 +3523,7 @@ dependencies = [
"futures-core",
"libc",
"redox_syscall 0.2.10",
"tokio 1.11.0",
"tokio 1.12.0",
"tokio-stream",
"xattr",
]
@@ -3486,7 +3537,7 @@ dependencies = [
"futures-util",
"log",
"pin-project",
"tokio 1.11.0",
"tokio 1.12.0",
"tungstenite",
]
@@ -3501,7 +3552,7 @@ dependencies = [
"futures-sink",
"log",
"pin-project-lite 0.2.7",
"tokio 1.11.0",
"tokio 1.12.0",
]
[[package]]
@@ -3530,7 +3581,7 @@ dependencies = [
"serde_derive",
"sha2",
"sha3",
"tokio 1.11.0",
"tokio 1.12.0",
]
[[package]]

View File

@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::path::Path;
use beau_collector::BeauCollector;
@@ -31,7 +32,7 @@ pub fn validate_configuration(
std::fs::rename(config_path.with_extension("tmp"), config_path)?;
// return set result
Ok(SetResult {
depends_on: indexmap::IndexMap::new(),
depends_on: BTreeMap::new(),
// sending sigterm so service is restarted - in 0.3.x services, this is whatever signal is needed to send to the process to pick up the configuration
signal: Some(nix::sys::signal::SIGTERM),
})
@@ -43,16 +44,17 @@ pub fn validate_configuration(
pub fn validate_dependency_configuration(
name: &str,
config: Config,
parent_name: &str,
parent_config: Config,
rules_path: &Path,
dependent_config: Config,
) -> Result<(), anyhow::Error> {
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));
cfgs.insert(name, Cow::Borrowed(&dependent_config));
let rule_check = rules
.into_iter()
.map(|r| r.check(&config, &cfgs))
.map(|r| r.check(&parent_config, &cfgs))
.bcollect::<Vec<_>>();
match rule_check {
Ok(_) => Ok(()),
@@ -62,22 +64,22 @@ pub fn validate_dependency_configuration(
pub fn apply_dependency_configuration(
name: &str,
mut config: Config,
config: Config,
parent_name: &str,
mut parent_config: Config,
rules_path: &Path,
dependent_config: Config,
) -> Result<Config, anyhow::Error> {
let rules: Vec<ConfigRuleEntryWithSuggestions> =
serde_yaml::from_reader(std::fs::File::open(rules_path)?)?;
let mut cfgs = LinearMap::new();
cfgs.insert(parent_name, Cow::Owned(parent_config.clone()));
cfgs.insert(name, Cow::Owned(config.clone()));
cfgs.insert(name, Cow::Owned(dependent_config.clone()));
let rule_check = rules
.into_iter()
.map(|r| r.apply(name, &mut config, &mut cfgs))
.map(|r| r.apply(parent_name, &mut parent_config, &mut cfgs))
.bcollect::<Vec<_>>();
match rule_check {
Ok(_) => Ok(config),
Err(e) => Err(anyhow!("{}", e))
Ok(_) => Ok(parent_config),
Err(e) => Err(anyhow!("{}", e)),
}
}
}

View File

@@ -114,7 +114,7 @@ impl ConfigRuleEntry {
cfgs: &LinearMap<&str, Cow<Config>>,
) -> Result<(), anyhow::Error> {
if !(self.rule.compiled)(cfg, cfgs) {
anyhow::anyhow!("{}", self.description);
return Err(anyhow::anyhow!("{}", self.description))
}
Ok(())
}

View File

@@ -76,6 +76,11 @@ fn inner_main() -> Result<(), anyhow::Error> {
SubCommand::with_name("dependency")
.subcommand(
SubCommand::with_name("check")
.arg(
Arg::with_name("dependent_package_id")
.help("Package identifier of this package (the child/depdendent)")
.required(true),
)
.arg(
Arg::with_name("dependency_package_id")
.help("Identifier of the dependency")
@@ -94,9 +99,14 @@ fn inner_main() -> Result<(), anyhow::Error> {
)
.subcommand(
SubCommand::with_name("auto-configure")
.arg(
Arg::with_name("dependent_package_id")
.help("Package identifier of this package (the child/depdendent)")
.required(true),
)
.arg(
Arg::with_name("dependency_package_id")
.help("Package identifier of the dependency")
.help("Package identifier of the parent/dependency")
.required(true),
)
.arg(
@@ -200,20 +210,22 @@ fn inner_main() -> Result<(), anyhow::Error> {
},
("dependency", Some(sub_m)) => match sub_m.subcommand() {
("check", Some(sub_m)) => {
let dependency_config = serde_yaml::from_reader(stdin())?;
let dependent_config = serde_yaml::from_reader(
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 rules_path = Path::new(sub_m.value_of("assets").unwrap());
let name = sub_m.value_of("dependency_package_id").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,
dependency_config,
name,
config,
parent_name,
parent_config,
rules_path,
dependent_config,
) {
Ok(a) => {
serde_yaml::to_writer(stdout(), &a)?;
@@ -226,20 +238,22 @@ fn inner_main() -> Result<(), anyhow::Error> {
}
}
("auto-configure", Some(sub_m)) => {
let dependency_config = serde_yaml::from_reader(stdin())?;
let dependent_config = serde_yaml::from_reader(
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 rules_path = Path::new(sub_m.value_of("assets").unwrap());
let name = sub_m.value_of("dependency_package_id").unwrap();
let name = sub_m.value_of("dependent_package_id").unwrap();
let parent_name = sub_m.value_of("dependency_package_id").unwrap();
match apply_dependency_configuration(
name,
dependency_config,
config,
parent_name,
parent_config,
rules_path,
dependent_config,
) {
Ok(a) => {
serde_yaml::to_writer(stdout(), &a)?;