mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-10 18:38:22 +00:00
swap validator with garde, update deps
This commit is contained in:
parent
32e209b996
commit
7d0b9c5c3b
10 changed files with 831 additions and 475 deletions
1251
Cargo.lock
generated
1251
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -22,7 +22,7 @@ tower-http = "0.4.4"
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = "0.3.17"
|
tracing-subscriber = "0.3.17"
|
||||||
uuid = { version = "1.5.0", features = ["v4"] }
|
uuid = { version = "1.5.0", features = ["v4"] }
|
||||||
validator = { version = "0.15", features = ["derive"] }
|
|
||||||
tera = "1"
|
tera = "1"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
garde = { version = "0.20.0", features = ["full"] }
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use super::definitions::config::Config;
|
use super::definitions::config::Config;
|
||||||
|
use garde::Validate;
|
||||||
use pwhash::sha512_crypt;
|
use pwhash::sha512_crypt;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::sync::{Arc, Mutex, MutexGuard};
|
use std::sync::{Arc, Mutex, MutexGuard};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum ConfigError {
|
pub enum ConfigError {
|
||||||
|
@ -13,7 +13,7 @@ pub enum ConfigError {
|
||||||
SerdeError(#[from] serde_json::Error),
|
SerdeError(#[from] serde_json::Error),
|
||||||
|
|
||||||
#[error("Validation Error")]
|
#[error("Validation Error")]
|
||||||
ValidatonError(#[from] validator::ValidationErrors),
|
ValidatonError(#[from] garde::Report),
|
||||||
|
|
||||||
#[error("Hash Error")]
|
#[error("Hash Error")]
|
||||||
HashError(#[from] pwhash::error::Error),
|
HashError(#[from] pwhash::error::Error),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
use garde::Validate;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
use super::firewall;
|
use super::firewall;
|
||||||
use super::firewall::SNATType;
|
use super::firewall::SNATType;
|
||||||
|
@ -18,12 +18,19 @@ use crate::macro_db;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
#[garde(skip)]
|
||||||
pub config_version: u64,
|
pub config_version: u64,
|
||||||
|
#[garde(dive)]
|
||||||
pub network: network::Network,
|
pub network: network::Network,
|
||||||
|
#[garde(dive)]
|
||||||
pub object: object::Object,
|
pub object: object::Object,
|
||||||
|
#[garde(dive)]
|
||||||
pub system: system::System,
|
pub system: system::System,
|
||||||
|
#[garde(dive)]
|
||||||
pub service: service::Service,
|
pub service: service::Service,
|
||||||
|
#[garde(dive)]
|
||||||
pub vpn: vpn::VPN,
|
pub vpn: vpn::VPN,
|
||||||
|
#[garde(dive)]
|
||||||
pub firewall: firewall::Firewall,
|
pub firewall: firewall::Firewall,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
|
use garde::Validate;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
pub struct Firewall {
|
pub struct Firewall {
|
||||||
|
#[garde(dive)]
|
||||||
pub forward_rules: Vec<ForwardRule>,
|
pub forward_rules: Vec<ForwardRule>,
|
||||||
|
#[garde(dive)]
|
||||||
pub destination_nat_rules: Vec<DestinationNATRule>,
|
pub destination_nat_rules: Vec<DestinationNATRule>,
|
||||||
|
#[garde(dive)]
|
||||||
pub source_nat_rules: Vec<SourceNATRule>,
|
pub source_nat_rules: Vec<SourceNATRule>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct ForwardRule {
|
pub struct ForwardRule {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub services: Vec<String>,
|
pub services: Vec<String>,
|
||||||
|
@ -20,6 +24,7 @@ pub struct ForwardRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct DestinationNATRule {
|
pub struct DestinationNATRule {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub services: Vec<String>,
|
pub services: Vec<String>,
|
||||||
|
@ -32,6 +37,7 @@ pub struct DestinationNATRule {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct SourceNATRule {
|
pub struct SourceNATRule {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub services: Vec<String>,
|
pub services: Vec<String>,
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
|
use garde::Validate;
|
||||||
use ipnet::IpNet;
|
use ipnet::IpNet;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
pub struct Network {
|
pub struct Network {
|
||||||
|
#[garde(dive)]
|
||||||
pub interfaces: Vec<NetworkInterface>,
|
pub interfaces: Vec<NetworkInterface>,
|
||||||
|
#[garde(dive)]
|
||||||
pub static_routes: Vec<StaticRoute>,
|
pub static_routes: Vec<StaticRoute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct NetworkInterface {
|
pub struct NetworkInterface {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub alias: String,
|
pub alias: String,
|
||||||
|
@ -39,6 +42,7 @@ pub enum AddressingMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct StaticRoute {
|
pub struct StaticRoute {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
|
@ -49,6 +53,7 @@ pub struct StaticRoute {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct Link {
|
pub struct Link {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
|
use garde::Validate;
|
||||||
use ipnet::IpNet;
|
use ipnet::IpNet;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
pub struct Object {
|
pub struct Object {
|
||||||
|
#[garde(dive)]
|
||||||
pub addresses: Vec<Address>,
|
pub addresses: Vec<Address>,
|
||||||
|
#[garde(dive)]
|
||||||
pub services: Vec<Service>,
|
pub services: Vec<Service>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct Address {
|
pub struct Address {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub address_type: AddressType,
|
pub address_type: AddressType,
|
||||||
|
@ -26,6 +29,7 @@ pub enum AddressType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub service_type: ServiceType,
|
pub service_type: ServiceType,
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
|
use garde::Validate;
|
||||||
use macaddr::MacAddr8;
|
use macaddr::MacAddr8;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
pub struct Service {
|
pub struct Service {
|
||||||
|
#[garde(dive)]
|
||||||
pub dhcp_servers: Vec<DHCPServer>,
|
pub dhcp_servers: Vec<DHCPServer>,
|
||||||
|
#[garde(dive)]
|
||||||
pub dns_servers: Vec<DNSServer>,
|
pub dns_servers: Vec<DNSServer>,
|
||||||
|
#[garde(dive)]
|
||||||
pub ntp_servers: Vec<NTPServer>,
|
pub ntp_servers: Vec<NTPServer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct DHCPServer {
|
pub struct DHCPServer {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
|
@ -23,6 +27,7 @@ pub struct DHCPServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct DNSServer {
|
pub struct DNSServer {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
|
@ -30,6 +35,7 @@ pub struct DNSServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct NTPServer {
|
pub struct NTPServer {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub interface: String,
|
pub interface: String,
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
|
use garde::Validate;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
pub struct System {
|
pub struct System {
|
||||||
|
#[garde(dive)]
|
||||||
pub users: Vec<User>,
|
pub users: Vec<User>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub comment: String,
|
pub comment: String,
|
||||||
|
|
|
@ -1,18 +1,22 @@
|
||||||
|
use garde::Validate;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use validator::Validate;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
pub struct VPN {
|
pub struct VPN {
|
||||||
|
#[garde(dive)]
|
||||||
pub wireguard: Wireguard,
|
pub wireguard: Wireguard,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Default, Debug)]
|
||||||
pub struct Wireguard {
|
pub struct Wireguard {
|
||||||
|
#[garde(dive)]
|
||||||
pub interfaces: Vec<WireguardInterface>,
|
pub interfaces: Vec<WireguardInterface>,
|
||||||
|
#[garde(dive)]
|
||||||
pub peers: Vec<WireguardPeer>,
|
pub peers: Vec<WireguardPeer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct WireguardInterface {
|
pub struct WireguardInterface {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
|
@ -23,6 +27,7 @@ pub struct WireguardInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Validate, Debug)]
|
||||||
|
#[garde(allow_unvalidated)]
|
||||||
pub struct WireguardPeer {
|
pub struct WireguardPeer {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
|
|
Loading…
Add table
Reference in a new issue