feat: Inventory PhysicalHost persistence with sqlx and local sqlite db #125
							
								
								
									
										8
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -1671,6 +1671,7 @@ dependencies = [ | |||||||
|  "env_logger", |  "env_logger", | ||||||
|  "harmony", |  "harmony", | ||||||
|  "harmony_cli", |  "harmony_cli", | ||||||
|  |  "harmony_types", | ||||||
|  "logging", |  "logging", | ||||||
|  "tokio", |  "tokio", | ||||||
|  "url", |  "url", | ||||||
| @ -1732,6 +1733,7 @@ dependencies = [ | |||||||
|  "harmony", |  "harmony", | ||||||
|  "harmony_cli", |  "harmony_cli", | ||||||
|  "harmony_macros", |  "harmony_macros", | ||||||
|  |  "harmony_types", | ||||||
|  "tokio", |  "tokio", | ||||||
|  "url", |  "url", | ||||||
| ] | ] | ||||||
| @ -1743,6 +1745,7 @@ dependencies = [ | |||||||
|  "cidr", |  "cidr", | ||||||
|  "harmony", |  "harmony", | ||||||
|  "harmony_cli", |  "harmony_cli", | ||||||
|  |  "harmony_types", | ||||||
|  "tokio", |  "tokio", | ||||||
|  "url", |  "url", | ||||||
| ] | ] | ||||||
| @ -2293,7 +2296,6 @@ dependencies = [ | |||||||
|  "opnsense-config", |  "opnsense-config", | ||||||
|  "opnsense-config-xml", |  "opnsense-config-xml", | ||||||
|  "pretty_assertions", |  "pretty_assertions", | ||||||
|  "rand 0.9.1", |  | ||||||
|  "reqwest 0.11.27", |  "reqwest 0.11.27", | ||||||
|  "russh", |  "russh", | ||||||
|  "rust-ipmi", |  "rust-ipmi", | ||||||
| @ -2437,7 +2439,9 @@ dependencies = [ | |||||||
| name = "harmony_types" | name = "harmony_types" | ||||||
| version = "0.1.0" | version = "0.1.0" | ||||||
| dependencies = [ | dependencies = [ | ||||||
|  |  "rand 0.9.1", | ||||||
|  "serde", |  "serde", | ||||||
|  |  "url", | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| [[package]] | [[package]] | ||||||
| @ -3849,7 +3853,7 @@ dependencies = [ | |||||||
|  "env_logger", |  "env_logger", | ||||||
|  "log", |  "log", | ||||||
|  "pretty_assertions", |  "pretty_assertions", | ||||||
|  "rand 0.8.5", |  "rand 0.9.1", | ||||||
|  "serde", |  "serde", | ||||||
|  "thiserror 2.0.14", |  "thiserror 2.0.14", | ||||||
|  "tokio", |  "tokio", | ||||||
|  | |||||||
| @ -36,7 +36,7 @@ tokio = { version = "1.40", features = [ | |||||||
| cidr = { features = ["serde"], version = "0.2" } | cidr = { features = ["serde"], version = "0.2" } | ||||||
| russh = "0.45" | russh = "0.45" | ||||||
| russh-keys = "0.45" | russh-keys = "0.45" | ||||||
| rand = "0.8" | rand = "0.9" | ||||||
| url = "2.5" | url = "2.5" | ||||||
| kube = { version = "1.1.0", features = [ | kube = { version = "1.1.0", features = [ | ||||||
|   "config", |   "config", | ||||||
| @ -67,3 +67,4 @@ serde = { version = "1.0.209", features = ["derive", "rc"] } | |||||||
| serde_json = "1.0.127" | serde_json = "1.0.127" | ||||||
| askama = "0.14" | askama = "0.14" | ||||||
| sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite" ] } | sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite" ] } | ||||||
|  | reqwest = { version = "0.12", features = ["stream", "rustls-tls", "http2"], default-features = false } | ||||||
|  | |||||||
| @ -7,8 +7,9 @@ license.workspace = true | |||||||
| 
 | 
 | ||||||
| [dependencies] | [dependencies] | ||||||
| env_logger.workspace = true | env_logger.workspace = true | ||||||
| harmony = { version = "0.1.0", path = "../../harmony" } | harmony = { path = "../../harmony" } | ||||||
| harmony_cli = { version = "0.1.0", path = "../../harmony_cli" } | harmony_cli = { path = "../../harmony_cli" } | ||||||
|  | harmony_types = { path = "../../harmony_types" } | ||||||
| logging = "0.1.0" | logging = "0.1.0" | ||||||
| tokio.workspace = true | tokio.workspace = true | ||||||
| url.workspace = true | url.workspace = true | ||||||
|  | |||||||
| @ -1,15 +1,16 @@ | |||||||
| use std::{path::PathBuf, str::FromStr, sync::Arc}; | use std::{path::PathBuf, str::FromStr, sync::Arc}; | ||||||
| 
 | 
 | ||||||
| use harmony::{ | use harmony::{ | ||||||
|     data::Id, |  | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     modules::{ |     modules::{ | ||||||
|         application::{ApplicationScore, RustWebFramework, RustWebapp, features::Monitoring}, |         application::{ApplicationScore, RustWebFramework, RustWebapp, features::Monitoring}, | ||||||
|         monitoring::alert_channel::webhook_receiver::WebhookReceiver, |         monitoring::alert_channel::webhook_receiver::WebhookReceiver, | ||||||
|         tenant::TenantScore, |         tenant::TenantScore, | ||||||
|     }, |     }, | ||||||
|     topology::{K8sAnywhereTopology, Url, tenant::TenantConfig}, |     topology::{K8sAnywhereTopology, tenant::TenantConfig}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
| async fn main() { | async fn main() { | ||||||
|  | |||||||
| @ -2,8 +2,9 @@ use harmony::{ | |||||||
|     data::Version, |     data::Version, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     modules::lamp::{LAMPConfig, LAMPScore}, |     modules::lamp::{LAMPConfig, LAMPScore}, | ||||||
|     topology::{K8sAnywhereTopology, Url}, |     topology::K8sAnywhereTopology, | ||||||
| }; | }; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
| async fn main() { | async fn main() { | ||||||
|  | |||||||
| @ -6,8 +6,9 @@ readme.workspace = true | |||||||
| license.workspace = true | license.workspace = true | ||||||
| 
 | 
 | ||||||
| [dependencies] | [dependencies] | ||||||
| harmony = { version = "0.1.0", path = "../../harmony" } | harmony = { path = "../../harmony" } | ||||||
| harmony_cli = { version = "0.1.0", path = "../../harmony_cli" } | harmony_cli = { path = "../../harmony_cli" } | ||||||
| harmony_macros = { version = "0.1.0", path = "../../harmony_macros" } | harmony_macros = { path = "../../harmony_macros" } | ||||||
|  | harmony_types = { path = "../../harmony_types" } | ||||||
| tokio.workspace = true | tokio.workspace = true | ||||||
| url.workspace = true | url.workspace = true | ||||||
|  | |||||||
| @ -22,8 +22,9 @@ use harmony::{ | |||||||
|             k8s::pvc::high_pvc_fill_rate_over_two_days, |             k8s::pvc::high_pvc_fill_rate_over_two_days, | ||||||
|         }, |         }, | ||||||
|     }, |     }, | ||||||
|     topology::{K8sAnywhereTopology, Url}, |     topology::K8sAnywhereTopology, | ||||||
| }; | }; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
| async fn main() { | async fn main() { | ||||||
|  | |||||||
| @ -7,7 +7,8 @@ license.workspace = true | |||||||
| 
 | 
 | ||||||
| [dependencies] | [dependencies] | ||||||
| cidr.workspace = true | cidr.workspace = true | ||||||
| harmony = { version = "0.1.0", path = "../../harmony" } | harmony = { path = "../../harmony" } | ||||||
| harmony_cli = { version = "0.1.0", path = "../../harmony_cli" } | harmony_cli = { path = "../../harmony_cli" } | ||||||
|  | harmony_types = { path = "../../harmony_types" } | ||||||
| tokio.workspace = true | tokio.workspace = true | ||||||
| url.workspace = true | url.workspace = true | ||||||
|  | |||||||
| @ -1,7 +1,6 @@ | |||||||
| use std::{collections::HashMap, str::FromStr}; | use std::{collections::HashMap, str::FromStr}; | ||||||
| 
 | 
 | ||||||
| use harmony::{ | use harmony::{ | ||||||
|     data::Id, |  | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     modules::{ |     modules::{ | ||||||
|         monitoring::{ |         monitoring::{ | ||||||
| @ -19,10 +18,12 @@ use harmony::{ | |||||||
|         tenant::TenantScore, |         tenant::TenantScore, | ||||||
|     }, |     }, | ||||||
|     topology::{ |     topology::{ | ||||||
|         K8sAnywhereTopology, Url, |         K8sAnywhereTopology, | ||||||
|         tenant::{ResourceLimits, TenantConfig, TenantNetworkPolicy}, |         tenant::{ResourceLimits, TenantConfig, TenantNetworkPolicy}, | ||||||
|     }, |     }, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
| async fn main() { | async fn main() { | ||||||
|  | |||||||
| @ -18,9 +18,10 @@ use harmony::{ | |||||||
|         }, |         }, | ||||||
|         tftp::TftpScore, |         tftp::TftpScore, | ||||||
|     }, |     }, | ||||||
|     topology::{LogicalHost, UnmanagedRouter, Url}, |     topology::{LogicalHost, UnmanagedRouter}, | ||||||
| }; | }; | ||||||
| use harmony_macros::{ip, mac_address}; | use harmony_macros::{ip, mac_address}; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
| async fn main() { | async fn main() { | ||||||
|  | |||||||
| @ -15,9 +15,10 @@ use harmony::{ | |||||||
|         opnsense::OPNsenseShellCommandScore, |         opnsense::OPNsenseShellCommandScore, | ||||||
|         tftp::TftpScore, |         tftp::TftpScore, | ||||||
|     }, |     }, | ||||||
|     topology::{LogicalHost, UnmanagedRouter, Url}, |     topology::{LogicalHost, UnmanagedRouter}, | ||||||
| }; | }; | ||||||
| use harmony_macros::{ip, mac_address}; | use harmony_macros::{ip, mac_address}; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
| async fn main() { | async fn main() { | ||||||
|  | |||||||
| @ -11,8 +11,9 @@ use harmony::{ | |||||||
|             discord_alert_channel::DiscordWebhook, webhook_receiver::WebhookReceiver, |             discord_alert_channel::DiscordWebhook, webhook_receiver::WebhookReceiver, | ||||||
|         }, |         }, | ||||||
|     }, |     }, | ||||||
|     topology::{K8sAnywhereTopology, Url}, |     topology::K8sAnywhereTopology, | ||||||
| }; | }; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
| async fn main() { | async fn main() { | ||||||
|  | |||||||
| @ -1,11 +1,11 @@ | |||||||
| use std::str::FromStr; | use std::str::FromStr; | ||||||
| 
 | 
 | ||||||
| use harmony::{ | use harmony::{ | ||||||
|     data::Id, |  | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     modules::tenant::TenantScore, |     modules::tenant::TenantScore, | ||||||
|     topology::{K8sAnywhereTopology, tenant::TenantConfig}, |     topology::{K8sAnywhereTopology, tenant::TenantConfig}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[tokio::main] | #[tokio::main] | ||||||
| async fn main() { | async fn main() { | ||||||
|  | |||||||
| @ -9,7 +9,6 @@ license.workspace = true | |||||||
| testing = [] | testing = [] | ||||||
| 
 | 
 | ||||||
| [dependencies] | [dependencies] | ||||||
| rand = "0.9" |  | ||||||
| hex = "0.4" | hex = "0.4" | ||||||
| reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"], default-features = false } | reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"], default-features = false } | ||||||
| russh = "0.45.0" | russh = "0.45.0" | ||||||
|  | |||||||
| @ -1,6 +1,4 @@ | |||||||
| mod file; | mod file; | ||||||
| mod id; |  | ||||||
| mod version; | mod version; | ||||||
| pub use file::*; | pub use file::*; | ||||||
| pub use id::*; |  | ||||||
| pub use version::*; | pub use version::*; | ||||||
|  | |||||||
| @ -1,8 +1,7 @@ | |||||||
| use std::fmt; | use std::fmt; | ||||||
| 
 | 
 | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| 
 | use harmony_types::net::IpAddress; | ||||||
| use super::topology::IpAddress; |  | ||||||
| 
 | 
 | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| pub enum ExecutorError { | pub enum ExecutorError { | ||||||
|  | |||||||
| @ -199,7 +199,7 @@ pub struct NetworkInterface { | |||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
| use harmony_macros::mac_address; | use harmony_macros::mac_address; | ||||||
| 
 | 
 | ||||||
| use crate::data::Id; | use harmony_types::id::Id; | ||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
| impl NetworkInterface { | impl NetworkInterface { | ||||||
|     pub fn dummy() -> Self { |     pub fn dummy() -> Self { | ||||||
|  | |||||||
| @ -1,13 +1,11 @@ | |||||||
|  | use harmony_types::id::Id; | ||||||
| use std::error::Error; | use std::error::Error; | ||||||
| 
 | 
 | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use derive_new::new; | use derive_new::new; | ||||||
| 
 | 
 | ||||||
| use super::{ | use super::{ | ||||||
|     data::{Id, Version}, |     data::Version, executors::ExecutorError, inventory::Inventory, topology::PreparationError, | ||||||
|     executors::ExecutorError, |  | ||||||
|     inventory::Inventory, |  | ||||||
|     topology::PreparationError, |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| pub enum InterpretName { | pub enum InterpretName { | ||||||
|  | |||||||
| @ -1,3 +1,4 @@ | |||||||
|  | use harmony_types::id::Id; | ||||||
| use std::collections::BTreeMap; | use std::collections::BTreeMap; | ||||||
| 
 | 
 | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| @ -5,7 +6,6 @@ use serde::Serialize; | |||||||
| use serde_value::Value; | use serde_value::Value; | ||||||
| 
 | 
 | ||||||
| use super::{ | use super::{ | ||||||
|     data::Id, |  | ||||||
|     instrumentation::{self, HarmonyEvent}, |     instrumentation::{self, HarmonyEvent}, | ||||||
|     interpret::{Interpret, InterpretError, Outcome}, |     interpret::{Interpret, InterpretError, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use harmony_macros::ip; | use harmony_macros::ip; | ||||||
| use harmony_types::net::MacAddress; | use harmony_types::net::MacAddress; | ||||||
|  | use harmony_types::net::Url; | ||||||
| use log::debug; | use log::debug; | ||||||
| use log::info; | use log::info; | ||||||
| 
 | 
 | ||||||
| @ -26,7 +27,6 @@ use super::Router; | |||||||
| use super::TftpServer; | use super::TftpServer; | ||||||
| 
 | 
 | ||||||
| use super::Topology; | use super::Topology; | ||||||
| use super::Url; |  | ||||||
| use super::k8s::K8sClient; | use super::k8s::K8sClient; | ||||||
| use std::sync::Arc; | use std::sync::Arc; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,8 +1,8 @@ | |||||||
| use crate::{data::FileContent, executors::ExecutorError}; | use crate::{data::FileContent, executors::ExecutorError}; | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| 
 | 
 | ||||||
| use super::{IpAddress, Url}; | use harmony_types::net::IpAddress; | ||||||
| 
 | use harmony_types::net::Url; | ||||||
| #[async_trait] | #[async_trait] | ||||||
| pub trait HttpServer: Send + Sync { | pub trait HttpServer: Send + Sync { | ||||||
|     async fn serve_files(&self, url: &Url) -> Result<(), ExecutorError>; |     async fn serve_files(&self, url: &Url) -> Result<(), ExecutorError>; | ||||||
|  | |||||||
| @ -4,8 +4,9 @@ use async_trait::async_trait; | |||||||
| use log::debug; | use log::debug; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use super::{IpAddress, LogicalHost}; | use super::LogicalHost; | ||||||
| use crate::executors::ExecutorError; | use crate::executors::ExecutorError; | ||||||
|  | use harmony_types::net::IpAddress; | ||||||
| 
 | 
 | ||||||
| impl std::fmt::Debug for dyn LoadBalancer { | impl std::fmt::Debug for dyn LoadBalancer { | ||||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
| mod ha_cluster; | mod ha_cluster; | ||||||
|  | use harmony_types::net::IpAddress; | ||||||
| mod host_binding; | mod host_binding; | ||||||
| mod http; | mod http; | ||||||
| pub mod installable; | pub mod installable; | ||||||
| @ -32,7 +33,6 @@ use super::{ | |||||||
|     instrumentation::{self, HarmonyEvent}, |     instrumentation::{self, HarmonyEvent}, | ||||||
| }; | }; | ||||||
| use std::error::Error; | use std::error::Error; | ||||||
| use std::net::IpAddr; |  | ||||||
| 
 | 
 | ||||||
| /// Represents a logical view of an infrastructure environment providing specific capabilities.
 | /// Represents a logical view of an infrastructure environment providing specific capabilities.
 | ||||||
| ///
 | ///
 | ||||||
| @ -196,35 +196,6 @@ pub trait MultiTargetTopology: Topology { | |||||||
|     fn current_target(&self) -> DeploymentTarget; |     fn current_target(&self) -> DeploymentTarget; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub type IpAddress = IpAddr; |  | ||||||
| 
 |  | ||||||
| #[derive(Debug, Clone)] |  | ||||||
| pub enum Url { |  | ||||||
|     LocalFolder(String), |  | ||||||
|     Url(url::Url), |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl Serialize for Url { |  | ||||||
|     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |  | ||||||
|     where |  | ||||||
|         S: serde::Serializer, |  | ||||||
|     { |  | ||||||
|         match self { |  | ||||||
|             Url::LocalFolder(path) => serializer.serialize_str(path), |  | ||||||
|             Url::Url(url) => serializer.serialize_str(url.as_str()), |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl std::fmt::Display for Url { |  | ||||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |  | ||||||
|         match self { |  | ||||||
|             Url::LocalFolder(path) => write!(f, "{}", path), |  | ||||||
|             Url::Url(url) => write!(f, "{}", url), |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /// Represents a logical member of a cluster that provides one or more services.
 | /// Represents a logical member of a cluster that provides one or more services.
 | ||||||
| ///
 | ///
 | ||||||
| /// A LogicalHost can represent various roles within the infrastructure, such as:
 | /// A LogicalHost can represent various roles within the infrastructure, such as:
 | ||||||
| @ -263,7 +234,8 @@ impl LogicalHost { | |||||||
|     ///
 |     ///
 | ||||||
|     /// ```
 |     /// ```
 | ||||||
|     /// use std::str::FromStr;
 |     /// use std::str::FromStr;
 | ||||||
|     /// use harmony::topology::{IpAddress, LogicalHost};
 |     /// use harmony::topology::{LogicalHost};
 | ||||||
|  |     /// use harmony_types::net::IpAddress;
 | ||||||
|     ///
 |     ///
 | ||||||
|     /// let start_ip = IpAddress::from_str("192.168.0.20").unwrap();
 |     /// let start_ip = IpAddress::from_str("192.168.0.20").unwrap();
 | ||||||
|     /// let hosts = LogicalHost::create_hosts(3, start_ip, "worker");
 |     /// let hosts = LogicalHost::create_hosts(3, start_ip, "worker");
 | ||||||
| @ -319,7 +291,7 @@ fn increment_ip(ip: IpAddress, increment: u32) -> Option<IpAddress> { | |||||||
| 
 | 
 | ||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
| mod tests { | mod tests { | ||||||
|     use super::*; |     use harmony_types::net::Url; | ||||||
|     use serde_json; |     use serde_json; | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|  | |||||||
| @ -1,12 +1,12 @@ | |||||||
| use std::{net::Ipv4Addr, str::FromStr, sync::Arc}; | use std::{net::Ipv4Addr, str::FromStr, sync::Arc}; | ||||||
| 
 | 
 | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use harmony_types::net::MacAddress; | use harmony_types::net::{IpAddress, MacAddress}; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use crate::executors::ExecutorError; | use crate::executors::ExecutorError; | ||||||
| 
 | 
 | ||||||
| use super::{IpAddress, LogicalHost, k8s::K8sClient}; | use super::{LogicalHost, k8s::K8sClient}; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| pub struct DHCPStaticEntry { | pub struct DHCPStaticEntry { | ||||||
|  | |||||||
| @ -4,11 +4,12 @@ use async_trait::async_trait; | |||||||
| use log::debug; | use log::debug; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     topology::{Topology, installable::Installable}, |     topology::{Topology, installable::Installable}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[async_trait] | #[async_trait] | ||||||
| pub trait AlertSender: Send + Sync + std::fmt::Debug { | pub trait AlertSender: Send + Sync + std::fmt::Debug { | ||||||
|  | |||||||
| @ -2,7 +2,7 @@ pub mod k8s; | |||||||
| mod manager; | mod manager; | ||||||
| pub mod network_policy; | pub mod network_policy; | ||||||
| 
 | 
 | ||||||
| use crate::data::Id; | use harmony_types::id::Id; | ||||||
| pub use manager::*; | pub use manager::*; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| use std::str::FromStr; | use std::str::FromStr; | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| use crate::executors::ExecutorError; | use crate::executors::ExecutorError; | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| 
 | 
 | ||||||
| use super::{IpAddress, Url}; | use harmony_types::net::{IpAddress, Url}; | ||||||
| 
 | 
 | ||||||
| #[async_trait] | #[async_trait] | ||||||
| pub trait TftpServer: Send + Sync { | pub trait TftpServer: Send + Sync { | ||||||
|  | |||||||
| @ -3,11 +3,9 @@ use std::sync::Arc; | |||||||
| 
 | 
 | ||||||
| use russh::{client, keys::key}; | use russh::{client, keys::key}; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::domain::executors::{ExecutorError, SshClient}; | ||||||
|     domain::executors::{ExecutorError, SshClient}, |  | ||||||
|     topology::IpAddress, |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
|  | use harmony_types::net::IpAddress; | ||||||
| pub struct RusshClient; | pub struct RusshClient; | ||||||
| 
 | 
 | ||||||
| #[async_trait] | #[async_trait] | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| use crate::hardware::ManagementInterface; | use crate::hardware::ManagementInterface; | ||||||
| use crate::topology::IpAddress; |  | ||||||
| use derive_new::new; | use derive_new::new; | ||||||
|  | use harmony_types::net::IpAddress; | ||||||
| use harmony_types::net::MacAddress; | use harmony_types::net::MacAddress; | ||||||
| use log::info; | use log::info; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
| use crate::{ | use crate::{ | ||||||
|     data::Id, |  | ||||||
|     hardware::PhysicalHost, |     hardware::PhysicalHost, | ||||||
|     inventory::{InventoryRepository, RepoError}, |     inventory::{InventoryRepository, RepoError}, | ||||||
| }; | }; | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use log::{info, warn}; | use harmony_types::id::Id; | ||||||
|  | use log::info; | ||||||
| use sqlx::{Pool, Sqlite, SqlitePool}; | use sqlx::{Pool, Sqlite, SqlitePool}; | ||||||
| 
 | 
 | ||||||
| /// A thread-safe, connection-pooled repository using SQLite.
 | /// A thread-safe, connection-pooled repository using SQLite.
 | ||||||
|  | |||||||
| @ -4,10 +4,11 @@ use log::info; | |||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     executors::ExecutorError, |     executors::ExecutorError, | ||||||
|     topology::{DHCPStaticEntry, DhcpServer, IpAddress, LogicalHost, PxeOptions}, |     topology::{DHCPStaticEntry, DhcpServer, LogicalHost, PxeOptions}, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| use super::OPNSenseFirewall; | use super::OPNSenseFirewall; | ||||||
|  | use harmony_types::net::IpAddress; | ||||||
| 
 | 
 | ||||||
| #[async_trait] | #[async_trait] | ||||||
| impl DhcpServer for OPNSenseFirewall { | impl DhcpServer for OPNSenseFirewall { | ||||||
|  | |||||||
| @ -1,11 +1,11 @@ | |||||||
| use crate::infra::opnsense::Host; | use crate::infra::opnsense::Host; | ||||||
| use crate::infra::opnsense::IpAddress; |  | ||||||
| use crate::infra::opnsense::LogicalHost; | use crate::infra::opnsense::LogicalHost; | ||||||
| use crate::{ | use crate::{ | ||||||
|     executors::ExecutorError, |     executors::ExecutorError, | ||||||
|     topology::{DnsRecord, DnsServer}, |     topology::{DnsRecord, DnsServer}, | ||||||
| }; | }; | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
|  | use harmony_types::net::IpAddress; | ||||||
| 
 | 
 | ||||||
| use super::OPNSenseFirewall; | use super::OPNSenseFirewall; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,9 +1,10 @@ | |||||||
| use crate::{ | use crate::{ | ||||||
|     executors::ExecutorError, |     executors::ExecutorError, | ||||||
|     topology::{Firewall, FirewallRule, IpAddress, LogicalHost}, |     topology::{Firewall, FirewallRule, LogicalHost}, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| use super::OPNSenseFirewall; | use super::OPNSenseFirewall; | ||||||
|  | use harmony_types::net::IpAddress; | ||||||
| 
 | 
 | ||||||
| impl Firewall for OPNSenseFirewall { | impl Firewall for OPNSenseFirewall { | ||||||
|     fn add_rule(&mut self, _rule: FirewallRule) -> Result<(), ExecutorError> { |     fn add_rule(&mut self, _rule: FirewallRule) -> Result<(), ExecutorError> { | ||||||
|  | |||||||
| @ -1,13 +1,11 @@ | |||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use log::info; | use log::info; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{data::FileContent, executors::ExecutorError, topology::HttpServer}; | ||||||
|     data::FileContent, |  | ||||||
|     executors::ExecutorError, |  | ||||||
|     topology::{HttpServer, IpAddress, Url}, |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| use super::OPNSenseFirewall; | use super::OPNSenseFirewall; | ||||||
|  | use harmony_types::net::IpAddress; | ||||||
|  | use harmony_types::net::Url; | ||||||
| const OPNSENSE_HTTP_ROOT_PATH: &str = "/usr/local/http"; | const OPNSENSE_HTTP_ROOT_PATH: &str = "/usr/local/http"; | ||||||
| 
 | 
 | ||||||
| #[async_trait] | #[async_trait] | ||||||
|  | |||||||
| @ -6,10 +6,11 @@ use uuid::Uuid; | |||||||
| use crate::{ | use crate::{ | ||||||
|     executors::ExecutorError, |     executors::ExecutorError, | ||||||
|     topology::{ |     topology::{ | ||||||
|         BackendServer, HealthCheck, HttpMethod, HttpStatusCode, IpAddress, LoadBalancer, |         BackendServer, HealthCheck, HttpMethod, HttpStatusCode, LoadBalancer, LoadBalancerService, | ||||||
|         LoadBalancerService, LogicalHost, |         LogicalHost, | ||||||
|     }, |     }, | ||||||
| }; | }; | ||||||
|  | use harmony_types::net::IpAddress; | ||||||
| 
 | 
 | ||||||
| use super::OPNSenseFirewall; | use super::OPNSenseFirewall; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -11,10 +11,8 @@ pub use management::*; | |||||||
| use opnsense_config_xml::Host; | use opnsense_config_xml::Host; | ||||||
| use tokio::sync::RwLock; | use tokio::sync::RwLock; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{executors::ExecutorError, topology::LogicalHost}; | ||||||
|     executors::ExecutorError, | use harmony_types::net::IpAddress; | ||||||
|     topology::{IpAddress, LogicalHost}, |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone)] | #[derive(Debug, Clone)] | ||||||
| pub struct OPNSenseFirewall { | pub struct OPNSenseFirewall { | ||||||
|  | |||||||
| @ -1,10 +1,9 @@ | |||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use log::info; | use log::info; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{executors::ExecutorError, topology::TftpServer}; | ||||||
|     executors::ExecutorError, | use harmony_types::net::IpAddress; | ||||||
|     topology::{IpAddress, TftpServer, Url}, | use harmony_types::net::Url; | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| use super::OPNSenseFirewall; | use super::OPNSenseFirewall; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -4,13 +4,14 @@ use serde::Serialize; | |||||||
| use std::str::FromStr; | use std::str::FromStr; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     modules::helm::chart::{HelmChartScore, HelmRepository}, |     modules::helm::chart::{HelmChartScore, HelmRepository}, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{HelmCommand, K8sclient, Topology}, |     topology::{HelmCommand, K8sclient, Topology}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| use super::ArgoApplication; | use super::ArgoApplication; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ use crate::{ | |||||||
|         alert_channel::webhook_receiver::WebhookReceiver, ntfy::ntfy::NtfyScore, |         alert_channel::webhook_receiver::WebhookReceiver, ntfy::ntfy::NtfyScore, | ||||||
|     }, |     }, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{HelmCommand, K8sclient, Topology, Url, tenant::TenantManager}, |     topology::{HelmCommand, K8sclient, Topology, tenant::TenantManager}, | ||||||
| }; | }; | ||||||
| use crate::{ | use crate::{ | ||||||
|     modules::prometheus::prometheus::PrometheusApplicationMonitoring, |     modules::prometheus::prometheus::PrometheusApplicationMonitoring, | ||||||
| @ -19,6 +19,7 @@ use crate::{ | |||||||
| }; | }; | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use base64::{Engine as _, engine::general_purpose}; | use base64::{Engine as _, engine::general_purpose}; | ||||||
|  | use harmony_types::net::Url; | ||||||
| use log::{debug, info}; | use log::{debug, info}; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone)] | #[derive(Debug, Clone)] | ||||||
|  | |||||||
| @ -13,12 +13,13 @@ use async_trait::async_trait; | |||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     instrumentation::{self, HarmonyEvent}, |     instrumentation::{self, HarmonyEvent}, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     topology::Topology, |     topology::Topology, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Clone, Debug)] | #[derive(Clone, Debug)] | ||||||
| pub enum ApplicationFeatureStatus { | pub enum ApplicationFeatureStatus { | ||||||
|  | |||||||
| @ -15,10 +15,8 @@ use serde::Serialize; | |||||||
| use tar::Archive; | use tar::Archive; | ||||||
| 
 | 
 | ||||||
| use crate::config::{REGISTRY_PROJECT, REGISTRY_URL}; | use crate::config::{REGISTRY_PROJECT, REGISTRY_URL}; | ||||||
| use crate::{ | use crate::{score::Score, topology::Topology}; | ||||||
|     score::Score, | use harmony_types::net::Url; | ||||||
|     topology::{Topology, Url}, |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| use super::{Application, ApplicationFeature, ApplicationInterpret, HelmPackage, OCICompliant}; | use super::{Application, ApplicationFeature, ApplicationInterpret, HelmPackage, OCICompliant}; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use derive_new::new; | use derive_new::new; | ||||||
|  | use harmony_types::id::Id; | ||||||
| use log::info; | use log::info; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| @ -7,10 +8,11 @@ use crate::{ | |||||||
|     domain::{data::Version, interpret::InterpretStatus}, |     domain::{data::Version, interpret::InterpretStatus}, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     topology::{DHCPStaticEntry, DhcpServer, HostBinding, IpAddress, PxeOptions, Topology}, |     topology::{DHCPStaticEntry, DhcpServer, HostBinding, PxeOptions, Topology}, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| use crate::domain::score::Score; | use crate::domain::score::Score; | ||||||
|  | use harmony_types::net::IpAddress; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, new, Clone, Serialize)] | #[derive(Debug, new, Clone, Serialize)] | ||||||
| pub struct DhcpScore { | pub struct DhcpScore { | ||||||
| @ -135,7 +137,7 @@ impl<T: DhcpServer> Interpret<T> for DhcpInterpret { | |||||||
|         self.status.clone() |         self.status.clone() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn get_children(&self) -> Vec<crate::domain::data::Id> { |     fn get_children(&self) -> Vec<Id> { | ||||||
|         todo!() |         todo!() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use derive_new::new; | use derive_new::new; | ||||||
|  | use harmony_types::id::Id; | ||||||
| use log::info; | use log::info; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| @ -91,7 +92,7 @@ impl<T: Topology + DnsServer> Interpret<T> for DnsInterpret { | |||||||
|         self.status.clone() |         self.status.clone() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn get_children(&self) -> Vec<crate::domain::data::Id> { |     fn get_children(&self) -> Vec<Id> { | ||||||
|         todo!() |         todo!() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,4 +1,5 @@ | |||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
|  | use harmony_types::id::Id; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
| @ -67,7 +68,7 @@ impl<T: Topology> Interpret<T> for DummyInterpret { | |||||||
|         self.status.clone() |         self.status.clone() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn get_children(&self) -> Vec<crate::domain::data::Id> { |     fn get_children(&self) -> Vec<Id> { | ||||||
|         todo!() |         todo!() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -113,7 +114,7 @@ impl<T: Topology> Interpret<T> for PanicInterpret { | |||||||
|         InterpretStatus::QUEUED |         InterpretStatus::QUEUED | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn get_children(&self) -> Vec<crate::domain::data::Id> { |     fn get_children(&self) -> Vec<Id> { | ||||||
|         todo!() |         todo!() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,9 +1,10 @@ | |||||||
| use crate::data::{Id, Version}; | use crate::data::Version; | ||||||
| use crate::interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}; | use crate::interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}; | ||||||
| use crate::inventory::Inventory; | use crate::inventory::Inventory; | ||||||
| use crate::score::Score; | use crate::score::Score; | ||||||
| use crate::topology::{HelmCommand, Topology}; | use crate::topology::{HelmCommand, Topology}; | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
|  | use harmony_types::id::Id; | ||||||
| use helm_wrapper_rs; | use helm_wrapper_rs; | ||||||
| use helm_wrapper_rs::blocking::{DefaultHelmExecutor, HelmExecutor}; | use helm_wrapper_rs::blocking::{DefaultHelmExecutor, HelmExecutor}; | ||||||
| use log::{debug, info, warn}; | use log::{debug, info, warn}; | ||||||
|  | |||||||
| @ -8,11 +8,12 @@ use std::process::{Command, Output}; | |||||||
| use temp_dir::{self, TempDir}; | use temp_dir::{self, TempDir}; | ||||||
| use temp_file::TempFile; | use temp_file::TempFile; | ||||||
| 
 | 
 | ||||||
| use crate::data::{Id, Version}; | use crate::data::Version; | ||||||
| use crate::interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}; | use crate::interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}; | ||||||
| use crate::inventory::Inventory; | use crate::inventory::Inventory; | ||||||
| use crate::score::Score; | use crate::score::Score; | ||||||
| use crate::topology::{HelmCommand, K8sclient, Topology}; | use crate::topology::{HelmCommand, K8sclient, Topology}; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Clone)] | #[derive(Clone)] | ||||||
| pub struct HelmCommandExecutor { | pub struct HelmCommandExecutor { | ||||||
|  | |||||||
| @ -3,12 +3,14 @@ use derive_new::new; | |||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{FileContent, Id, Version}, |     data::{FileContent, Version}, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{HttpServer, Topology, Url}, |     topology::{HttpServer, Topology}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| /// Configure an HTTP server that is provided by the Topology
 | /// Configure an HTTP server that is provided by the Topology
 | ||||||
| ///
 | ///
 | ||||||
|  | |||||||
| @ -4,12 +4,13 @@ use log::{debug, info}; | |||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::Topology, |     topology::Topology, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| /// This launches an harmony_inventory_agent discovery process
 | /// This launches an harmony_inventory_agent discovery process
 | ||||||
| /// This will allow us to register/update hosts running harmony_inventory_agent
 | /// This will allow us to register/update hosts running harmony_inventory_agent
 | ||||||
|  | |||||||
| @ -3,12 +3,13 @@ use derive_new::new; | |||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::Topology, |     topology::Topology, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, new, Clone, Serialize)] | #[derive(Debug, new, Clone, Serialize)] | ||||||
| pub struct IpxeScore { | pub struct IpxeScore { | ||||||
|  | |||||||
| @ -6,12 +6,13 @@ use serde::Serialize; | |||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     config::HARMONY_DATA_DIR, |     config::HARMONY_DATA_DIR, | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::Topology, |     topology::Topology, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Serialize)] | #[derive(Debug, Clone, Serialize)] | ||||||
| pub struct K3DInstallationScore { | pub struct K3DInstallationScore { | ||||||
|  | |||||||
| @ -5,12 +5,13 @@ use log::info; | |||||||
| use serde::{Serialize, de::DeserializeOwned}; | use serde::{Serialize, de::DeserializeOwned}; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{K8sclient, Topology}, |     topology::{K8sclient, Topology}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Serialize)] | #[derive(Debug, Clone, Serialize)] | ||||||
| pub struct K8sResourceScore<K: Resource + std::fmt::Debug> { | pub struct K8sResourceScore<K: Resource + std::fmt::Debug> { | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ use dockerfile_builder::instruction::{CMD, COPY, ENV, EXPOSE, FROM, RUN, WORKDIR | |||||||
| use dockerfile_builder::{Dockerfile, instruction_builder::EnvBuilder}; | use dockerfile_builder::{Dockerfile, instruction_builder::EnvBuilder}; | ||||||
| use fqdn::fqdn; | use fqdn::fqdn; | ||||||
| use harmony_macros::ingress_path; | use harmony_macros::ingress_path; | ||||||
|  | use harmony_types::net::Url; | ||||||
| use non_blank_string_rs::NonBlankString; | use non_blank_string_rs::NonBlankString; | ||||||
| use serde_json::json; | use serde_json::json; | ||||||
| use std::collections::HashMap; | use std::collections::HashMap; | ||||||
| @ -18,13 +19,14 @@ use crate::config::{REGISTRY_PROJECT, REGISTRY_URL}; | |||||||
| use crate::modules::k8s::ingress::K8sIngressScore; | use crate::modules::k8s::ingress::K8sIngressScore; | ||||||
| use crate::topology::HelmCommand; | use crate::topology::HelmCommand; | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     modules::k8s::deployment::K8sDeploymentScore, |     modules::k8s::deployment::K8sDeploymentScore, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{K8sclient, Topology, Url}, |     topology::{K8sclient, Topology}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| use super::helm::chart::HelmChartScore; | use super::helm::chart::HelmChartScore; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,12 +3,13 @@ use log::info; | |||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{LoadBalancer, LoadBalancerService, Topology}, |     topology::{LoadBalancer, LoadBalancerService, Topology}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Serialize)] | #[derive(Debug, Clone, Serialize)] | ||||||
| pub struct LoadBalancerScore { | pub struct LoadBalancerScore { | ||||||
|  | |||||||
| @ -20,8 +20,9 @@ use crate::{ | |||||||
|         }, |         }, | ||||||
|         prometheus::prometheus::{Prometheus, PrometheusReceiver}, |         prometheus::prometheus::{Prometheus, PrometheusReceiver}, | ||||||
|     }, |     }, | ||||||
|     topology::{Url, oberservability::monitoring::AlertReceiver}, |     topology::oberservability::monitoring::AlertReceiver, | ||||||
| }; | }; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Serialize)] | #[derive(Debug, Clone, Serialize)] | ||||||
| pub struct DiscordWebhook { | pub struct DiscordWebhook { | ||||||
|  | |||||||
| @ -19,8 +19,9 @@ use crate::{ | |||||||
|         }, |         }, | ||||||
|         prometheus::prometheus::{Prometheus, PrometheusReceiver}, |         prometheus::prometheus::{Prometheus, PrometheusReceiver}, | ||||||
|     }, |     }, | ||||||
|     topology::{Url, oberservability::monitoring::AlertReceiver}, |     topology::oberservability::monitoring::AlertReceiver, | ||||||
| }; | }; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Serialize)] | #[derive(Debug, Clone, Serialize)] | ||||||
| pub struct WebhookReceiver { | pub struct WebhookReceiver { | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ use async_trait::async_trait; | |||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     modules::{ |     modules::{ | ||||||
| @ -15,6 +15,7 @@ use crate::{ | |||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{PreparationOutcome, Topology, oberservability::monitoring::AlertReceiver}, |     topology::{PreparationOutcome, Topology, oberservability::monitoring::AlertReceiver}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Serialize)] | #[derive(Debug, Clone, Serialize)] | ||||||
| pub struct ApplicationMonitoringScore { | pub struct ApplicationMonitoringScore { | ||||||
|  | |||||||
| @ -6,13 +6,14 @@ use serde::Serialize; | |||||||
| use strum::{Display, EnumString}; | use strum::{Display, EnumString}; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     modules::monitoring::ntfy::helm::ntfy_helm_chart::ntfy_helm_chart_score, |     modules::monitoring::ntfy::helm::ntfy_helm_chart::ntfy_helm_chart_score, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{HelmCommand, K8sclient, MultiTargetTopology, Topology, k8s::K8sClient}, |     topology::{HelmCommand, K8sclient, MultiTargetTopology, Topology, k8s::K8sClient}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Serialize)] | #[derive(Debug, Clone, Serialize)] | ||||||
| pub struct NtfyScore { | pub struct NtfyScore { | ||||||
|  | |||||||
| @ -1,17 +1,19 @@ | |||||||
| use askama::Template; | use askama::Template; | ||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use derive_new::new; | use derive_new::new; | ||||||
|  | use harmony_types::net::Url; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| use std::net::IpAddr; | use std::net::IpAddr; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{FileContent, FilePath, Id, Version}, |     data::{FileContent, FilePath, Version}, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     modules::{dhcp::DhcpScore, http::StaticFilesHttpScore, tftp::TftpScore}, |     modules::{dhcp::DhcpScore, http::StaticFilesHttpScore, tftp::TftpScore}, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{DhcpServer, HttpServer, Router, TftpServer, Topology, Url}, |     topology::{DhcpServer, HttpServer, Router, TftpServer, Topology}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, new, Clone, Serialize)] | #[derive(Debug, new, Clone, Serialize)] | ||||||
| pub struct OkdIpxeScore { | pub struct OkdIpxeScore { | ||||||
|  | |||||||
| @ -5,12 +5,13 @@ use serde::Serialize; | |||||||
| use tokio::sync::RwLock; | use tokio::sync::RwLock; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::Topology, |     topology::Topology, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone)] | #[derive(Debug, Clone)] | ||||||
| pub struct OPNsenseShellCommandScore { | pub struct OPNsenseShellCommandScore { | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ use crate::modules::monitoring::kube_prometheus::crd::service_monitor::{ | |||||||
| use crate::topology::oberservability::monitoring::AlertReceiver; | use crate::topology::oberservability::monitoring::AlertReceiver; | ||||||
| use crate::topology::{K8sclient, Topology, k8s::K8sClient}; | use crate::topology::{K8sclient, Topology, k8s::K8sClient}; | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     modules::monitoring::kube_prometheus::crd::{ |     modules::monitoring::kube_prometheus::crd::{ | ||||||
| @ -37,6 +37,7 @@ use crate::{ | |||||||
|     }, |     }, | ||||||
|     score::Score, |     score::Score, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| use super::prometheus::PrometheusApplicationMonitoring; | use super::prometheus::PrometheusApplicationMonitoring; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -9,12 +9,13 @@ use serde::{Deserialize, Serialize}; | |||||||
| use tokio::time::sleep; | use tokio::time::sleep; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{K8sclient, Topology, k8s::K8sClient}, |     topology::{K8sclient, Topology, k8s::K8sClient}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Clone, Serialize)] | #[derive(Debug, Clone, Serialize)] | ||||||
| pub struct CephRemoveOsd { | pub struct CephRemoveOsd { | ||||||
|  | |||||||
| @ -3,15 +3,15 @@ use std::{sync::Arc, time::Duration}; | |||||||
| use async_trait::async_trait; | use async_trait::async_trait; | ||||||
| use log::debug; | use log::debug; | ||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| use tokio::time::Instant; |  | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{K8sclient, Topology, k8s::K8sClient}, |     topology::{K8sclient, Topology, k8s::K8sClient}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Clone, Debug, Serialize)] | #[derive(Clone, Debug, Serialize)] | ||||||
| pub struct CephVerifyClusterHealth { | pub struct CephVerifyClusterHealth { | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ use async_trait::async_trait; | |||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
| @ -14,6 +14,7 @@ use crate::{ | |||||||
|         tenant::{TenantConfig, TenantManager}, |         tenant::{TenantConfig, TenantManager}, | ||||||
|     }, |     }, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Serialize, Clone)] | #[derive(Debug, Serialize, Clone)] | ||||||
| pub struct TenantScore { | pub struct TenantScore { | ||||||
|  | |||||||
| @ -3,12 +3,14 @@ use derive_new::new; | |||||||
| use serde::Serialize; | use serde::Serialize; | ||||||
| 
 | 
 | ||||||
| use crate::{ | use crate::{ | ||||||
|     data::{Id, Version}, |     data::Version, | ||||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, |     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
|     score::Score, |     score::Score, | ||||||
|     topology::{Router, TftpServer, Topology, Url}, |     topology::{Router, TftpServer, Topology}, | ||||||
| }; | }; | ||||||
|  | use harmony_types::id::Id; | ||||||
|  | use harmony_types::net::Url; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, new, Clone, Serialize)] | #[derive(Debug, new, Clone, Serialize)] | ||||||
| pub struct TftpScore { | pub struct TftpScore { | ||||||
|  | |||||||
| @ -4,8 +4,7 @@ use crate::local_presence::SERVICE_NAME; | |||||||
| 
 | 
 | ||||||
| pub type DiscoveryEvent = ServiceEvent; | pub type DiscoveryEvent = ServiceEvent; | ||||||
| 
 | 
 | ||||||
| pub fn discover_agents(timeout: Option<u64>, on_event: impl Fn(DiscoveryEvent) + Send + 'static) | pub fn discover_agents(timeout: Option<u64>, on_event: impl Fn(DiscoveryEvent) + Send + 'static) { | ||||||
| { |  | ||||||
|     // Create a new mDNS daemon.
 |     // Create a new mDNS daemon.
 | ||||||
|     let mdns = ServiceDaemon::new().expect("Failed to create mDNS daemon"); |     let mdns = ServiceDaemon::new().expect("Failed to create mDNS daemon"); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -6,4 +6,6 @@ readme.workspace = true | |||||||
| license.workspace = true | license.workspace = true | ||||||
| 
 | 
 | ||||||
| [dependencies] | [dependencies] | ||||||
| serde = { version = "1.0.209", features = ["derive"] } | serde.workspace = true | ||||||
|  | url.workspace = true | ||||||
|  | rand.workspace = true | ||||||
|  | |||||||
							
								
								
									
										72
									
								
								harmony_types/src/id.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								harmony_types/src/id.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,72 @@ | |||||||
|  | use rand::distr::Alphanumeric; | ||||||
|  | use rand::distr::SampleString; | ||||||
|  | use std::str::FromStr; | ||||||
|  | use std::time::SystemTime; | ||||||
|  | use std::time::UNIX_EPOCH; | ||||||
|  | 
 | ||||||
|  | use serde::{Deserialize, Serialize}; | ||||||
|  | 
 | ||||||
|  | /// A unique identifier designed for ease of use.
 | ||||||
|  | ///
 | ||||||
|  | /// You can pass it any String to use and Id, or you can use the default format with `Id::default()`
 | ||||||
|  | ///
 | ||||||
|  | /// The default format looks like this
 | ||||||
|  | ///
 | ||||||
|  | /// `462d4c_g2COgai`
 | ||||||
|  | ///
 | ||||||
|  | /// The first part is the unix timesamp in hexadecimal which makes Id easily sorted by creation time.
 | ||||||
|  | /// Second part is a serie of 7 random characters.
 | ||||||
|  | ///
 | ||||||
|  | /// **It is not meant to be very secure or unique**, it is suitable to generate up to 10 000 items per
 | ||||||
|  | /// second with a reasonable collision rate of 0,000014 % as calculated by this calculator : https://kevingal.com/apps/collision.html
 | ||||||
|  | #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||||||
|  | pub struct Id { | ||||||
|  |     value: String, | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Id { | ||||||
|  |     pub fn empty() -> Self { | ||||||
|  |         Id { | ||||||
|  |             value: String::new(), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl FromStr for Id { | ||||||
|  |     type Err = (); | ||||||
|  | 
 | ||||||
|  |     fn from_str(s: &str) -> Result<Self, Self::Err> { | ||||||
|  |         Ok(Id { | ||||||
|  |             value: s.to_string(), | ||||||
|  |         }) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl From<String> for Id { | ||||||
|  |     fn from(value: String) -> Self { | ||||||
|  |         Self { value } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl std::fmt::Display for Id { | ||||||
|  |     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|  |         f.write_str(&self.value) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Default for Id { | ||||||
|  |     fn default() -> Self { | ||||||
|  |         let start = SystemTime::now(); | ||||||
|  |         let since_the_epoch = start | ||||||
|  |             .duration_since(UNIX_EPOCH) | ||||||
|  |             .expect("Time went backwards"); | ||||||
|  |         let timestamp = since_the_epoch.as_secs(); | ||||||
|  | 
 | ||||||
|  |         let hex_timestamp = format!("{:x}", timestamp & 0xffffff); | ||||||
|  | 
 | ||||||
|  |         let random_part: String = Alphanumeric.sample_string(&mut rand::rng(), 7); | ||||||
|  | 
 | ||||||
|  |         let value = format!("{}_{}", hex_timestamp, random_part); | ||||||
|  |         Self { value } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -1,28 +1,2 @@ | |||||||
| pub mod net { | pub mod id; | ||||||
|     use serde::Serialize; | pub mod net; | ||||||
| 
 |  | ||||||
|     #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize)] |  | ||||||
|     pub struct MacAddress(pub [u8; 6]); |  | ||||||
| 
 |  | ||||||
|     impl MacAddress { |  | ||||||
|         #[cfg(test)] |  | ||||||
|         pub fn dummy() -> Self { |  | ||||||
|             Self([0, 0, 0, 0, 0, 0]) |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     impl From<&MacAddress> for String { |  | ||||||
|         fn from(value: &MacAddress) -> Self { |  | ||||||
|             format!( |  | ||||||
|                 "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", |  | ||||||
|                 value.0[0], value.0[1], value.0[2], value.0[3], value.0[4], value.0[5] |  | ||||||
|             ) |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     impl std::fmt::Display for MacAddress { |  | ||||||
|         fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |  | ||||||
|             f.write_fmt(format_args!("MacAddress {}", String::from(self))) |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | |||||||
							
								
								
									
										55
									
								
								harmony_types/src/net.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								harmony_types/src/net.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,55 @@ | |||||||
|  | use serde::Serialize; | ||||||
|  | 
 | ||||||
|  | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize)] | ||||||
|  | pub struct MacAddress(pub [u8; 6]); | ||||||
|  | 
 | ||||||
|  | impl MacAddress { | ||||||
|  |     #[cfg(test)] | ||||||
|  |     pub fn dummy() -> Self { | ||||||
|  |         Self([0, 0, 0, 0, 0, 0]) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl From<&MacAddress> for String { | ||||||
|  |     fn from(value: &MacAddress) -> Self { | ||||||
|  |         format!( | ||||||
|  |             "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", | ||||||
|  |             value.0[0], value.0[1], value.0[2], value.0[3], value.0[4], value.0[5] | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl std::fmt::Display for MacAddress { | ||||||
|  |     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|  |         f.write_fmt(format_args!("MacAddress {}", String::from(self))) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | pub type IpAddress = std::net::IpAddr; | ||||||
|  | 
 | ||||||
|  | #[derive(Debug, Clone)] | ||||||
|  | pub enum Url { | ||||||
|  |     LocalFolder(String), | ||||||
|  |     Url(url::Url), | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl Serialize for Url { | ||||||
|  |     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||||||
|  |     where | ||||||
|  |         S: serde::Serializer, | ||||||
|  |     { | ||||||
|  |         match self { | ||||||
|  |             Url::LocalFolder(path) => serializer.serialize_str(path), | ||||||
|  |             Url::Url(url) => serializer.serialize_str(url.as_str()), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | impl std::fmt::Display for Url { | ||||||
|  |     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|  |         match self { | ||||||
|  |             Url::LocalFolder(path) => write!(f, "{}", path), | ||||||
|  |             Url::Url(url) => write!(f, "{}", url), | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user