Skip to content

Commit a3a8333

Browse files
Fix posture checks on windows (#898)
* make sure all posture checks on windows are prepared by the daemon * fix os_version reporting on windows * fix windows os_version - take 2
1 parent b5fa454 commit a3a8333

3 files changed

Lines changed: 36 additions & 20 deletions

File tree

src-tauri/src/commands.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::{
3030
DB_POOL,
3131
},
3232
enterprise::{
33-
periodic::config::poll_instance, posture::authorize_posture_session,
33+
self, periodic::config::poll_instance, posture::authorize_posture_session,
3434
provisioning::ProvisioningConfig,
3535
},
3636
error::Error,
@@ -1577,25 +1577,9 @@ pub fn get_platform_header() -> String {
15771577
}
15781578

15791579
#[tauri::command(async)]
1580-
#[cfg(not(windows))]
15811580
pub async fn get_posture_data() -> Result<DevicePostureData, Error> {
15821581
debug!("Received a command to prepare posture report");
1583-
Ok(DevicePostureData::new())
1584-
}
1585-
1586-
#[tauri::command(async)]
1587-
#[cfg(windows)]
1588-
pub async fn get_posture_data() -> Result<DevicePostureData, Error> {
1589-
debug!("Received a command to prepare posture report");
1590-
DAEMON_CLIENT
1591-
.clone()
1592-
.get_posture_data(tonic::Request::new(()))
1593-
.await
1594-
.map(|response| response.into_inner())
1595-
.map_err(|err| {
1596-
error!("Failed to get posture data from the daemon: {err}");
1597-
Error::InternalError(format!("Failed to get posture data from the daemon: {err}"))
1598-
})
1582+
enterprise::posture::get_posture_data().await
15991583
}
16001584

16011585
#[derive(Debug, Serialize)]

src-tauri/src/enterprise/inspector/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@ fn os_name() -> Result<String, UnavailableReason> {
3939

4040
/// Returns the operating system version.
4141
fn os_version() -> Result<String, UnavailableReason> {
42-
System::os_version().ok_or(UnavailableReason::DetectionFailed)
42+
#[cfg(windows)]
43+
{
44+
// Windows can report versions like "11 (26200)"; core expects a parseable major.
45+
System::os_version()
46+
.and_then(|version| version.split_whitespace().next().map(ToString::to_string))
47+
.ok_or(UnavailableReason::DetectionFailed)
48+
}
49+
50+
#[cfg(not(windows))]
51+
{
52+
System::os_version().ok_or(UnavailableReason::DetectionFailed)
53+
}
4354
}
4455

4556
/// Returns the Linux kernel version.

src-tauri/src/enterprise/posture.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use reqwest::StatusCode;
22
use serde::Deserialize;
33

4+
#[cfg(windows)]
5+
use crate::service::client::DAEMON_CLIENT;
46
use crate::{
57
database::{
68
models::{instance::Instance, location::Location, wireguard_keys::WireguardKeys, Id},
@@ -30,7 +32,7 @@ pub async fn authorize_posture_session(location: &Location<Id>) -> Result<String
3032
))
3133
})?;
3234

33-
let posture_data = DevicePostureData::new();
35+
let posture_data = get_posture_data().await?;
3436

3537
let request = DevicePostureCheckRequest {
3638
location_id: location.network_id,
@@ -77,3 +79,22 @@ pub async fn authorize_posture_session(location: &Location<Id>) -> Result<String
7779
))),
7880
}
7981
}
82+
83+
pub async fn get_posture_data() -> Result<DevicePostureData, Error> {
84+
#[cfg(windows)]
85+
{
86+
DAEMON_CLIENT
87+
.clone()
88+
.get_posture_data(tonic::Request::new(()))
89+
.await
90+
.map(|response| response.into_inner())
91+
.map_err(|err| {
92+
error!("Failed to get posture data from the daemon: {err}");
93+
Error::InternalError(format!("Failed to get posture data from the daemon: {err}"))
94+
})
95+
}
96+
#[cfg(not(windows))]
97+
{
98+
Ok(DevicePostureData::new())
99+
}
100+
}

0 commit comments

Comments
 (0)