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

View File

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

View File

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

View File

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