#![cfg(feature = "cloudflare_security_center")]
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
#![allow(clippy::missing_errors_doc, clippy::doc_markdown, clippy::useless_format)]
#![allow(unused_imports)]
use foundation_netio::{DynNetClient, PreparedRequestBuilder};
use foundation_netio::shared::client::http_client::HttpClient;
use serde::{Deserialize, Serialize};
use foundation_macros::JsonHash;
use super::shared::SecurityCenterValueCountsResponse;
use super::shared::SecurityCenterApiResponseCommon;
use super::shared::ApiResponse;
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ArchiveSecurityCenterInsightRequest {
pub dismiss: Option<bool>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ArchiveSecurityCenterInsightResponse {
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct GetSecurityCenterInsightContextResponse {
pub result: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct GetSecurityCenterInsightsResponse {
pub result: Option<serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct SecurityCenterApiResponseSingle {
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct SecurityCenterMessages {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetSecurityCenterInsightsArgs {
pub account_id: String,
pub dismissed: Option<String>,
pub issue_class: Option<String>,
pub issue_type: Option<String>,
pub product: Option<String>,
pub severity: Option<String>,
pub subject: Option<String>,
pub issue_class_neq: Option<String>,
pub issue_type_neq: Option<String>,
pub product_neq: Option<String>,
pub severity_neq: Option<String>,
pub subject_neq: Option<String>,
pub page: Option<String>,
pub per_page: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetSecurityCenterInsightCountsByClassArgs {
pub account_id: String,
pub dismissed: Option<String>,
pub issue_class: Option<String>,
pub issue_type: Option<String>,
pub product: Option<String>,
pub severity: Option<String>,
pub subject: Option<String>,
pub issue_class_neq: Option<String>,
pub issue_type_neq: Option<String>,
pub product_neq: Option<String>,
pub severity_neq: Option<String>,
pub subject_neq: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetSecurityCenterInsightCountsBySeverityArgs {
pub account_id: String,
pub dismissed: Option<String>,
pub issue_class: Option<String>,
pub issue_type: Option<String>,
pub product: Option<String>,
pub severity: Option<String>,
pub subject: Option<String>,
pub issue_class_neq: Option<String>,
pub issue_type_neq: Option<String>,
pub product_neq: Option<String>,
pub severity_neq: Option<String>,
pub subject_neq: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetSecurityCenterInsightCountsByTypeArgs {
pub account_id: String,
pub dismissed: Option<String>,
pub issue_class: Option<String>,
pub issue_type: Option<String>,
pub product: Option<String>,
pub severity: Option<String>,
pub subject: Option<String>,
pub issue_class_neq: Option<String>,
pub issue_type_neq: Option<String>,
pub product_neq: Option<String>,
pub severity_neq: Option<String>,
pub subject_neq: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetSecurityCenterInsightContextArgs {
pub account_id: String,
pub issue_id: String,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct ArchiveSecurityCenterInsightArgs {
pub account_id: String,
pub issue_id: String,
pub body: ArchiveSecurityCenterInsightRequest,
}
pub async fn get_security_center_insights_request<F>(
client: DynNetClient,
args: &GetSecurityCenterInsightsArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<GetSecurityCenterInsightsResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/security-center/insights",
args.account_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::get(&endpoint_url)
.map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;
builder = builder.query("dismissed", args.dismissed.as_deref());
builder = builder.query("issue_class", args.issue_class.as_deref());
builder = builder.query("issue_type", args.issue_type.as_deref());
builder = builder.query("product", args.product.as_deref());
builder = builder.query("severity", args.severity.as_deref());
builder = builder.query("subject", args.subject.as_deref());
builder = builder.query("issue_class~neq", args.issue_class_neq.as_deref());
builder = builder.query("issue_type~neq", args.issue_type_neq.as_deref());
builder = builder.query("product~neq", args.product_neq.as_deref());
builder = builder.query("severity~neq", args.severity_neq.as_deref());
builder = builder.query("subject~neq", args.subject_neq.as_deref());
builder = builder.query("page", args.page.as_deref());
builder = builder.query("per_page", args.per_page.as_deref());
if let Some(f) = builder_mod {
f(&mut builder);
}
let response = client.send_async(builder.build()).await
.map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;
let status: usize = response.get_status().into();
let headers = response.get_headers_ref().clone();
if status < 200 || status >= 300 {
let error_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let body = (!error_bytes.is_empty())
.then(|| String::from_utf8_lossy(&error_bytes).into_owned());
return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body });
}
let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let parsed: GetSecurityCenterInsightsResponse = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
Ok(ApiResponse { status: status as u16, headers, body: parsed })
}
pub async fn get_security_center_insight_counts_by_class_request<F>(
client: DynNetClient,
args: &GetSecurityCenterInsightCountsByClassArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<SecurityCenterValueCountsResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/security-center/insights/class",
args.account_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::get(&endpoint_url)
.map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;
builder = builder.query("dismissed", args.dismissed.as_deref());
builder = builder.query("issue_class", args.issue_class.as_deref());
builder = builder.query("issue_type", args.issue_type.as_deref());
builder = builder.query("product", args.product.as_deref());
builder = builder.query("severity", args.severity.as_deref());
builder = builder.query("subject", args.subject.as_deref());
builder = builder.query("issue_class~neq", args.issue_class_neq.as_deref());
builder = builder.query("issue_type~neq", args.issue_type_neq.as_deref());
builder = builder.query("product~neq", args.product_neq.as_deref());
builder = builder.query("severity~neq", args.severity_neq.as_deref());
builder = builder.query("subject~neq", args.subject_neq.as_deref());
if let Some(f) = builder_mod {
f(&mut builder);
}
let response = client.send_async(builder.build()).await
.map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;
let status: usize = response.get_status().into();
let headers = response.get_headers_ref().clone();
if status < 200 || status >= 300 {
let error_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let body = (!error_bytes.is_empty())
.then(|| String::from_utf8_lossy(&error_bytes).into_owned());
return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body });
}
let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let parsed: SecurityCenterValueCountsResponse = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
Ok(ApiResponse { status: status as u16, headers, body: parsed })
}
pub async fn get_security_center_insight_counts_by_severity_request<F>(
client: DynNetClient,
args: &GetSecurityCenterInsightCountsBySeverityArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<SecurityCenterValueCountsResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/security-center/insights/severity",
args.account_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::get(&endpoint_url)
.map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;
builder = builder.query("dismissed", args.dismissed.as_deref());
builder = builder.query("issue_class", args.issue_class.as_deref());
builder = builder.query("issue_type", args.issue_type.as_deref());
builder = builder.query("product", args.product.as_deref());
builder = builder.query("severity", args.severity.as_deref());
builder = builder.query("subject", args.subject.as_deref());
builder = builder.query("issue_class~neq", args.issue_class_neq.as_deref());
builder = builder.query("issue_type~neq", args.issue_type_neq.as_deref());
builder = builder.query("product~neq", args.product_neq.as_deref());
builder = builder.query("severity~neq", args.severity_neq.as_deref());
builder = builder.query("subject~neq", args.subject_neq.as_deref());
if let Some(f) = builder_mod {
f(&mut builder);
}
let response = client.send_async(builder.build()).await
.map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;
let status: usize = response.get_status().into();
let headers = response.get_headers_ref().clone();
if status < 200 || status >= 300 {
let error_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let body = (!error_bytes.is_empty())
.then(|| String::from_utf8_lossy(&error_bytes).into_owned());
return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body });
}
let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let parsed: SecurityCenterValueCountsResponse = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
Ok(ApiResponse { status: status as u16, headers, body: parsed })
}
pub async fn get_security_center_insight_counts_by_type_request<F>(
client: DynNetClient,
args: &GetSecurityCenterInsightCountsByTypeArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<SecurityCenterValueCountsResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/security-center/insights/type",
args.account_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::get(&endpoint_url)
.map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;
builder = builder.query("dismissed", args.dismissed.as_deref());
builder = builder.query("issue_class", args.issue_class.as_deref());
builder = builder.query("issue_type", args.issue_type.as_deref());
builder = builder.query("product", args.product.as_deref());
builder = builder.query("severity", args.severity.as_deref());
builder = builder.query("subject", args.subject.as_deref());
builder = builder.query("issue_class~neq", args.issue_class_neq.as_deref());
builder = builder.query("issue_type~neq", args.issue_type_neq.as_deref());
builder = builder.query("product~neq", args.product_neq.as_deref());
builder = builder.query("severity~neq", args.severity_neq.as_deref());
builder = builder.query("subject~neq", args.subject_neq.as_deref());
if let Some(f) = builder_mod {
f(&mut builder);
}
let response = client.send_async(builder.build()).await
.map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;
let status: usize = response.get_status().into();
let headers = response.get_headers_ref().clone();
if status < 200 || status >= 300 {
let error_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let body = (!error_bytes.is_empty())
.then(|| String::from_utf8_lossy(&error_bytes).into_owned());
return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body });
}
let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let parsed: SecurityCenterValueCountsResponse = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
Ok(ApiResponse { status: status as u16, headers, body: parsed })
}
pub async fn get_security_center_insight_context_request<F>(
client: DynNetClient,
args: &GetSecurityCenterInsightContextArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<GetSecurityCenterInsightContextResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/security-center/insights/{}/context",
args.account_id,
args.issue_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::get(&endpoint_url)
.map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;
if let Some(f) = builder_mod {
f(&mut builder);
}
let response = client.send_async(builder.build()).await
.map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;
let status: usize = response.get_status().into();
let headers = response.get_headers_ref().clone();
if status < 200 || status >= 300 {
let error_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let body = (!error_bytes.is_empty())
.then(|| String::from_utf8_lossy(&error_bytes).into_owned());
return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body });
}
let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let parsed: GetSecurityCenterInsightContextResponse = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
Ok(ApiResponse { status: status as u16, headers, body: parsed })
}
pub async fn archive_security_center_insight_request<F>(
client: DynNetClient,
args: &ArchiveSecurityCenterInsightArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<ArchiveSecurityCenterInsightResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/security-center/insights/{}/dismiss",
args.account_id,
args.issue_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::put(&endpoint_url)
.map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;
builder = builder.body_json(&args.body)
.map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;
if let Some(f) = builder_mod {
f(&mut builder);
}
let response = client.send_async(builder.build()).await
.map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;
let status: usize = response.get_status().into();
let headers = response.get_headers_ref().clone();
if status < 200 || status >= 300 {
let error_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let body = (!error_bytes.is_empty())
.then(|| String::from_utf8_lossy(&error_bytes).into_owned());
return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body });
}
let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
let parsed: ArchiveSecurityCenterInsightResponse = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
Ok(ApiResponse { status: status as u16, headers, body: parsed })
}