use crate::datadog;
use async_stream::try_stream;
use flate2::{
write::{GzEncoder, ZlibEncoder},
Compression,
};
use futures_core::stream::Stream;
use log::warn;
use reqwest::header::{HeaderMap, HeaderValue};
use serde::{Deserialize, Serialize};
use std::io::Write;
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetFindingOptionalParams {
pub snapshot_timestamp: Option<i64>,
}
impl GetFindingOptionalParams {
pub fn snapshot_timestamp(mut self, value: i64) -> Self {
self.snapshot_timestamp = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListFindingsOptionalParams {
pub page_limit: Option<i64>,
pub snapshot_timestamp: Option<i64>,
pub page_cursor: Option<String>,
pub filter_tags: Option<String>,
pub filter_evaluation_changed_at: Option<String>,
pub filter_muted: Option<bool>,
pub filter_rule_id: Option<String>,
pub filter_rule_name: Option<String>,
pub filter_resource_type: Option<String>,
pub filter_discovery_timestamp: Option<String>,
pub filter_evaluation: Option<crate::datadogV2::model::FindingEvaluation>,
pub filter_status: Option<crate::datadogV2::model::FindingStatus>,
}
impl ListFindingsOptionalParams {
pub fn page_limit(mut self, value: i64) -> Self {
self.page_limit = Some(value);
self
}
pub fn snapshot_timestamp(mut self, value: i64) -> Self {
self.snapshot_timestamp = Some(value);
self
}
pub fn page_cursor(mut self, value: String) -> Self {
self.page_cursor = Some(value);
self
}
pub fn filter_tags(mut self, value: String) -> Self {
self.filter_tags = Some(value);
self
}
pub fn filter_evaluation_changed_at(mut self, value: String) -> Self {
self.filter_evaluation_changed_at = Some(value);
self
}
pub fn filter_muted(mut self, value: bool) -> Self {
self.filter_muted = Some(value);
self
}
pub fn filter_rule_id(mut self, value: String) -> Self {
self.filter_rule_id = Some(value);
self
}
pub fn filter_rule_name(mut self, value: String) -> Self {
self.filter_rule_name = Some(value);
self
}
pub fn filter_resource_type(mut self, value: String) -> Self {
self.filter_resource_type = Some(value);
self
}
pub fn filter_discovery_timestamp(mut self, value: String) -> Self {
self.filter_discovery_timestamp = Some(value);
self
}
pub fn filter_evaluation(mut self, value: crate::datadogV2::model::FindingEvaluation) -> Self {
self.filter_evaluation = Some(value);
self
}
pub fn filter_status(mut self, value: crate::datadogV2::model::FindingStatus) -> Self {
self.filter_status = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListSecurityMonitoringRulesOptionalParams {
pub page_size: Option<i64>,
pub page_number: Option<i64>,
}
impl ListSecurityMonitoringRulesOptionalParams {
pub fn page_size(mut self, value: i64) -> Self {
self.page_size = Some(value);
self
}
pub fn page_number(mut self, value: i64) -> Self {
self.page_number = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListSecurityMonitoringSignalsOptionalParams {
pub filter_query: Option<String>,
pub filter_from: Option<chrono::DateTime<chrono::Utc>>,
pub filter_to: Option<chrono::DateTime<chrono::Utc>>,
pub sort: Option<crate::datadogV2::model::SecurityMonitoringSignalsSort>,
pub page_cursor: Option<String>,
pub page_limit: Option<i32>,
}
impl ListSecurityMonitoringSignalsOptionalParams {
pub fn filter_query(mut self, value: String) -> Self {
self.filter_query = Some(value);
self
}
pub fn filter_from(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.filter_from = Some(value);
self
}
pub fn filter_to(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.filter_to = Some(value);
self
}
pub fn sort(mut self, value: crate::datadogV2::model::SecurityMonitoringSignalsSort) -> Self {
self.sort = Some(value);
self
}
pub fn page_cursor(mut self, value: String) -> Self {
self.page_cursor = Some(value);
self
}
pub fn page_limit(mut self, value: i32) -> Self {
self.page_limit = Some(value);
self
}
}
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct SearchSecurityMonitoringSignalsOptionalParams {
pub body: Option<crate::datadogV2::model::SecurityMonitoringSignalListRequest>,
}
impl SearchSecurityMonitoringSignalsOptionalParams {
pub fn body(
mut self,
value: crate::datadogV2::model::SecurityMonitoringSignalListRequest,
) -> Self {
self.body = Some(value);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConvertExistingSecurityMonitoringRuleError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ConvertSecurityMonitoringRuleFromJSONToTerraformError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateSecurityFilterError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateSecurityMonitoringRuleError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateSecurityMonitoringSuppressionError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSecurityFilterError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSecurityMonitoringRuleError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSecurityMonitoringSuppressionError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EditSecurityMonitoringSignalAssigneeError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EditSecurityMonitoringSignalIncidentsError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EditSecurityMonitoringSignalStateError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetFindingError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSecurityFilterError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSecurityMonitoringRuleError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSecurityMonitoringSignalError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSecurityMonitoringSuppressionError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListFindingsError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSecurityFiltersError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSecurityMonitoringRulesError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSecurityMonitoringSignalsError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSecurityMonitoringSuppressionsError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum MuteFindingsError {
JSONAPIErrorResponse(crate::datadogV2::model::JSONAPIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchSecurityMonitoringSignalsError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TestExistingSecurityMonitoringRuleError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TestSecurityMonitoringRuleError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateSecurityFilterError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateSecurityMonitoringRuleError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateSecurityMonitoringSuppressionError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ValidateSecurityMonitoringRuleError {
APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone)]
pub struct SecurityMonitoringAPI {
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
}
impl Default for SecurityMonitoringAPI {
fn default() -> Self {
Self::with_config(datadog::Configuration::default())
}
}
impl SecurityMonitoringAPI {
pub fn new() -> Self {
Self::default()
}
pub fn with_config(config: datadog::Configuration) -> Self {
let mut reqwest_client_builder = reqwest::Client::builder();
if let Some(proxy_url) = &config.proxy_url {
let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}
let mut middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
if config.enable_retry {
struct RetryableStatus;
impl reqwest_retry::RetryableStrategy for RetryableStatus {
fn handle(
&self,
res: &Result<reqwest::Response, reqwest_middleware::Error>,
) -> Option<reqwest_retry::Retryable> {
match res {
Ok(success) => reqwest_retry::default_on_request_success(success),
Err(_) => None,
}
}
}
let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
.build_with_max_retries(config.max_retries);
let retry_middleware =
reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
backoff_policy,
RetryableStatus,
);
middleware_client_builder = middleware_client_builder.with(retry_middleware);
}
let client = middleware_client_builder.build();
Self { config, client }
}
pub fn with_client_and_config(
config: datadog::Configuration,
client: reqwest_middleware::ClientWithMiddleware,
) -> Self {
Self { config, client }
}
pub async fn convert_existing_security_monitoring_rule(
&self,
rule_id: String,
) -> Result<
crate::datadogV2::model::SecurityMonitoringRuleConvertResponse,
datadog::Error<ConvertExistingSecurityMonitoringRuleError>,
> {
match self
.convert_existing_security_monitoring_rule_with_http_info(rule_id)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn convert_existing_security_monitoring_rule_with_http_info(
&self,
rule_id: String,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringRuleConvertResponse>,
datadog::Error<ConvertExistingSecurityMonitoringRuleError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.convert_existing_security_monitoring_rule";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/rules/{rule_id}/convert",
local_configuration.get_operation_host(operation_id),
rule_id = datadog::urlencode(rule_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringRuleConvertResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ConvertExistingSecurityMonitoringRuleError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn convert_security_monitoring_rule_from_json_to_terraform(
&self,
body: crate::datadogV2::model::SecurityMonitoringRuleConvertPayload,
) -> Result<
crate::datadogV2::model::SecurityMonitoringRuleConvertResponse,
datadog::Error<ConvertSecurityMonitoringRuleFromJSONToTerraformError>,
> {
match self
.convert_security_monitoring_rule_from_json_to_terraform_with_http_info(body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn convert_security_monitoring_rule_from_json_to_terraform_with_http_info(
&self,
body: crate::datadogV2::model::SecurityMonitoringRuleConvertPayload,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringRuleConvertResponse>,
datadog::Error<ConvertSecurityMonitoringRuleFromJSONToTerraformError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.convert_security_monitoring_rule_from_json_to_terraform";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/rules/convert",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringRuleConvertResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ConvertSecurityMonitoringRuleFromJSONToTerraformError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn create_security_filter(
&self,
body: crate::datadogV2::model::SecurityFilterCreateRequest,
) -> Result<
crate::datadogV2::model::SecurityFilterResponse,
datadog::Error<CreateSecurityFilterError>,
> {
match self.create_security_filter_with_http_info(body).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn create_security_filter_with_http_info(
&self,
body: crate::datadogV2::model::SecurityFilterCreateRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityFilterResponse>,
datadog::Error<CreateSecurityFilterError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.create_security_filter";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/configuration/security_filters",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityFilterResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<CreateSecurityFilterError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn create_security_monitoring_rule(
&self,
body: crate::datadogV2::model::SecurityMonitoringRuleCreatePayload,
) -> Result<
crate::datadogV2::model::SecurityMonitoringRuleResponse,
datadog::Error<CreateSecurityMonitoringRuleError>,
> {
match self
.create_security_monitoring_rule_with_http_info(body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn create_security_monitoring_rule_with_http_info(
&self,
body: crate::datadogV2::model::SecurityMonitoringRuleCreatePayload,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringRuleResponse>,
datadog::Error<CreateSecurityMonitoringRuleError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.create_security_monitoring_rule";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/rules",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityMonitoringRuleResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<CreateSecurityMonitoringRuleError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn create_security_monitoring_suppression(
&self,
body: crate::datadogV2::model::SecurityMonitoringSuppressionCreateRequest,
) -> Result<
crate::datadogV2::model::SecurityMonitoringSuppressionResponse,
datadog::Error<CreateSecurityMonitoringSuppressionError>,
> {
match self
.create_security_monitoring_suppression_with_http_info(body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn create_security_monitoring_suppression_with_http_info(
&self,
body: crate::datadogV2::model::SecurityMonitoringSuppressionCreateRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringSuppressionResponse>,
datadog::Error<CreateSecurityMonitoringSuppressionError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.create_security_monitoring_suppression";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/configuration/suppressions",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringSuppressionResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<CreateSecurityMonitoringSuppressionError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn delete_security_filter(
&self,
security_filter_id: String,
) -> Result<(), datadog::Error<DeleteSecurityFilterError>> {
match self
.delete_security_filter_with_http_info(security_filter_id)
.await
{
Ok(_) => Ok(()),
Err(err) => Err(err),
}
}
pub async fn delete_security_filter_with_http_info(
&self,
security_filter_id: String,
) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteSecurityFilterError>> {
let local_configuration = &self.config;
let operation_id = "v2.delete_security_filter";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/configuration/security_filters/{security_filter_id}",
local_configuration.get_operation_host(operation_id),
security_filter_id = datadog::urlencode(security_filter_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("*/*"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: None,
})
} else {
let local_entity: Option<DeleteSecurityFilterError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn delete_security_monitoring_rule(
&self,
rule_id: String,
) -> Result<(), datadog::Error<DeleteSecurityMonitoringRuleError>> {
match self
.delete_security_monitoring_rule_with_http_info(rule_id)
.await
{
Ok(_) => Ok(()),
Err(err) => Err(err),
}
}
pub async fn delete_security_monitoring_rule_with_http_info(
&self,
rule_id: String,
) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteSecurityMonitoringRuleError>>
{
let local_configuration = &self.config;
let operation_id = "v2.delete_security_monitoring_rule";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/rules/{rule_id}",
local_configuration.get_operation_host(operation_id),
rule_id = datadog::urlencode(rule_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("*/*"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: None,
})
} else {
let local_entity: Option<DeleteSecurityMonitoringRuleError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn delete_security_monitoring_suppression(
&self,
suppression_id: String,
) -> Result<(), datadog::Error<DeleteSecurityMonitoringSuppressionError>> {
match self
.delete_security_monitoring_suppression_with_http_info(suppression_id)
.await
{
Ok(_) => Ok(()),
Err(err) => Err(err),
}
}
pub async fn delete_security_monitoring_suppression_with_http_info(
&self,
suppression_id: String,
) -> Result<
datadog::ResponseContent<()>,
datadog::Error<DeleteSecurityMonitoringSuppressionError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.delete_security_monitoring_suppression";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/configuration/suppressions/{suppression_id}",
local_configuration.get_operation_host(operation_id),
suppression_id = datadog::urlencode(suppression_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("*/*"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: None,
})
} else {
let local_entity: Option<DeleteSecurityMonitoringSuppressionError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn edit_security_monitoring_signal_assignee(
&self,
signal_id: String,
body: crate::datadogV2::model::SecurityMonitoringSignalAssigneeUpdateRequest,
) -> Result<
crate::datadogV2::model::SecurityMonitoringSignalTriageUpdateResponse,
datadog::Error<EditSecurityMonitoringSignalAssigneeError>,
> {
match self
.edit_security_monitoring_signal_assignee_with_http_info(signal_id, body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn edit_security_monitoring_signal_assignee_with_http_info(
&self,
signal_id: String,
body: crate::datadogV2::model::SecurityMonitoringSignalAssigneeUpdateRequest,
) -> Result<
datadog::ResponseContent<
crate::datadogV2::model::SecurityMonitoringSignalTriageUpdateResponse,
>,
datadog::Error<EditSecurityMonitoringSignalAssigneeError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.edit_security_monitoring_signal_assignee";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/signals/{signal_id}/assignee",
local_configuration.get_operation_host(operation_id),
signal_id = datadog::urlencode(signal_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringSignalTriageUpdateResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<EditSecurityMonitoringSignalAssigneeError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn edit_security_monitoring_signal_incidents(
&self,
signal_id: String,
body: crate::datadogV2::model::SecurityMonitoringSignalIncidentsUpdateRequest,
) -> Result<
crate::datadogV2::model::SecurityMonitoringSignalTriageUpdateResponse,
datadog::Error<EditSecurityMonitoringSignalIncidentsError>,
> {
match self
.edit_security_monitoring_signal_incidents_with_http_info(signal_id, body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn edit_security_monitoring_signal_incidents_with_http_info(
&self,
signal_id: String,
body: crate::datadogV2::model::SecurityMonitoringSignalIncidentsUpdateRequest,
) -> Result<
datadog::ResponseContent<
crate::datadogV2::model::SecurityMonitoringSignalTriageUpdateResponse,
>,
datadog::Error<EditSecurityMonitoringSignalIncidentsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.edit_security_monitoring_signal_incidents";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/signals/{signal_id}/incidents",
local_configuration.get_operation_host(operation_id),
signal_id = datadog::urlencode(signal_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringSignalTriageUpdateResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<EditSecurityMonitoringSignalIncidentsError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn edit_security_monitoring_signal_state(
&self,
signal_id: String,
body: crate::datadogV2::model::SecurityMonitoringSignalStateUpdateRequest,
) -> Result<
crate::datadogV2::model::SecurityMonitoringSignalTriageUpdateResponse,
datadog::Error<EditSecurityMonitoringSignalStateError>,
> {
match self
.edit_security_monitoring_signal_state_with_http_info(signal_id, body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn edit_security_monitoring_signal_state_with_http_info(
&self,
signal_id: String,
body: crate::datadogV2::model::SecurityMonitoringSignalStateUpdateRequest,
) -> Result<
datadog::ResponseContent<
crate::datadogV2::model::SecurityMonitoringSignalTriageUpdateResponse,
>,
datadog::Error<EditSecurityMonitoringSignalStateError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.edit_security_monitoring_signal_state";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/signals/{signal_id}/state",
local_configuration.get_operation_host(operation_id),
signal_id = datadog::urlencode(signal_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringSignalTriageUpdateResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<EditSecurityMonitoringSignalStateError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn get_finding(
&self,
finding_id: String,
params: GetFindingOptionalParams,
) -> Result<crate::datadogV2::model::GetFindingResponse, datadog::Error<GetFindingError>> {
match self.get_finding_with_http_info(finding_id, params).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn get_finding_with_http_info(
&self,
finding_id: String,
params: GetFindingOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::GetFindingResponse>,
datadog::Error<GetFindingError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_finding";
if local_configuration.is_unstable_operation_enabled(operation_id) {
warn!("Using unstable operation {operation_id}");
} else {
let local_error = datadog::UnstableOperationDisabledError {
msg: "Operation 'v2.get_finding' is not enabled".to_string(),
};
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
}
let snapshot_timestamp = params.snapshot_timestamp;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/posture_management/findings/{finding_id}",
local_configuration.get_operation_host(operation_id),
finding_id = datadog::urlencode(finding_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
if let Some(ref local_query_param) = snapshot_timestamp {
local_req_builder =
local_req_builder.query(&[("snapshot_timestamp", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::GetFindingResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<GetFindingError> = serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn get_security_filter(
&self,
security_filter_id: String,
) -> Result<
crate::datadogV2::model::SecurityFilterResponse,
datadog::Error<GetSecurityFilterError>,
> {
match self
.get_security_filter_with_http_info(security_filter_id)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn get_security_filter_with_http_info(
&self,
security_filter_id: String,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityFilterResponse>,
datadog::Error<GetSecurityFilterError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_security_filter";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/configuration/security_filters/{security_filter_id}",
local_configuration.get_operation_host(operation_id),
security_filter_id = datadog::urlencode(security_filter_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityFilterResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<GetSecurityFilterError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn get_security_monitoring_rule(
&self,
rule_id: String,
) -> Result<
crate::datadogV2::model::SecurityMonitoringRuleResponse,
datadog::Error<GetSecurityMonitoringRuleError>,
> {
match self
.get_security_monitoring_rule_with_http_info(rule_id)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn get_security_monitoring_rule_with_http_info(
&self,
rule_id: String,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringRuleResponse>,
datadog::Error<GetSecurityMonitoringRuleError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_security_monitoring_rule";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/rules/{rule_id}",
local_configuration.get_operation_host(operation_id),
rule_id = datadog::urlencode(rule_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityMonitoringRuleResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<GetSecurityMonitoringRuleError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn get_security_monitoring_signal(
&self,
signal_id: String,
) -> Result<
crate::datadogV2::model::SecurityMonitoringSignalResponse,
datadog::Error<GetSecurityMonitoringSignalError>,
> {
match self
.get_security_monitoring_signal_with_http_info(signal_id)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn get_security_monitoring_signal_with_http_info(
&self,
signal_id: String,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringSignalResponse>,
datadog::Error<GetSecurityMonitoringSignalError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_security_monitoring_signal";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/signals/{signal_id}",
local_configuration.get_operation_host(operation_id),
signal_id = datadog::urlencode(signal_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityMonitoringSignalResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<GetSecurityMonitoringSignalError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn get_security_monitoring_suppression(
&self,
suppression_id: String,
) -> Result<
crate::datadogV2::model::SecurityMonitoringSuppressionResponse,
datadog::Error<GetSecurityMonitoringSuppressionError>,
> {
match self
.get_security_monitoring_suppression_with_http_info(suppression_id)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn get_security_monitoring_suppression_with_http_info(
&self,
suppression_id: String,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringSuppressionResponse>,
datadog::Error<GetSecurityMonitoringSuppressionError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.get_security_monitoring_suppression";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/configuration/suppressions/{suppression_id}",
local_configuration.get_operation_host(operation_id),
suppression_id = datadog::urlencode(suppression_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringSuppressionResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<GetSecurityMonitoringSuppressionError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn list_findings(
&self,
params: ListFindingsOptionalParams,
) -> Result<crate::datadogV2::model::ListFindingsResponse, datadog::Error<ListFindingsError>>
{
match self.list_findings_with_http_info(params).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub fn list_findings_with_pagination(
&self,
mut params: ListFindingsOptionalParams,
) -> impl Stream<
Item = Result<crate::datadogV2::model::Finding, datadog::Error<ListFindingsError>>,
> + '_ {
try_stream! {
let mut page_size: i64 = 100;
if params.page_limit.is_none() {
params.page_limit = Some(page_size);
} else {
page_size = params.page_limit.unwrap().clone();
}
loop {
let resp = self.list_findings(params.clone()).await?;
let r = resp.data;
let count = r.len();
for team in r {
yield team;
}
if count < page_size as usize {
break;
}
let Some(page) = resp.meta.page else { break };
let Some(cursor) = page.cursor else { break };
params.page_cursor = Some(cursor);
}
}
}
pub async fn list_findings_with_http_info(
&self,
params: ListFindingsOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::ListFindingsResponse>,
datadog::Error<ListFindingsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.list_findings";
if local_configuration.is_unstable_operation_enabled(operation_id) {
warn!("Using unstable operation {operation_id}");
} else {
let local_error = datadog::UnstableOperationDisabledError {
msg: "Operation 'v2.list_findings' is not enabled".to_string(),
};
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
}
let page_limit = params.page_limit;
let snapshot_timestamp = params.snapshot_timestamp;
let page_cursor = params.page_cursor;
let filter_tags = params.filter_tags;
let filter_evaluation_changed_at = params.filter_evaluation_changed_at;
let filter_muted = params.filter_muted;
let filter_rule_id = params.filter_rule_id;
let filter_rule_name = params.filter_rule_name;
let filter_resource_type = params.filter_resource_type;
let filter_discovery_timestamp = params.filter_discovery_timestamp;
let filter_evaluation = params.filter_evaluation;
let filter_status = params.filter_status;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/posture_management/findings",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
if let Some(ref local_query_param) = page_limit {
local_req_builder =
local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = snapshot_timestamp {
local_req_builder =
local_req_builder.query(&[("snapshot_timestamp", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = page_cursor {
local_req_builder =
local_req_builder.query(&[("page[cursor]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_tags {
local_req_builder =
local_req_builder.query(&[("filter[tags]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_evaluation_changed_at {
local_req_builder = local_req_builder.query(&[(
"filter[evaluation_changed_at]",
&local_query_param.to_string(),
)]);
};
if let Some(ref local_query_param) = filter_muted {
local_req_builder =
local_req_builder.query(&[("filter[muted]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_rule_id {
local_req_builder =
local_req_builder.query(&[("filter[rule_id]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_rule_name {
local_req_builder =
local_req_builder.query(&[("filter[rule_name]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_resource_type {
local_req_builder = local_req_builder
.query(&[("filter[resource_type]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_discovery_timestamp {
local_req_builder = local_req_builder.query(&[(
"filter[discovery_timestamp]",
&local_query_param.to_string(),
)]);
};
if let Some(ref local_query_param) = filter_evaluation {
local_req_builder =
local_req_builder.query(&[("filter[evaluation]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_status {
local_req_builder =
local_req_builder.query(&[("filter[status]", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::ListFindingsResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ListFindingsError> = serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn list_security_filters(
&self,
) -> Result<
crate::datadogV2::model::SecurityFiltersResponse,
datadog::Error<ListSecurityFiltersError>,
> {
match self.list_security_filters_with_http_info().await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn list_security_filters_with_http_info(
&self,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityFiltersResponse>,
datadog::Error<ListSecurityFiltersError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.list_security_filters";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/configuration/security_filters",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityFiltersResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ListSecurityFiltersError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn list_security_monitoring_rules(
&self,
params: ListSecurityMonitoringRulesOptionalParams,
) -> Result<
crate::datadogV2::model::SecurityMonitoringListRulesResponse,
datadog::Error<ListSecurityMonitoringRulesError>,
> {
match self
.list_security_monitoring_rules_with_http_info(params)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn list_security_monitoring_rules_with_http_info(
&self,
params: ListSecurityMonitoringRulesOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringListRulesResponse>,
datadog::Error<ListSecurityMonitoringRulesError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.list_security_monitoring_rules";
let page_size = params.page_size;
let page_number = params.page_number;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/rules",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
if let Some(ref local_query_param) = page_size {
local_req_builder =
local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = page_number {
local_req_builder =
local_req_builder.query(&[("page[number]", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityMonitoringListRulesResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ListSecurityMonitoringRulesError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn list_security_monitoring_signals(
&self,
params: ListSecurityMonitoringSignalsOptionalParams,
) -> Result<
crate::datadogV2::model::SecurityMonitoringSignalsListResponse,
datadog::Error<ListSecurityMonitoringSignalsError>,
> {
match self
.list_security_monitoring_signals_with_http_info(params)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub fn list_security_monitoring_signals_with_pagination(
&self,
mut params: ListSecurityMonitoringSignalsOptionalParams,
) -> impl Stream<
Item = Result<
crate::datadogV2::model::SecurityMonitoringSignal,
datadog::Error<ListSecurityMonitoringSignalsError>,
>,
> + '_ {
try_stream! {
let mut page_size: i32 = 10;
if params.page_limit.is_none() {
params.page_limit = Some(page_size);
} else {
page_size = params.page_limit.unwrap().clone();
}
loop {
let resp = self.list_security_monitoring_signals(params.clone()).await?;
let Some(data) = resp.data else { break };
let r = data;
let count = r.len();
for team in r {
yield team;
}
if count < page_size as usize {
break;
}
let Some(meta) = resp.meta else { break };
let Some(page) = meta.page else { break };
let Some(after) = page.after else { break };
params.page_cursor = Some(after);
}
}
}
pub async fn list_security_monitoring_signals_with_http_info(
&self,
params: ListSecurityMonitoringSignalsOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringSignalsListResponse>,
datadog::Error<ListSecurityMonitoringSignalsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.list_security_monitoring_signals";
let filter_query = params.filter_query;
let filter_from = params.filter_from;
let filter_to = params.filter_to;
let sort = params.sort;
let page_cursor = params.page_cursor;
let page_limit = params.page_limit;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/signals",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
if let Some(ref local_query_param) = filter_query {
local_req_builder =
local_req_builder.query(&[("filter[query]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = filter_from {
local_req_builder = local_req_builder.query(&[(
"filter[from]",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
if let Some(ref local_query_param) = filter_to {
local_req_builder = local_req_builder.query(&[(
"filter[to]",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
if let Some(ref local_query_param) = sort {
local_req_builder =
local_req_builder.query(&[("sort", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = page_cursor {
local_req_builder =
local_req_builder.query(&[("page[cursor]", &local_query_param.to_string())]);
};
if let Some(ref local_query_param) = page_limit {
local_req_builder =
local_req_builder.query(&[("page[limit]", &local_query_param.to_string())]);
};
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringSignalsListResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ListSecurityMonitoringSignalsError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn list_security_monitoring_suppressions(
&self,
) -> Result<
crate::datadogV2::model::SecurityMonitoringSuppressionsResponse,
datadog::Error<ListSecurityMonitoringSuppressionsError>,
> {
match self
.list_security_monitoring_suppressions_with_http_info()
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn list_security_monitoring_suppressions_with_http_info(
&self,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringSuppressionsResponse>,
datadog::Error<ListSecurityMonitoringSuppressionsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.list_security_monitoring_suppressions";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/configuration/suppressions",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringSuppressionsResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<ListSecurityMonitoringSuppressionsError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn mute_findings(
&self,
body: crate::datadogV2::model::BulkMuteFindingsRequest,
) -> Result<crate::datadogV2::model::BulkMuteFindingsResponse, datadog::Error<MuteFindingsError>>
{
match self.mute_findings_with_http_info(body).await {
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn mute_findings_with_http_info(
&self,
body: crate::datadogV2::model::BulkMuteFindingsRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::BulkMuteFindingsResponse>,
datadog::Error<MuteFindingsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.mute_findings";
if local_configuration.is_unstable_operation_enabled(operation_id) {
warn!("Using unstable operation {operation_id}");
} else {
let local_error = datadog::UnstableOperationDisabledError {
msg: "Operation 'v2.mute_findings' is not enabled".to_string(),
};
return Err(datadog::Error::UnstableOperationDisabledError(local_error));
}
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/posture_management/findings",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::BulkMuteFindingsResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<MuteFindingsError> = serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn search_security_monitoring_signals(
&self,
params: SearchSecurityMonitoringSignalsOptionalParams,
) -> Result<
crate::datadogV2::model::SecurityMonitoringSignalsListResponse,
datadog::Error<SearchSecurityMonitoringSignalsError>,
> {
match self
.search_security_monitoring_signals_with_http_info(params)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub fn search_security_monitoring_signals_with_pagination(
&self,
mut params: SearchSecurityMonitoringSignalsOptionalParams,
) -> impl Stream<
Item = Result<
crate::datadogV2::model::SecurityMonitoringSignal,
datadog::Error<SearchSecurityMonitoringSignalsError>,
>,
> + '_ {
try_stream! {
let mut page_size: i32 = 10;
if params.body.is_none() {
params.body = Some(crate::datadogV2::model::SecurityMonitoringSignalListRequest::new());
}
if params.body.as_ref().unwrap().page.is_none() {
params.body.as_mut().unwrap().page = Some(crate::datadogV2::model::SecurityMonitoringSignalListRequestPage::new());
}
if params.body.as_ref().unwrap().page.as_ref().unwrap().limit.is_none() {
params.body.as_mut().unwrap().page.as_mut().unwrap().limit = Some(page_size);
} else {
page_size = params.body.as_ref().unwrap().page.as_ref().unwrap().limit.unwrap().clone();
}
loop {
let resp = self.search_security_monitoring_signals(params.clone()).await?;
let Some(data) = resp.data else { break };
let r = data;
let count = r.len();
for team in r {
yield team;
}
if count < page_size as usize {
break;
}
let Some(meta) = resp.meta else { break };
let Some(page) = meta.page else { break };
let Some(after) = page.after else { break };
params.body.as_mut().unwrap().page.as_mut().unwrap().cursor = Some(after);
}
}
}
pub async fn search_security_monitoring_signals_with_http_info(
&self,
params: SearchSecurityMonitoringSignalsOptionalParams,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringSignalsListResponse>,
datadog::Error<SearchSecurityMonitoringSignalsError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.search_security_monitoring_signals";
let body = params.body;
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/signals/search",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringSignalsListResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<SearchSecurityMonitoringSignalsError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn test_existing_security_monitoring_rule(
&self,
rule_id: String,
body: crate::datadogV2::model::SecurityMonitoringRuleTestRequest,
) -> Result<
crate::datadogV2::model::SecurityMonitoringRuleTestResponse,
datadog::Error<TestExistingSecurityMonitoringRuleError>,
> {
match self
.test_existing_security_monitoring_rule_with_http_info(rule_id, body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn test_existing_security_monitoring_rule_with_http_info(
&self,
rule_id: String,
body: crate::datadogV2::model::SecurityMonitoringRuleTestRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringRuleTestResponse>,
datadog::Error<TestExistingSecurityMonitoringRuleError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.test_existing_security_monitoring_rule";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/rules/{rule_id}/test",
local_configuration.get_operation_host(operation_id),
rule_id = datadog::urlencode(rule_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityMonitoringRuleTestResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<TestExistingSecurityMonitoringRuleError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn test_security_monitoring_rule(
&self,
body: crate::datadogV2::model::SecurityMonitoringRuleTestRequest,
) -> Result<
crate::datadogV2::model::SecurityMonitoringRuleTestResponse,
datadog::Error<TestSecurityMonitoringRuleError>,
> {
match self
.test_security_monitoring_rule_with_http_info(body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn test_security_monitoring_rule_with_http_info(
&self,
body: crate::datadogV2::model::SecurityMonitoringRuleTestRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringRuleTestResponse>,
datadog::Error<TestSecurityMonitoringRuleError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.test_security_monitoring_rule";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/rules/test",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityMonitoringRuleTestResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<TestSecurityMonitoringRuleError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn update_security_filter(
&self,
security_filter_id: String,
body: crate::datadogV2::model::SecurityFilterUpdateRequest,
) -> Result<
crate::datadogV2::model::SecurityFilterResponse,
datadog::Error<UpdateSecurityFilterError>,
> {
match self
.update_security_filter_with_http_info(security_filter_id, body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn update_security_filter_with_http_info(
&self,
security_filter_id: String,
body: crate::datadogV2::model::SecurityFilterUpdateRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityFilterResponse>,
datadog::Error<UpdateSecurityFilterError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.update_security_filter";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/configuration/security_filters/{security_filter_id}",
local_configuration.get_operation_host(operation_id),
security_filter_id = datadog::urlencode(security_filter_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityFilterResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<UpdateSecurityFilterError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn update_security_monitoring_rule(
&self,
rule_id: String,
body: crate::datadogV2::model::SecurityMonitoringRuleUpdatePayload,
) -> Result<
crate::datadogV2::model::SecurityMonitoringRuleResponse,
datadog::Error<UpdateSecurityMonitoringRuleError>,
> {
match self
.update_security_monitoring_rule_with_http_info(rule_id, body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn update_security_monitoring_rule_with_http_info(
&self,
rule_id: String,
body: crate::datadogV2::model::SecurityMonitoringRuleUpdatePayload,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringRuleResponse>,
datadog::Error<UpdateSecurityMonitoringRuleError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.update_security_monitoring_rule";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/rules/{rule_id}",
local_configuration.get_operation_host(operation_id),
rule_id = datadog::urlencode(rule_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PUT, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<crate::datadogV2::model::SecurityMonitoringRuleResponse>(
&local_content,
) {
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<UpdateSecurityMonitoringRuleError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn update_security_monitoring_suppression(
&self,
suppression_id: String,
body: crate::datadogV2::model::SecurityMonitoringSuppressionUpdateRequest,
) -> Result<
crate::datadogV2::model::SecurityMonitoringSuppressionResponse,
datadog::Error<UpdateSecurityMonitoringSuppressionError>,
> {
match self
.update_security_monitoring_suppression_with_http_info(suppression_id, body)
.await
{
Ok(response_content) => {
if let Some(e) = response_content.entity {
Ok(e)
} else {
Err(datadog::Error::Serde(serde::de::Error::custom(
"response content was None",
)))
}
}
Err(err) => Err(err),
}
}
pub async fn update_security_monitoring_suppression_with_http_info(
&self,
suppression_id: String,
body: crate::datadogV2::model::SecurityMonitoringSuppressionUpdateRequest,
) -> Result<
datadog::ResponseContent<crate::datadogV2::model::SecurityMonitoringSuppressionResponse>,
datadog::Error<UpdateSecurityMonitoringSuppressionError>,
> {
let local_configuration = &self.config;
let operation_id = "v2.update_security_monitoring_suppression";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/configuration/suppressions/{suppression_id}",
local_configuration.get_operation_host(operation_id),
suppression_id = datadog::urlencode(suppression_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("application/json"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
match serde_json::from_str::<
crate::datadogV2::model::SecurityMonitoringSuppressionResponse,
>(&local_content)
{
Ok(e) => {
return Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: Some(e),
})
}
Err(e) => return Err(datadog::Error::Serde(e)),
};
} else {
let local_entity: Option<UpdateSecurityMonitoringSuppressionError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
pub async fn validate_security_monitoring_rule(
&self,
body: crate::datadogV2::model::SecurityMonitoringRuleValidatePayload,
) -> Result<(), datadog::Error<ValidateSecurityMonitoringRuleError>> {
match self
.validate_security_monitoring_rule_with_http_info(body)
.await
{
Ok(_) => Ok(()),
Err(err) => Err(err),
}
}
pub async fn validate_security_monitoring_rule_with_http_info(
&self,
body: crate::datadogV2::model::SecurityMonitoringRuleValidatePayload,
) -> Result<datadog::ResponseContent<()>, datadog::Error<ValidateSecurityMonitoringRuleError>>
{
let local_configuration = &self.config;
let operation_id = "v2.validate_security_monitoring_rule";
let local_client = &self.client;
let local_uri_str = format!(
"{}/api/v2/security_monitoring/rules/validation",
local_configuration.get_operation_host(operation_id)
);
let mut local_req_builder =
local_client.request(reqwest::Method::POST, local_uri_str.as_str());
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("application/json"));
headers.insert("Accept", HeaderValue::from_static("*/*"));
match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
Err(e) => {
log::warn!("Failed to parse user agent header: {e}, falling back to default");
headers.insert(
reqwest::header::USER_AGENT,
HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
)
}
};
if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
headers.insert(
"DD-API-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-API-KEY header"),
);
};
if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
headers.insert(
"DD-APPLICATION-KEY",
HeaderValue::from_str(local_key.key.as_str())
.expect("failed to parse DD-APPLICATION-KEY header"),
);
};
let output = Vec::new();
let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
if body.serialize(&mut ser).is_ok() {
if let Some(content_encoding) = headers.get("Content-Encoding") {
match content_encoding.to_str().unwrap_or_default() {
"gzip" => {
let mut enc = GzEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"deflate" => {
let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
"zstd1" => {
let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
let _ = enc.write_all(ser.into_inner().as_slice());
match enc.finish() {
Ok(buf) => {
local_req_builder = local_req_builder.body(buf);
}
Err(e) => return Err(datadog::Error::Io(e)),
}
}
_ => {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
} else {
local_req_builder = local_req_builder.body(ser.into_inner());
}
}
local_req_builder = local_req_builder.headers(headers);
let local_req = local_req_builder.build()?;
log::debug!("request content: {:?}", local_req.body());
let local_resp = local_client.execute(local_req).await?;
let local_status = local_resp.status();
let local_content = local_resp.text().await?;
log::debug!("response content: {}", local_content);
if !local_status.is_client_error() && !local_status.is_server_error() {
Ok(datadog::ResponseContent {
status: local_status,
content: local_content,
entity: None,
})
} else {
let local_entity: Option<ValidateSecurityMonitoringRuleError> =
serde_json::from_str(&local_content).ok();
let local_error = datadog::ResponseContent {
status: local_status,
content: local_content,
entity: local_entity,
};
Err(datadog::Error::ResponseError(local_error))
}
}
}