use sdforge::validator::Validate;
use serde::{Deserialize, Serialize};
fn validate_cidr_list(ips: &[String]) -> Result<(), sdforge::validator::ValidationError> {
for ip in ips {
if ip.parse::<std::net::IpAddr>().is_err() && ipnetwork::IpNetwork::from_str(ip).is_err() {
return Err(sdforge::validator::ValidationError::new("invalid_cidr")
.with_message(format!("Invalid IP or CIDR notation: {}", ip).into()));
}
}
Ok(())
}
use std::str::FromStr;
#[derive(Debug, Clone, Deserialize, Serialize, Validate)]
#[validate(crate = "sdforge::validator")]
#[serde(deny_unknown_fields)]
pub struct UpdateTeamGeoRestrictionsRequest {
pub enable_geo_restrictions: bool,
#[validate(length(min = 1, message = "Country code list cannot be empty"))]
pub allowed_countries: Option<Vec<String>>,
#[validate(length(min = 1, message = "Country code list cannot be empty"))]
pub blocked_countries: Option<Vec<String>>,
#[validate(custom(function = "validate_cidr_list"))]
pub ip_whitelist: Option<Vec<String>>,
pub domain_blacklist: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize)]
pub struct TeamGeoRestrictionsResponse {
pub team_id: crate::domain::id::Id,
pub enable_geo_restrictions: bool,
pub allowed_countries: Option<Vec<String>>,
pub blocked_countries: Option<Vec<String>>,
pub ip_whitelist: Option<Vec<String>>,
pub domain_blacklist: Option<Vec<String>>,
}