files_sdk/advanced/
siem_http_destinations.rs

1//! SIEM HTTP destination configuration
2
3use crate::{FilesClient, PaginationInfo, Result};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Serialize, Deserialize, Clone)]
7pub struct SiemHttpDestinationEntity {
8    pub id: Option<i64>,
9    #[serde(flatten)]
10    pub data: serde_json::Map<String, serde_json::Value>,
11}
12
13#[derive(Debug, Clone)]
14pub struct SiemHttpDestinationHandler {
15    client: FilesClient,
16}
17
18impl SiemHttpDestinationHandler {
19    pub fn new(client: FilesClient) -> Self {
20        Self { client }
21    }
22
23    pub async fn list(
24        &self,
25        cursor: Option<String>,
26        per_page: Option<i64>,
27    ) -> Result<(Vec<SiemHttpDestinationEntity>, PaginationInfo)> {
28        let mut endpoint = "/siem_http_destinations".to_string();
29        let mut params = Vec::new();
30        if let Some(c) = cursor {
31            params.push(format!("cursor={}", c));
32        }
33        if let Some(pp) = per_page {
34            params.push(format!("per_page={}", pp));
35        }
36        if !params.is_empty() {
37            endpoint.push('?');
38            endpoint.push_str(&params.join("&"));
39        }
40
41        let url = format!("{}{}", self.client.inner.base_url, endpoint);
42        let response = reqwest::Client::new()
43            .get(&url)
44            .header("X-FilesAPI-Key", &self.client.inner.api_key)
45            .send()
46            .await?;
47
48        let headers = response.headers().clone();
49        let pagination = PaginationInfo::from_headers(&headers);
50        let status = response.status();
51        if !status.is_success() {
52            return Err(crate::FilesError::ApiError {
53                code: status.as_u16(),
54                message: response.text().await.unwrap_or_default(),
55            });
56        }
57        let items: Vec<SiemHttpDestinationEntity> = response.json().await?;
58        Ok((items, pagination))
59    }
60
61    pub async fn get(&self, id: i64) -> Result<SiemHttpDestinationEntity> {
62        let endpoint = format!("/siem_http_destinations/{}", id);
63        let response = self.client.get_raw(&endpoint).await?;
64        Ok(serde_json::from_value(response)?)
65    }
66
67    pub async fn create(&self, params: serde_json::Value) -> Result<SiemHttpDestinationEntity> {
68        let response = self
69            .client
70            .post_raw("/siem_http_destinations", params)
71            .await?;
72        Ok(serde_json::from_value(response)?)
73    }
74
75    pub async fn update(
76        &self,
77        id: i64,
78        params: serde_json::Value,
79    ) -> Result<SiemHttpDestinationEntity> {
80        let endpoint = format!("/siem_http_destinations/{}", id);
81        let response = self.client.patch_raw(&endpoint, params).await?;
82        Ok(serde_json::from_value(response)?)
83    }
84
85    pub async fn delete(&self, id: i64) -> Result<()> {
86        let endpoint = format!("/siem_http_destinations/{}", id);
87        self.client.delete_raw(&endpoint).await?;
88        Ok(())
89    }
90}
91
92#[cfg(test)]
93mod tests {
94    use super::*;
95    #[test]
96    fn test_handler_creation() {
97        let client = FilesClient::builder().api_key("test-key").build().unwrap();
98        let _handler = SiemHttpDestinationHandler::new(client);
99    }
100}