use serde::{Deserialize, Serialize};
use utoipa::{IntoParams, ToSchema};
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ScanRequest {
#[schema(example = "example.com:443")]
pub target: String,
#[serde(default)]
pub options: ScanOptions,
#[serde(skip_serializing_if = "Option::is_none")]
pub webhook_url: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, ToSchema)]
pub struct ScanOptions {
#[serde(default)]
pub test_protocols: bool,
#[serde(default)]
pub test_ciphers: bool,
#[serde(default)]
pub test_vulnerabilities: bool,
#[serde(default)]
pub analyze_certificates: bool,
#[serde(default)]
pub test_http_headers: bool,
#[serde(default)]
pub client_simulation: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub starttls_protocol: Option<String>,
#[serde(default = "default_timeout")]
pub timeout_seconds: u64,
#[serde(default)]
pub ipv4_only: bool,
#[serde(default)]
pub ipv6_only: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub ip: Option<String>,
#[serde(default)]
pub full_scan: bool,
}
fn default_timeout() -> u64 {
30
}
impl ScanOptions {
pub fn full() -> Self {
Self {
test_protocols: true,
test_ciphers: true,
test_vulnerabilities: true,
analyze_certificates: true,
test_http_headers: true,
client_simulation: true,
full_scan: true,
..Default::default()
}
}
pub fn quick() -> Self {
Self {
test_protocols: true,
test_ciphers: false,
test_vulnerabilities: false,
analyze_certificates: true,
test_http_headers: false,
client_simulation: false,
..Default::default()
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct PolicyRequest {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub rules: String,
#[serde(default = "default_true")]
pub enabled: bool,
}
fn default_true() -> bool {
true
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct PolicyEvaluationRequest {
pub target: String,
#[serde(default)]
pub options: ScanOptions,
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
pub struct CertificateQuery {
#[serde(default = "default_limit")]
pub limit: usize,
#[serde(default)]
pub offset: usize,
#[serde(default = "default_sort")]
pub sort: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub hostname: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub expiring_within_days: Option<u32>,
}
fn default_limit() -> usize {
50
}
fn default_sort() -> String {
"expiry_asc".to_string()
}
impl Default for CertificateQuery {
fn default() -> Self {
Self {
limit: default_limit(),
offset: 0,
sort: default_sort(),
hostname: None,
expiring_within_days: None,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
pub struct ComplianceCheckRequest {
pub target: String,
pub framework: String,
#[serde(default)]
pub detailed: bool,
}