osquery_rust_ng/plugin/_enums/
response.rs

1use crate::ExtensionResponse;
2use crate::_osquery::ExtensionStatus;
3use std::collections::BTreeMap;
4
5pub enum ExtensionResponseEnum {
6    Success(),
7    SuccessWithId(u64),
8    Failure(String),
9    Constraint(),
10    Readonly(),
11}
12
13impl From<ExtensionResponseEnum> for ExtensionResponse {
14    fn from(value: ExtensionResponseEnum) -> Self {
15        let mut resp = BTreeMap::<String, String>::new();
16
17        let code = match value {
18            ExtensionResponseEnum::Success() => {
19                resp.insert("status".to_string(), "success".to_string());
20                0
21            }
22            ExtensionResponseEnum::SuccessWithId(id) => {
23                resp.insert("status".to_string(), "success".to_string());
24                resp.insert("id".to_string(), id.to_string());
25                0
26            }
27            ExtensionResponseEnum::Failure(msg) => {
28                resp.insert("status".to_string(), "failure".to_string());
29                resp.insert("message".to_string(), msg.to_string());
30                1
31            }
32            ExtensionResponseEnum::Constraint() => {
33                resp.insert("status".to_string(), "constraint".to_string());
34                1
35            }
36            ExtensionResponseEnum::Readonly() => {
37                resp.insert("status".to_string(), "readonly".to_string());
38                1
39            }
40        };
41
42        ExtensionResponse::new(ExtensionStatus::new(code, None, None), vec![resp])
43    }
44}