feat: schedule nonblocking Windows HIP patch checks

This commit is contained in:
Kevin Yue committed 2026-11-18 13:56:12 +08:00
1 parent bde11186f8
commit 5e7e343def
13 files changed
+318 -19

No files matched your search

+15
View File
@@ -45,3 +45,18 @@ mod tests {
assert_eq!(serde_json::from_value::<HipSource>(json).unwrap(), source);
}
}
/// Collection metadata for the exact XML returned by a generated preview.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Type)]
#[serde(rename_all = "camelCase")]
pub struct HipReport {
pub xml: String,
pub windows_updates: Option<WindowsUpdateStatus>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, Type)]
#[serde(rename_all = "camelCase")]
pub struct WindowsUpdateStatus {
/// Present only when this report includes a completed local patch observation.
pub checked_at: Option<u64>,
}
+2
View File
@@ -424,6 +424,8 @@ pub struct UpdateLogLevelRequest(pub String);
#[derive(Debug, Deserialize, Serialize)]
pub enum WsRequest {
SetTunnelStatisticsEnabled { enabled: bool },
SetWindowsPatchInterest { enabled: bool },
RefreshWindowsPatches { after: Option<u64> },
Connect(Box<ConnectRequest>),
Disconnect(DisconnectRequest),
StopNonTunnelAttachment { connection_id: uuid::Uuid },
@@ -55,6 +55,8 @@ pub enum ServiceResult {
offset: usize,
xml: String,
complete: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
windows_updates: Option<crate::hip::WindowsUpdateStatus>,
},
HipApprovalStatus(HipApprovalStatus),
NoSubmittedHipReport,
+17 -3
View File
@@ -275,10 +275,18 @@ pub fn generate_identity_report(input: &ReportInput) -> anyhow::Result<String> {
}
pub fn generate_report_with_control(input: &ReportInput, control: &dyn CollectionControl) -> anyhow::Result<String> {
Ok(generate_report_details(input, control)?.xml)
}
pub fn generate_report_details(
input: &ReportInput,
control: &dyn CollectionControl,
) -> anyhow::Result<gpapi::hip::HipReport> {
control.check()?;
let cookie_params = cookie_params(input);
let (generate_time, day, month, year) = get_current_time_components();
let host_info = HostInfoCollector::new(&input.profile, input, &cookie_params).collect(control)?;
let windows_updates = host_info.windows_updates.clone();
let template = HipReportTemplate {
client_version: input.profile.client_version(),
generate_time,
@@ -289,9 +297,9 @@ pub fn generate_report_with_control(input: &ReportInput, control: &dyn Collectio
host_info,
md5: input.context.md5(),
};
let report = format_xml(&template.render()?)?;
let xml = format_xml(&template.render()?)?;
control.check()?;
Ok(report)
Ok(gpapi::hip::HipReport { xml, windows_updates })
}
fn cookie_params(input: &ReportInput) -> HashMap<String, String> {
@@ -373,6 +381,7 @@ struct HostInfo {
sentinel: Option<SentinelInfo>,
ufw: Option<UfwInfo>,
windows_categories: Option<String>,
windows_updates: Option<gpapi::hip::WindowsUpdateStatus>,
}
impl HostInfo {
@@ -497,6 +506,7 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> {
sentinel: None,
ufw: None,
windows_categories: None,
windows_updates: None,
})
}
@@ -558,7 +568,11 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> {
let commands = CollectorCommands::new(control);
#[cfg(windows)]
if self.profile.client_os() == ClientOs::Windows && self.profile.is_native() {
info.windows_categories = Some(windows::collect(&commands, control)?.render()?);
let report = windows::collect(&commands, control)?;
info.windows_updates = Some(gpapi::hip::WindowsUpdateStatus {
checked_at: report.patches_checked_at,
});
info.windows_categories = Some(report.render()?);
}
if self.profile.client_os() == ClientOs::Linux && self.profile.is_native() {
+1
View File
@@ -11,6 +11,7 @@ pub(super) struct WindowsReport {
pub firewall: Vec<ProductState>,
pub patch_management: Vec<ProductState>,
pub missing_patches: Option<Vec<MissingPatch>>,
pub patches_checked_at: Option<u64>,
pub unavailable: Vec<String>,
}