From d5833f30c43fd75fddaf54d29c7ec1608afe4138 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Sun, 13 Mar 2022 20:14:50 +0100 Subject: [PATCH] Adding `machines` back to config --- bffhd/config.rs | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/bffhd/config.rs b/bffhd/config.rs index bfcf4a5..b161700 100644 --- a/bffhd/config.rs +++ b/bffhd/config.rs @@ -8,7 +8,7 @@ use std::fmt::Formatter; use std::net::{SocketAddr, IpAddr, ToSocketAddrs}; use std::str::FromStr; use serde::de::Error; -use crate::authorization::permissions::PermRule; +use crate::authorization::permissions::{PermRule, PrivilegesBuf}; use crate::authorization::roles::RoleIdentifier; type Result = std::result::Result; @@ -19,13 +19,38 @@ pub fn read(path: &Path) -> Result { .map_err(Into::into) } +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] +/// A description of a machine +/// +/// This is the struct that a machine is serialized to/from. +/// Combining this with the actual state of the system will return a machine +pub struct MachineDescription { + /// The name of the machine. Doesn't need to be unique but is what humans will be presented. + pub name: String, + + /// An optional description of the Machine. + #[serde(default, skip_serializing_if = "Option::is_none", deserialize_with = "deser_option")] + pub description: Option, + + #[serde(default, skip_serializing_if = "Option::is_none", deserialize_with = "deser_option")] + pub wiki: Option, + + #[serde(default, skip_serializing_if = "Option::is_none", deserialize_with = "deser_option")] + pub category: Option, + + /// The permission required + #[serde(flatten)] + pub privs: PrivilegesBuf, +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { /// A list of address/port pairs to listen on. pub listens: Vec, /// Machine descriptions to load - //pub machines: HashMap, + pub machines: HashMap, /// Actors to load and their configuration options pub actors: HashMap, @@ -136,6 +161,7 @@ impl Default for Config { fn default() -> Self { let mut actors: HashMap:: = HashMap::new(); let mut initiators: HashMap:: = HashMap::new(); + let mut machines = HashMap::new(); actors.insert("Actor".to_string(), ModuleConfig { module: "Shelly".to_string(), @@ -155,6 +181,7 @@ impl Default for Config { ], actors, initiators, + machines, mqtt_url: "tcp://localhost:1883".to_string(), actor_connections: vec![ ("Testmachine".to_string(), "Actor".to_string()),