regent_sdk/state/attribute/utilities/
debug.rs1use crate::error::RegentError;
2use crate::hosts::managed_host::InternalApiCallOutcome;
3use crate::hosts::managed_host::{AssessCompliance, ReachCompliance};
4use crate::hosts::properties::HostProperties;
5use crate::secrets::SecretProvidersPool;
6use crate::state::Check;
7use crate::state::attribute::HostHandler;
8use crate::state::attribute::Privilege;
9use crate::state::attribute::Remediation;
10use crate::state::compliance::AttributeComplianceAssessment;
11use serde::{Deserialize, Serialize};
12
13#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14#[serde(deny_unknown_fields)]
15#[serde(rename_all = "PascalCase")]
16pub struct DebugBlockExpectedState {
17 msg: String,
18 }
20
21impl Check for DebugBlockExpectedState {
22 fn check(&self) -> Result<(), RegentError> {
23 Ok(())
24 }
25}
26
27impl<Handler: HostHandler> AssessCompliance<Handler> for DebugBlockExpectedState {
28 async fn assess_compliance(
29 &self,
30 _host_handler: &mut Handler,
31 _host_properties: &Option<HostProperties>,
32 _privilege: &Privilege,
33 _optional_secret_provider: &Option<SecretProvidersPool>,
34 ) -> Result<AttributeComplianceAssessment, RegentError> {
35 return Ok(AttributeComplianceAssessment::NonCompliant(Vec::from([
36 Remediation::None(self.msg.clone()),
37 ])));
38 }
39}
40
41#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
42pub struct DebugApiCall {}
43
44impl DebugApiCall {
45 pub fn display(&self) -> String {
46 "Debug module".into()
47 }
48}
49
50impl<Handler: HostHandler> ReachCompliance<Handler> for DebugApiCall {
51 async fn call(
52 &self,
53 _host_handler: &mut Handler,
54 _host_properties: &Option<HostProperties>,
55 _optional_secret_provider: &Option<SecretProvidersPool>,
56 ) -> Result<InternalApiCallOutcome, RegentError> {
57 Ok(InternalApiCallOutcome::Success(None))
58 }
59}
60
61#[cfg(test)]
62mod tests {
63
64 use super::*;
65
66 #[test]
67 fn parsing_debug_module_block_from_yaml_str() {
68 let attribute = "---
69Msg: some content
70 ";
71
72 let attribute: DebugBlockExpectedState = yaml_serde::from_str(attribute).unwrap();
73
74 assert_eq!(attribute.msg, "some content".to_string());
75 }
76}