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