From 02570fea6fa3a1f4af040f72726e750c4af7375e Mon Sep 17 00:00:00 2001 From: Gregor Reitzenstein Date: Sat, 12 Dec 2020 13:58:04 +0100 Subject: [PATCH] move config to Dhall --- Cargo.lock | 452 ++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 5 +- src/config.rs | 61 +++---- src/db.rs | 4 - src/db/machine.rs | 1 - src/error.rs | 21 ++- src/machine.rs | 2 +- 7 files changed, 478 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c27c8c..d9b7545 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,26 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "abnf" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47feb9fbcef700639ef28e04ca2a87eab8161a01a075ee227b15c90143805462" +dependencies = [ + "nom", +] + +[[package]] +name = "abnf_to_pest" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "372baaa5d3a422d8816b513bcdb2c120078c8614f7ecbcc3baf34a1634bbbe2e" +dependencies = [ + "abnf", + "indexmap", + "itertools", + "pretty", +] + [[package]] name = "aho-corasick" version = "0.7.14" @@ -9,6 +30,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "annotate-snippets" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c96c3d1062ea7101741480185a6a1275eab01cbe8b20e378d1311bc056d2e08" +dependencies = [ + "unicode-width", +] + [[package]] name = "ansi_term" version = "0.11.0" @@ -210,6 +240,36 @@ dependencies = [ "constant_time_eq", ] +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array 0.12.3", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array 0.14.4", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + [[package]] name = "blocking" version = "1.0.2" @@ -224,6 +284,12 @@ dependencies = [ "once_cell", ] +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + [[package]] name = "byteorder" version = "1.3.4" @@ -356,24 +422,18 @@ dependencies = [ "cache-padded", ] -[[package]] -name = "config" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b076e143e1d9538dde65da30f8481c2a6c44040edb8e02b9bf1351edb92ce3" -dependencies = [ - "lazy_static", - "nom", - "serde", - "toml", -] - [[package]] name = "constant_time_eq" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" + [[package]] name = "crossbeam-channel" version = "0.4.4" @@ -406,6 +466,41 @@ dependencies = [ "syn", ] +[[package]] +name = "dhall" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7930c7ac2b3989a07a2a3400bf9f4bc1c65074f330e3ff22b372a4d386fabd0" +dependencies = [ + "abnf_to_pest", + "annotate-snippets", + "hex", + "itertools", + "lazy_static", + "once_cell", + "percent-encoding", + "pest", + "pest_consume", + "pest_generator", + "quote", + "serde", + "serde_cbor", + "sha2", + "url", +] + +[[package]] +name = "dhall_proc_macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf6cff1e2ddd03851652e0cde982b01dc877c9fc9da9ba25ad4241a151945f09" +dependencies = [ + "itertools", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "diflouroborane" version = "0.1.0" @@ -417,7 +512,6 @@ dependencies = [ "capnp-rpc", "capnpc", "clap", - "config", "easy-parallel", "flexbuffers", "futures 0.3.7", @@ -425,7 +519,6 @@ dependencies = [ "futures-test", "futures-util", "genawaiter", - "glob", "lazy_static", "libc", "lmdb-rkv", @@ -434,6 +527,7 @@ dependencies = [ "rsasl", "rust-argon2", "serde", + "serde_dhall", "signal-hook", "slog", "slog-async", @@ -443,6 +537,24 @@ dependencies = [ "uuid", ] +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array 0.12.3", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array 0.14.4", +] + [[package]] name = "dirs" version = "2.0.2" @@ -470,12 +582,24 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "easy-parallel" version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dd4afd79212583ff429b913ad6605242ed7eec277e950b1438f300748f948f4" +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "env_logger" version = "0.7.1" @@ -495,6 +619,12 @@ version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + [[package]] name = "fastrand" version = "1.4.0" @@ -517,6 +647,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "form_urlencoded" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" +dependencies = [ + "matches", + "percent-encoding", +] + [[package]] name = "futures" version = "0.1.30" @@ -773,6 +913,25 @@ dependencies = [ "syn", ] +[[package]] +name = "generic-array" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "getrandom" version = "0.1.15" @@ -799,6 +958,18 @@ dependencies = [ "bindgen", ] +[[package]] +name = "half" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" + +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + [[package]] name = "hermit-abi" version = "0.1.17" @@ -808,6 +979,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" + [[package]] name = "humantime" version = "1.3.0" @@ -817,6 +994,27 @@ dependencies = [ "quick-error", ] +[[package]] +name = "idna" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "instant" version = "0.1.8" @@ -826,6 +1024,15 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -899,6 +1106,18 @@ dependencies = [ "cfg-if 0.1.10", ] +[[package]] +name = "maplit" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" + +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" + [[package]] name = "maybe-uninit" version = "2.0.0" @@ -989,6 +1208,18 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "paho-mqtt" version = "0.8.0" @@ -1023,6 +1254,79 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + +[[package]] +name = "pest_consume" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f06d200abe3be440ee3be3dcd2a65518250c0181364a332fa334b35152cb82e" +dependencies = [ + "pest", + "pest_consume_macros", + "pest_derive", + "proc-macro-hack", +] + +[[package]] +name = "pest_consume_macros" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "466dea9184791ec0b5304cc103dcbd3f267b0157aa60b2efc74ea1b1c886ea51" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_derive" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +dependencies = [ + "pest", + "pest_generator", +] + +[[package]] +name = "pest_generator" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +dependencies = [ + "pest", + "pest_meta", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pest_meta" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +dependencies = [ + "maplit", + "pest", + "sha-1", +] + [[package]] name = "pin-project" version = "1.0.1" @@ -1080,6 +1384,15 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" +[[package]] +name = "pretty" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60c0d9f6fc88ecdd245d90c1920ff76a430ab34303fc778d33b1d0a4c3bf6d3" +dependencies = [ + "typed-arena", +] + [[package]] name = "proc-macro-crate" version = "0.1.5" @@ -1270,6 +1583,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_cbor" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622" +dependencies = [ + "half", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.117" @@ -1281,6 +1604,44 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_dhall" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f80d945a711c648e559c4d39832379f36a303d393fca4719080de51701266f38" +dependencies = [ + "dhall", + "dhall_proc_macros", + "doc-comment", + "serde", + "url", +] + +[[package]] +name = "sha-1" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +dependencies = [ + "block-buffer 0.7.3", + "digest 0.8.1", + "fake-simd", + "opaque-debug 0.2.3", +] + +[[package]] +name = "sha2" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e7aab86fe2149bad8c507606bdb3f4ef5e7b2380eb92350f56122cca72a42a8" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpuid-bool", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + [[package]] name = "shlex" version = "0.1.1" @@ -1469,6 +1830,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "tinyvec" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + [[package]] name = "toml" version = "0.5.7" @@ -1478,6 +1854,42 @@ dependencies = [ "serde", ] +[[package]] +name = "typed-arena" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9b2228007eba4120145f785df0f6c92ea538f5a3635a612ecf4e334c8c1446d" + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + +[[package]] +name = "unicode-bidi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +dependencies = [ + "matches", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.8" @@ -1490,6 +1902,18 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +[[package]] +name = "url" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", +] + [[package]] name = "uuid" version = "0.8.1" diff --git a/Cargo.toml b/Cargo.toml index 964cbf3..47274d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,11 +31,10 @@ capnp-rpc = "0.13" capnp-futures = "0.13" serde = { version = "1.0", features = ["derive"] } +toml = "0.5" flexbuffers = "0.1" -glob = "0.3" -toml = "0.5" -config = { version = "0.10", default-features = false, features = ["toml"] } +serde_dhall = { version = "0.9", default-features = false } uuid = { version = "0.8", features = ["serde", "v4"] } diff --git a/src/config.rs b/src/config.rs index d1e5b07..6a5ce8b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,37 +1,36 @@ +use std::default::Default; use std::str::FromStr; use std::path::{Path, PathBuf}; -use serde::{Serialize, Deserialize}; use std::io::Read; -use std::fs::File; - -use crate::error::Result; - -use std::default::Default; - +use std::fs; use std::collections::HashMap; -use config::Config; -pub use config::ConfigError; -use glob::glob; +use serde::{Serialize, Deserialize}; -pub fn read(path: &Path) -> Result { - let mut settings = Config::default(); - settings - .merge(config::File::from(path)).unwrap(); +use crate::error::Result; +use crate::machine::MachineDescription; +use crate::db::machine::MachineIdentifier; - Ok(settings.try_into()?) +pub fn read(path: &Path) -> Result { + serde_dhall::from_file(path).parse().map_err(Into::into) } +#[deprecated] +pub type Settings = Config; + #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Settings { - pub machines: PathBuf, +pub struct Config { + /// A list of address/port pairs to listen on. + // TODO: This should really be a variant type; that is something that can figure out itself if + // it contains enough information to open a socket (i.e. it checks if it's a valid path (=> + // Unix socket) or IPv4/v6 address) pub listens: Box<[Listen]>, - pub shelly: Option, -} -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ShellyCfg { - pub mqtt_url: String + /// Machine descriptions to load + pub machines: HashMap, + + /// Modules to load and their configuration options + pub modules: HashMap>, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -42,19 +41,11 @@ pub struct Listen { impl Default for Settings { fn default() -> Self { - Settings { - listens: Box::new([Listen { - address: "127.0.0.1".to_string(), - port: Some(DEFAULT_PORT) - }, - Listen { - address: "::1".to_string(), - port: Some(DEFAULT_PORT) - }]), - shelly: Some(ShellyCfg { - mqtt_url: "127.0.0.1:1883".to_string() - }), - machines: PathBuf::from("/etc/bffh/machines/") + let modules: HashMap::> = HashMap::new(); + Config { + listens: Box::new([]), + machines: HashMap::new(), + modules: modules, } } } diff --git a/src/db.rs b/src/db.rs index 9391c6b..dfcee80 100644 --- a/src/db.rs +++ b/src/db.rs @@ -48,10 +48,6 @@ impl Databases { let env = Arc::new(env); let mdb = machine::init(log.new(o!("system" => "machines")), &config, env.clone())?; - // Error out if any of the subsystems failed to start. - let defs = crate::machine::MachineDescription::load_file(&config.machines)?; - - let mut ac = access::AccessControl::new(); let permdb = access::init(log.new(o!("system" => "permissions")), &config, env.clone())?; diff --git a/src/db/machine.rs b/src/db/machine.rs index 8813978..a243408 100644 --- a/src/db/machine.rs +++ b/src/db/machine.rs @@ -105,7 +105,6 @@ impl MachineState { } pub fn init(log: Logger, config: &Settings, env: Arc) -> Result { - let mut machine_descriptions = MachineDescription::load_file(&config.machines)?; let mut flags = lmdb::DatabaseFlags::empty(); flags.set(lmdb::DatabaseFlags::INTEGER_KEY, true); let machdb = env.create_db(Some("machines"), flags)?; diff --git a/src/error.rs b/src/error.rs index 03f57e0..801b435 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,6 +1,7 @@ use std::io; use std::fmt; use toml; +use serde_dhall; use rsasl::SaslError; @@ -15,6 +16,7 @@ use crate::network; pub enum Error { TomlDe(toml::de::Error), TomlSer(toml::ser::Error), + Dhall(serde_dhall::Error), SASL(SaslError), IO(io::Error), Boxed(Box), @@ -24,7 +26,6 @@ pub enum Error { FlexbuffersSer(flexbuffers::SerializationError), FuturesSpawn(futures_task::SpawnError), MQTT(mqtt::Error), - Config(config::ConfigError), BadVersion((u32,u32)), Argon2(argon2::Error), EventNetwork(network::Error), @@ -40,6 +41,9 @@ impl fmt::Display for Error { Error::TomlSer(e) => { write!(f, "TOML Serialization error: {}", e) }, + Error::Dhall(e) => { + write!(f, "Dhall coding error: {}", e) + }, Error::SASL(e) => { write!(f, "SASL Error: {}", e) }, @@ -67,9 +71,6 @@ impl fmt::Display for Error { Error::MQTT(e) => { write!(f, "Paho MQTT encountered an error: {}", e) }, - Error::Config(e) => { - write!(f, "Failed to parse config: {}", e) - } Error::Argon2(e) => { write!(f, "Argon2 en/decoding failure: {}", e) } @@ -110,6 +111,12 @@ impl From for Error { } } +impl From for Error { + fn from(e: serde_dhall::Error) -> Error { + Error::Dhall(e) + } +} + impl From> for Error { fn from(e: Box) -> Error { Error::Boxed(e) @@ -152,12 +159,6 @@ impl From for Error { } } -impl From for Error { - fn from(e: config::ConfigError) -> Error { - Error::Config(e) - } -} - impl From for Error { fn from(e: network::Error) -> Error { Error::EventNetwork(e) diff --git a/src/machine.rs b/src/machine.rs index 62ee38a..c21c2d1 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -235,7 +235,7 @@ impl MachineDescription { } pub fn load(config: &crate::config::Settings) -> Result { - let mut map = MachineDescription::load_file(&config.machines)?; + let mut map = config.machines.clone(); let it = map.drain() .map(|(k,v)| {