refact: Move basic types to harmony_types crate to avoid external dependencies. #126
							
								
								
									
										8
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -1671,6 +1671,7 @@ dependencies = [ | ||||
|  "env_logger", | ||||
|  "harmony", | ||||
|  "harmony_cli", | ||||
|  "harmony_types", | ||||
|  "logging", | ||||
|  "tokio", | ||||
|  "url", | ||||
| @ -1732,6 +1733,7 @@ dependencies = [ | ||||
|  "harmony", | ||||
|  "harmony_cli", | ||||
|  "harmony_macros", | ||||
|  "harmony_types", | ||||
|  "tokio", | ||||
|  "url", | ||||
| ] | ||||
| @ -1743,6 +1745,7 @@ dependencies = [ | ||||
|  "cidr", | ||||
|  "harmony", | ||||
|  "harmony_cli", | ||||
|  "harmony_types", | ||||
|  "tokio", | ||||
|  "url", | ||||
| ] | ||||
| @ -2293,7 +2296,6 @@ dependencies = [ | ||||
|  "opnsense-config", | ||||
|  "opnsense-config-xml", | ||||
|  "pretty_assertions", | ||||
|  "rand 0.9.1", | ||||
|  "reqwest 0.11.27", | ||||
|  "russh", | ||||
|  "rust-ipmi", | ||||
| @ -2437,7 +2439,9 @@ dependencies = [ | ||||
| name = "harmony_types" | ||||
| version = "0.1.0" | ||||
| dependencies = [ | ||||
|  "rand 0.9.1", | ||||
|  "serde", | ||||
|  "url", | ||||
| ] | ||||
| 
 | ||||
| [[package]] | ||||
| @ -3849,7 +3853,7 @@ dependencies = [ | ||||
|  "env_logger", | ||||
|  "log", | ||||
|  "pretty_assertions", | ||||
|  "rand 0.8.5", | ||||
|  "rand 0.9.1", | ||||
|  "serde", | ||||
|  "thiserror 2.0.14", | ||||
|  "tokio", | ||||
|  | ||||
| @ -36,7 +36,7 @@ tokio = { version = "1.40", features = [ | ||||
| cidr = { features = ["serde"], version = "0.2" } | ||||
| russh = "0.45" | ||||
| russh-keys = "0.45" | ||||
| rand = "0.8" | ||||
| rand = "0.9" | ||||
| url = "2.5" | ||||
| kube = { version = "1.1.0", features = [ | ||||
|   "config", | ||||
| @ -67,3 +67,4 @@ serde = { version = "1.0.209", features = ["derive", "rc"] } | ||||
| serde_json = "1.0.127" | ||||
| askama = "0.14" | ||||
| 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] | ||||
| env_logger.workspace = true | ||||
| harmony = { version = "0.1.0", path = "../../harmony" } | ||||
| harmony_cli = { version = "0.1.0", path = "../../harmony_cli" } | ||||
| harmony = { path = "../../harmony" } | ||||
| harmony_cli = { path = "../../harmony_cli" } | ||||
| harmony_types = { path = "../../harmony_types" } | ||||
| logging = "0.1.0" | ||||
| tokio.workspace = true | ||||
| url.workspace = true | ||||
|  | ||||
| @ -1,15 +1,16 @@ | ||||
| use std::{path::PathBuf, str::FromStr, sync::Arc}; | ||||
| 
 | ||||
| use harmony::{ | ||||
|     data::Id, | ||||
|     inventory::Inventory, | ||||
|     modules::{ | ||||
|         application::{ApplicationScore, RustWebFramework, RustWebapp, features::Monitoring}, | ||||
|         monitoring::alert_channel::webhook_receiver::WebhookReceiver, | ||||
|         tenant::TenantScore, | ||||
|     }, | ||||
|     topology::{K8sAnywhereTopology, Url, tenant::TenantConfig}, | ||||
|     topology::{K8sAnywhereTopology, tenant::TenantConfig}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| #[tokio::main] | ||||
| async fn main() { | ||||
|  | ||||
| @ -2,8 +2,9 @@ use harmony::{ | ||||
|     data::Version, | ||||
|     inventory::Inventory, | ||||
|     modules::lamp::{LAMPConfig, LAMPScore}, | ||||
|     topology::{K8sAnywhereTopology, Url}, | ||||
|     topology::K8sAnywhereTopology, | ||||
| }; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| #[tokio::main] | ||||
| async fn main() { | ||||
|  | ||||
| @ -6,8 +6,9 @@ readme.workspace = true | ||||
| license.workspace = true | ||||
| 
 | ||||
| [dependencies] | ||||
| harmony = { version = "0.1.0", path = "../../harmony" } | ||||
| harmony_cli = { version = "0.1.0", path = "../../harmony_cli" } | ||||
| harmony_macros = { version = "0.1.0", path = "../../harmony_macros" } | ||||
| harmony = { path = "../../harmony" } | ||||
| harmony_cli = { path = "../../harmony_cli" } | ||||
| harmony_macros = { path = "../../harmony_macros" } | ||||
| harmony_types = { path = "../../harmony_types" } | ||||
| tokio.workspace = true | ||||
| url.workspace = true | ||||
|  | ||||
| @ -22,8 +22,9 @@ use harmony::{ | ||||
|             k8s::pvc::high_pvc_fill_rate_over_two_days, | ||||
|         }, | ||||
|     }, | ||||
|     topology::{K8sAnywhereTopology, Url}, | ||||
|     topology::K8sAnywhereTopology, | ||||
| }; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| #[tokio::main] | ||||
| async fn main() { | ||||
|  | ||||
| @ -7,7 +7,8 @@ license.workspace = true | ||||
| 
 | ||||
| [dependencies] | ||||
| cidr.workspace = true | ||||
| harmony = { version = "0.1.0", path = "../../harmony" } | ||||
| harmony_cli = { version = "0.1.0", path = "../../harmony_cli" } | ||||
| harmony = { path = "../../harmony" } | ||||
| harmony_cli = { path = "../../harmony_cli" } | ||||
| harmony_types = { path = "../../harmony_types" } | ||||
| tokio.workspace = true | ||||
| url.workspace = true | ||||
|  | ||||
| @ -1,7 +1,6 @@ | ||||
| use std::{collections::HashMap, str::FromStr}; | ||||
| 
 | ||||
| use harmony::{ | ||||
|     data::Id, | ||||
|     inventory::Inventory, | ||||
|     modules::{ | ||||
|         monitoring::{ | ||||
| @ -19,10 +18,12 @@ use harmony::{ | ||||
|         tenant::TenantScore, | ||||
|     }, | ||||
|     topology::{ | ||||
|         K8sAnywhereTopology, Url, | ||||
|         K8sAnywhereTopology, | ||||
|         tenant::{ResourceLimits, TenantConfig, TenantNetworkPolicy}, | ||||
|     }, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| #[tokio::main] | ||||
| async fn main() { | ||||
|  | ||||
| @ -18,9 +18,10 @@ use harmony::{ | ||||
|         }, | ||||
|         tftp::TftpScore, | ||||
|     }, | ||||
|     topology::{LogicalHost, UnmanagedRouter, Url}, | ||||
|     topology::{LogicalHost, UnmanagedRouter}, | ||||
| }; | ||||
| use harmony_macros::{ip, mac_address}; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| #[tokio::main] | ||||
| async fn main() { | ||||
|  | ||||
| @ -15,9 +15,10 @@ use harmony::{ | ||||
|         opnsense::OPNsenseShellCommandScore, | ||||
|         tftp::TftpScore, | ||||
|     }, | ||||
|     topology::{LogicalHost, UnmanagedRouter, Url}, | ||||
|     topology::{LogicalHost, UnmanagedRouter}, | ||||
| }; | ||||
| use harmony_macros::{ip, mac_address}; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| #[tokio::main] | ||||
| async fn main() { | ||||
|  | ||||
| @ -11,8 +11,9 @@ use harmony::{ | ||||
|             discord_alert_channel::DiscordWebhook, webhook_receiver::WebhookReceiver, | ||||
|         }, | ||||
|     }, | ||||
|     topology::{K8sAnywhereTopology, Url}, | ||||
|     topology::K8sAnywhereTopology, | ||||
| }; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| #[tokio::main] | ||||
| async fn main() { | ||||
|  | ||||
| @ -1,11 +1,11 @@ | ||||
| use std::str::FromStr; | ||||
| 
 | ||||
| use harmony::{ | ||||
|     data::Id, | ||||
|     inventory::Inventory, | ||||
|     modules::tenant::TenantScore, | ||||
|     topology::{K8sAnywhereTopology, tenant::TenantConfig}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[tokio::main] | ||||
| async fn main() { | ||||
|  | ||||
| @ -9,7 +9,6 @@ license.workspace = true | ||||
| testing = [] | ||||
| 
 | ||||
| [dependencies] | ||||
| rand = "0.9" | ||||
| hex = "0.4" | ||||
| reqwest = { version = "0.11", features = ["blocking", "json", "rustls-tls"], default-features = false } | ||||
| russh = "0.45.0" | ||||
|  | ||||
| @ -1,6 +1,4 @@ | ||||
| mod file; | ||||
| mod id; | ||||
| mod version; | ||||
| pub use file::*; | ||||
| pub use id::*; | ||||
| pub use version::*; | ||||
|  | ||||
| @ -1,8 +1,7 @@ | ||||
| use std::fmt; | ||||
| 
 | ||||
| use async_trait::async_trait; | ||||
| 
 | ||||
| use super::topology::IpAddress; | ||||
| use harmony_types::net::IpAddress; | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub enum ExecutorError { | ||||
|  | ||||
| @ -199,7 +199,7 @@ pub struct NetworkInterface { | ||||
| #[cfg(test)] | ||||
| use harmony_macros::mac_address; | ||||
| 
 | ||||
| use crate::data::Id; | ||||
| use harmony_types::id::Id; | ||||
| #[cfg(test)] | ||||
| impl NetworkInterface { | ||||
|     pub fn dummy() -> Self { | ||||
|  | ||||
| @ -1,13 +1,11 @@ | ||||
| use harmony_types::id::Id; | ||||
| use std::error::Error; | ||||
| 
 | ||||
| use async_trait::async_trait; | ||||
| use derive_new::new; | ||||
| 
 | ||||
| use super::{ | ||||
|     data::{Id, Version}, | ||||
|     executors::ExecutorError, | ||||
|     inventory::Inventory, | ||||
|     topology::PreparationError, | ||||
|     data::Version, executors::ExecutorError, inventory::Inventory, topology::PreparationError, | ||||
| }; | ||||
| 
 | ||||
| pub enum InterpretName { | ||||
|  | ||||
| @ -1,3 +1,4 @@ | ||||
| use harmony_types::id::Id; | ||||
| use std::collections::BTreeMap; | ||||
| 
 | ||||
| use async_trait::async_trait; | ||||
| @ -5,7 +6,6 @@ use serde::Serialize; | ||||
| use serde_value::Value; | ||||
| 
 | ||||
| use super::{ | ||||
|     data::Id, | ||||
|     instrumentation::{self, HarmonyEvent}, | ||||
|     interpret::{Interpret, InterpretError, Outcome}, | ||||
|     inventory::Inventory, | ||||
|  | ||||
| @ -1,6 +1,7 @@ | ||||
| use async_trait::async_trait; | ||||
| use harmony_macros::ip; | ||||
| use harmony_types::net::MacAddress; | ||||
| use harmony_types::net::Url; | ||||
| use log::debug; | ||||
| use log::info; | ||||
| 
 | ||||
| @ -26,7 +27,6 @@ use super::Router; | ||||
| use super::TftpServer; | ||||
| 
 | ||||
| use super::Topology; | ||||
| use super::Url; | ||||
| use super::k8s::K8sClient; | ||||
| use std::sync::Arc; | ||||
| 
 | ||||
|  | ||||
| @ -1,8 +1,8 @@ | ||||
| use crate::{data::FileContent, executors::ExecutorError}; | ||||
| use async_trait::async_trait; | ||||
| 
 | ||||
| use super::{IpAddress, Url}; | ||||
| 
 | ||||
| use harmony_types::net::IpAddress; | ||||
| use harmony_types::net::Url; | ||||
| #[async_trait] | ||||
| pub trait HttpServer: Send + Sync { | ||||
|     async fn serve_files(&self, url: &Url) -> Result<(), ExecutorError>; | ||||
|  | ||||
| @ -4,8 +4,9 @@ use async_trait::async_trait; | ||||
| use log::debug; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use super::{IpAddress, LogicalHost}; | ||||
| use super::LogicalHost; | ||||
| use crate::executors::ExecutorError; | ||||
| use harmony_types::net::IpAddress; | ||||
| 
 | ||||
| impl std::fmt::Debug for dyn LoadBalancer { | ||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| mod ha_cluster; | ||||
| use harmony_types::net::IpAddress; | ||||
| mod host_binding; | ||||
| mod http; | ||||
| pub mod installable; | ||||
| @ -32,7 +33,6 @@ use super::{ | ||||
|     instrumentation::{self, HarmonyEvent}, | ||||
| }; | ||||
| use std::error::Error; | ||||
| use std::net::IpAddr; | ||||
| 
 | ||||
| /// Represents a logical view of an infrastructure environment providing specific capabilities.
 | ||||
| ///
 | ||||
| @ -196,35 +196,6 @@ pub trait MultiTargetTopology: Topology { | ||||
|     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.
 | ||||
| ///
 | ||||
| /// A LogicalHost can represent various roles within the infrastructure, such as:
 | ||||
| @ -263,7 +234,8 @@ impl LogicalHost { | ||||
|     ///
 | ||||
|     /// ```
 | ||||
|     /// 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 hosts = LogicalHost::create_hosts(3, start_ip, "worker");
 | ||||
| @ -319,7 +291,7 @@ fn increment_ip(ip: IpAddress, increment: u32) -> Option<IpAddress> { | ||||
| 
 | ||||
| #[cfg(test)] | ||||
| mod tests { | ||||
|     use super::*; | ||||
|     use harmony_types::net::Url; | ||||
|     use serde_json; | ||||
| 
 | ||||
|     #[test] | ||||
|  | ||||
| @ -1,12 +1,12 @@ | ||||
| use std::{net::Ipv4Addr, str::FromStr, sync::Arc}; | ||||
| 
 | ||||
| use async_trait::async_trait; | ||||
| use harmony_types::net::MacAddress; | ||||
| use harmony_types::net::{IpAddress, MacAddress}; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use crate::executors::ExecutorError; | ||||
| 
 | ||||
| use super::{IpAddress, LogicalHost, k8s::K8sClient}; | ||||
| use super::{LogicalHost, k8s::K8sClient}; | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub struct DHCPStaticEntry { | ||||
|  | ||||
| @ -4,11 +4,12 @@ use async_trait::async_trait; | ||||
| use log::debug; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     topology::{Topology, installable::Installable}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[async_trait] | ||||
| pub trait AlertSender: Send + Sync + std::fmt::Debug { | ||||
|  | ||||
| @ -2,7 +2,7 @@ pub mod k8s; | ||||
| mod manager; | ||||
| pub mod network_policy; | ||||
| 
 | ||||
| use crate::data::Id; | ||||
| use harmony_types::id::Id; | ||||
| pub use manager::*; | ||||
| use serde::{Deserialize, Serialize}; | ||||
| use std::str::FromStr; | ||||
|  | ||||
| @ -1,7 +1,7 @@ | ||||
| use crate::executors::ExecutorError; | ||||
| use async_trait::async_trait; | ||||
| 
 | ||||
| use super::{IpAddress, Url}; | ||||
| use harmony_types::net::{IpAddress, Url}; | ||||
| 
 | ||||
| #[async_trait] | ||||
| pub trait TftpServer: Send + Sync { | ||||
|  | ||||
| @ -3,11 +3,9 @@ use std::sync::Arc; | ||||
| 
 | ||||
| use russh::{client, keys::key}; | ||||
| 
 | ||||
| use crate::{ | ||||
|     domain::executors::{ExecutorError, SshClient}, | ||||
|     topology::IpAddress, | ||||
| }; | ||||
| use crate::domain::executors::{ExecutorError, SshClient}; | ||||
| 
 | ||||
| use harmony_types::net::IpAddress; | ||||
| pub struct RusshClient; | ||||
| 
 | ||||
| #[async_trait] | ||||
|  | ||||
| @ -1,6 +1,6 @@ | ||||
| use crate::hardware::ManagementInterface; | ||||
| use crate::topology::IpAddress; | ||||
| use derive_new::new; | ||||
| use harmony_types::net::IpAddress; | ||||
| use harmony_types::net::MacAddress; | ||||
| use log::info; | ||||
| use serde::Serialize; | ||||
|  | ||||
| @ -1,10 +1,10 @@ | ||||
| use crate::{ | ||||
|     data::Id, | ||||
|     hardware::PhysicalHost, | ||||
|     inventory::{InventoryRepository, RepoError}, | ||||
| }; | ||||
| use async_trait::async_trait; | ||||
| use log::{info, warn}; | ||||
| use harmony_types::id::Id; | ||||
| use log::info; | ||||
| use sqlx::{Pool, Sqlite, SqlitePool}; | ||||
| 
 | ||||
| /// A thread-safe, connection-pooled repository using SQLite.
 | ||||
|  | ||||
| @ -4,10 +4,11 @@ use log::info; | ||||
| 
 | ||||
| use crate::{ | ||||
|     executors::ExecutorError, | ||||
|     topology::{DHCPStaticEntry, DhcpServer, IpAddress, LogicalHost, PxeOptions}, | ||||
|     topology::{DHCPStaticEntry, DhcpServer, LogicalHost, PxeOptions}, | ||||
| }; | ||||
| 
 | ||||
| use super::OPNSenseFirewall; | ||||
| use harmony_types::net::IpAddress; | ||||
| 
 | ||||
| #[async_trait] | ||||
| impl DhcpServer for OPNSenseFirewall { | ||||
|  | ||||
| @ -1,11 +1,11 @@ | ||||
| use crate::infra::opnsense::Host; | ||||
| use crate::infra::opnsense::IpAddress; | ||||
| use crate::infra::opnsense::LogicalHost; | ||||
| use crate::{ | ||||
|     executors::ExecutorError, | ||||
|     topology::{DnsRecord, DnsServer}, | ||||
| }; | ||||
| use async_trait::async_trait; | ||||
| use harmony_types::net::IpAddress; | ||||
| 
 | ||||
| use super::OPNSenseFirewall; | ||||
| 
 | ||||
|  | ||||
| @ -1,9 +1,10 @@ | ||||
| use crate::{ | ||||
|     executors::ExecutorError, | ||||
|     topology::{Firewall, FirewallRule, IpAddress, LogicalHost}, | ||||
|     topology::{Firewall, FirewallRule, LogicalHost}, | ||||
| }; | ||||
| 
 | ||||
| use super::OPNSenseFirewall; | ||||
| use harmony_types::net::IpAddress; | ||||
| 
 | ||||
| impl Firewall for OPNSenseFirewall { | ||||
|     fn add_rule(&mut self, _rule: FirewallRule) -> Result<(), ExecutorError> { | ||||
|  | ||||
| @ -1,13 +1,11 @@ | ||||
| use async_trait::async_trait; | ||||
| use log::info; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::FileContent, | ||||
|     executors::ExecutorError, | ||||
|     topology::{HttpServer, IpAddress, Url}, | ||||
| }; | ||||
| use crate::{data::FileContent, executors::ExecutorError, topology::HttpServer}; | ||||
| 
 | ||||
| use super::OPNSenseFirewall; | ||||
| use harmony_types::net::IpAddress; | ||||
| use harmony_types::net::Url; | ||||
| const OPNSENSE_HTTP_ROOT_PATH: &str = "/usr/local/http"; | ||||
| 
 | ||||
| #[async_trait] | ||||
|  | ||||
| @ -6,10 +6,11 @@ use uuid::Uuid; | ||||
| use crate::{ | ||||
|     executors::ExecutorError, | ||||
|     topology::{ | ||||
|         BackendServer, HealthCheck, HttpMethod, HttpStatusCode, IpAddress, LoadBalancer, | ||||
|         LoadBalancerService, LogicalHost, | ||||
|         BackendServer, HealthCheck, HttpMethod, HttpStatusCode, LoadBalancer, LoadBalancerService, | ||||
|         LogicalHost, | ||||
|     }, | ||||
| }; | ||||
| use harmony_types::net::IpAddress; | ||||
| 
 | ||||
| use super::OPNSenseFirewall; | ||||
| 
 | ||||
|  | ||||
| @ -11,10 +11,8 @@ pub use management::*; | ||||
| use opnsense_config_xml::Host; | ||||
| use tokio::sync::RwLock; | ||||
| 
 | ||||
| use crate::{ | ||||
|     executors::ExecutorError, | ||||
|     topology::{IpAddress, LogicalHost}, | ||||
| }; | ||||
| use crate::{executors::ExecutorError, topology::LogicalHost}; | ||||
| use harmony_types::net::IpAddress; | ||||
| 
 | ||||
| #[derive(Debug, Clone)] | ||||
| pub struct OPNSenseFirewall { | ||||
|  | ||||
| @ -1,10 +1,9 @@ | ||||
| use async_trait::async_trait; | ||||
| use log::info; | ||||
| 
 | ||||
| use crate::{ | ||||
|     executors::ExecutorError, | ||||
|     topology::{IpAddress, TftpServer, Url}, | ||||
| }; | ||||
| use crate::{executors::ExecutorError, topology::TftpServer}; | ||||
| use harmony_types::net::IpAddress; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| use super::OPNSenseFirewall; | ||||
| 
 | ||||
|  | ||||
| @ -4,13 +4,14 @@ use serde::Serialize; | ||||
| use std::str::FromStr; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     modules::helm::chart::{HelmChartScore, HelmRepository}, | ||||
|     score::Score, | ||||
|     topology::{HelmCommand, K8sclient, Topology}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| use super::ArgoApplication; | ||||
| 
 | ||||
|  | ||||
| @ -11,7 +11,7 @@ use crate::{ | ||||
|         alert_channel::webhook_receiver::WebhookReceiver, ntfy::ntfy::NtfyScore, | ||||
|     }, | ||||
|     score::Score, | ||||
|     topology::{HelmCommand, K8sclient, Topology, Url, tenant::TenantManager}, | ||||
|     topology::{HelmCommand, K8sclient, Topology, tenant::TenantManager}, | ||||
| }; | ||||
| use crate::{ | ||||
|     modules::prometheus::prometheus::PrometheusApplicationMonitoring, | ||||
| @ -19,6 +19,7 @@ use crate::{ | ||||
| }; | ||||
| use async_trait::async_trait; | ||||
| use base64::{Engine as _, engine::general_purpose}; | ||||
| use harmony_types::net::Url; | ||||
| use log::{debug, info}; | ||||
| 
 | ||||
| #[derive(Debug, Clone)] | ||||
|  | ||||
| @ -13,12 +13,13 @@ use async_trait::async_trait; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     instrumentation::{self, HarmonyEvent}, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     topology::Topology, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Clone, Debug)] | ||||
| pub enum ApplicationFeatureStatus { | ||||
|  | ||||
| @ -15,10 +15,8 @@ use serde::Serialize; | ||||
| use tar::Archive; | ||||
| 
 | ||||
| use crate::config::{REGISTRY_PROJECT, REGISTRY_URL}; | ||||
| use crate::{ | ||||
|     score::Score, | ||||
|     topology::{Topology, Url}, | ||||
| }; | ||||
| use crate::{score::Score, topology::Topology}; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| use super::{Application, ApplicationFeature, ApplicationInterpret, HelmPackage, OCICompliant}; | ||||
| 
 | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| use async_trait::async_trait; | ||||
| use derive_new::new; | ||||
| use harmony_types::id::Id; | ||||
| use log::info; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| @ -7,10 +8,11 @@ use crate::{ | ||||
|     domain::{data::Version, interpret::InterpretStatus}, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     topology::{DHCPStaticEntry, DhcpServer, HostBinding, IpAddress, PxeOptions, Topology}, | ||||
|     topology::{DHCPStaticEntry, DhcpServer, HostBinding, PxeOptions, Topology}, | ||||
| }; | ||||
| 
 | ||||
| use crate::domain::score::Score; | ||||
| use harmony_types::net::IpAddress; | ||||
| 
 | ||||
| #[derive(Debug, new, Clone, Serialize)] | ||||
| pub struct DhcpScore { | ||||
| @ -135,7 +137,7 @@ impl<T: DhcpServer> Interpret<T> for DhcpInterpret { | ||||
|         self.status.clone() | ||||
|     } | ||||
| 
 | ||||
|     fn get_children(&self) -> Vec<crate::domain::data::Id> { | ||||
|     fn get_children(&self) -> Vec<Id> { | ||||
|         todo!() | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| use async_trait::async_trait; | ||||
| use derive_new::new; | ||||
| use harmony_types::id::Id; | ||||
| use log::info; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| @ -91,7 +92,7 @@ impl<T: Topology + DnsServer> Interpret<T> for DnsInterpret { | ||||
|         self.status.clone() | ||||
|     } | ||||
| 
 | ||||
|     fn get_children(&self) -> Vec<crate::domain::data::Id> { | ||||
|     fn get_children(&self) -> Vec<Id> { | ||||
|         todo!() | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| use async_trait::async_trait; | ||||
| use harmony_types::id::Id; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use crate::{ | ||||
| @ -67,7 +68,7 @@ impl<T: Topology> Interpret<T> for DummyInterpret { | ||||
|         self.status.clone() | ||||
|     } | ||||
| 
 | ||||
|     fn get_children(&self) -> Vec<crate::domain::data::Id> { | ||||
|     fn get_children(&self) -> Vec<Id> { | ||||
|         todo!() | ||||
|     } | ||||
| 
 | ||||
| @ -113,7 +114,7 @@ impl<T: Topology> Interpret<T> for PanicInterpret { | ||||
|         InterpretStatus::QUEUED | ||||
|     } | ||||
| 
 | ||||
|     fn get_children(&self) -> Vec<crate::domain::data::Id> { | ||||
|     fn get_children(&self) -> Vec<Id> { | ||||
|         todo!() | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -1,9 +1,10 @@ | ||||
| use crate::data::{Id, Version}; | ||||
| use crate::data::Version; | ||||
| use crate::interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}; | ||||
| use crate::inventory::Inventory; | ||||
| use crate::score::Score; | ||||
| use crate::topology::{HelmCommand, Topology}; | ||||
| use async_trait::async_trait; | ||||
| use harmony_types::id::Id; | ||||
| use helm_wrapper_rs; | ||||
| use helm_wrapper_rs::blocking::{DefaultHelmExecutor, HelmExecutor}; | ||||
| use log::{debug, info, warn}; | ||||
|  | ||||
| @ -8,11 +8,12 @@ use std::process::{Command, Output}; | ||||
| use temp_dir::{self, TempDir}; | ||||
| use temp_file::TempFile; | ||||
| 
 | ||||
| use crate::data::{Id, Version}; | ||||
| use crate::data::Version; | ||||
| use crate::interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}; | ||||
| use crate::inventory::Inventory; | ||||
| use crate::score::Score; | ||||
| use crate::topology::{HelmCommand, K8sclient, Topology}; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Clone)] | ||||
| pub struct HelmCommandExecutor { | ||||
|  | ||||
| @ -3,12 +3,14 @@ use derive_new::new; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{FileContent, Id, Version}, | ||||
|     data::{FileContent, Version}, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     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
 | ||||
| ///
 | ||||
|  | ||||
| @ -4,12 +4,13 @@ use log::{debug, info}; | ||||
| use serde::{Deserialize, Serialize}; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     score::Score, | ||||
|     topology::Topology, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| /// This launches an harmony_inventory_agent discovery process
 | ||||
| /// This will allow us to register/update hosts running harmony_inventory_agent
 | ||||
|  | ||||
| @ -3,12 +3,13 @@ use derive_new::new; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     score::Score, | ||||
|     topology::Topology, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Debug, new, Clone, Serialize)] | ||||
| pub struct IpxeScore { | ||||
|  | ||||
| @ -6,12 +6,13 @@ use serde::Serialize; | ||||
| 
 | ||||
| use crate::{ | ||||
|     config::HARMONY_DATA_DIR, | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     score::Score, | ||||
|     topology::Topology, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Debug, Clone, Serialize)] | ||||
| pub struct K3DInstallationScore { | ||||
|  | ||||
| @ -5,12 +5,13 @@ use log::info; | ||||
| use serde::{Serialize, de::DeserializeOwned}; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     score::Score, | ||||
|     topology::{K8sclient, Topology}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Debug, Clone, Serialize)] | ||||
| 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 fqdn::fqdn; | ||||
| use harmony_macros::ingress_path; | ||||
| use harmony_types::net::Url; | ||||
| use non_blank_string_rs::NonBlankString; | ||||
| use serde_json::json; | ||||
| use std::collections::HashMap; | ||||
| @ -18,13 +19,14 @@ use crate::config::{REGISTRY_PROJECT, REGISTRY_URL}; | ||||
| use crate::modules::k8s::ingress::K8sIngressScore; | ||||
| use crate::topology::HelmCommand; | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     modules::k8s::deployment::K8sDeploymentScore, | ||||
|     score::Score, | ||||
|     topology::{K8sclient, Topology, Url}, | ||||
|     topology::{K8sclient, Topology}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| use super::helm::chart::HelmChartScore; | ||||
| 
 | ||||
|  | ||||
| @ -3,12 +3,13 @@ use log::info; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     score::Score, | ||||
|     topology::{LoadBalancer, LoadBalancerService, Topology}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Debug, Clone, Serialize)] | ||||
| pub struct LoadBalancerScore { | ||||
|  | ||||
| @ -20,8 +20,9 @@ use crate::{ | ||||
|         }, | ||||
|         prometheus::prometheus::{Prometheus, PrometheusReceiver}, | ||||
|     }, | ||||
|     topology::{Url, oberservability::monitoring::AlertReceiver}, | ||||
|     topology::oberservability::monitoring::AlertReceiver, | ||||
| }; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| #[derive(Debug, Clone, Serialize)] | ||||
| pub struct DiscordWebhook { | ||||
|  | ||||
| @ -19,8 +19,9 @@ use crate::{ | ||||
|         }, | ||||
|         prometheus::prometheus::{Prometheus, PrometheusReceiver}, | ||||
|     }, | ||||
|     topology::{Url, oberservability::monitoring::AlertReceiver}, | ||||
|     topology::oberservability::monitoring::AlertReceiver, | ||||
| }; | ||||
| use harmony_types::net::Url; | ||||
| 
 | ||||
| #[derive(Debug, Clone, Serialize)] | ||||
| pub struct WebhookReceiver { | ||||
|  | ||||
| @ -4,7 +4,7 @@ use async_trait::async_trait; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     modules::{ | ||||
| @ -15,6 +15,7 @@ use crate::{ | ||||
|     score::Score, | ||||
|     topology::{PreparationOutcome, Topology, oberservability::monitoring::AlertReceiver}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Debug, Clone, Serialize)] | ||||
| pub struct ApplicationMonitoringScore { | ||||
|  | ||||
| @ -6,13 +6,14 @@ use serde::Serialize; | ||||
| use strum::{Display, EnumString}; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     modules::monitoring::ntfy::helm::ntfy_helm_chart::ntfy_helm_chart_score, | ||||
|     score::Score, | ||||
|     topology::{HelmCommand, K8sclient, MultiTargetTopology, Topology, k8s::K8sClient}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Debug, Clone, Serialize)] | ||||
| pub struct NtfyScore { | ||||
|  | ||||
| @ -1,17 +1,19 @@ | ||||
| use askama::Template; | ||||
| use async_trait::async_trait; | ||||
| use derive_new::new; | ||||
| use harmony_types::net::Url; | ||||
| use serde::Serialize; | ||||
| use std::net::IpAddr; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{FileContent, FilePath, Id, Version}, | ||||
|     data::{FileContent, FilePath, Version}, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     modules::{dhcp::DhcpScore, http::StaticFilesHttpScore, tftp::TftpScore}, | ||||
|     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)] | ||||
| pub struct OkdIpxeScore { | ||||
|  | ||||
| @ -5,12 +5,13 @@ use serde::Serialize; | ||||
| use tokio::sync::RwLock; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     score::Score, | ||||
|     topology::Topology, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Debug, Clone)] | ||||
| 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::{K8sclient, Topology, k8s::K8sClient}; | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     modules::monitoring::kube_prometheus::crd::{ | ||||
| @ -37,6 +37,7 @@ use crate::{ | ||||
|     }, | ||||
|     score::Score, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| use super::prometheus::PrometheusApplicationMonitoring; | ||||
| 
 | ||||
|  | ||||
| @ -9,12 +9,13 @@ use serde::{Deserialize, Serialize}; | ||||
| use tokio::time::sleep; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     score::Score, | ||||
|     topology::{K8sclient, Topology, k8s::K8sClient}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Debug, Clone, Serialize)] | ||||
| pub struct CephRemoveOsd { | ||||
|  | ||||
| @ -3,15 +3,15 @@ use std::{sync::Arc, time::Duration}; | ||||
| use async_trait::async_trait; | ||||
| use log::debug; | ||||
| use serde::Serialize; | ||||
| use tokio::time::Instant; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     score::Score, | ||||
|     topology::{K8sclient, Topology, k8s::K8sClient}, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Clone, Debug, Serialize)] | ||||
| pub struct CephVerifyClusterHealth { | ||||
|  | ||||
| @ -5,7 +5,7 @@ use async_trait::async_trait; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     score::Score, | ||||
| @ -14,6 +14,7 @@ use crate::{ | ||||
|         tenant::{TenantConfig, TenantManager}, | ||||
|     }, | ||||
| }; | ||||
| use harmony_types::id::Id; | ||||
| 
 | ||||
| #[derive(Debug, Serialize, Clone)] | ||||
| pub struct TenantScore { | ||||
|  | ||||
| @ -3,12 +3,14 @@ use derive_new::new; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| use crate::{ | ||||
|     data::{Id, Version}, | ||||
|     data::Version, | ||||
|     interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome}, | ||||
|     inventory::Inventory, | ||||
|     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)] | ||||
| pub struct TftpScore { | ||||
|  | ||||
| @ -4,8 +4,7 @@ use crate::local_presence::SERVICE_NAME; | ||||
| 
 | ||||
| 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.
 | ||||
|     let mdns = ServiceDaemon::new().expect("Failed to create mDNS daemon"); | ||||
| 
 | ||||
|  | ||||
| @ -6,4 +6,6 @@ readme.workspace = true | ||||
| license.workspace = true | ||||
| 
 | ||||
| [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 { | ||||
|     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 mod id; | ||||
| pub mod net; | ||||
|  | ||||
							
								
								
									
										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