#![cfg(feature = "cloudflare_apps")]
#![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::ApiResponse;
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsAppealReason {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsMessage {
pub message: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsMitigatedEntityType {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsMitigationAppeal {
pub id: String,
pub reason: AbuseReportsAppealReason,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsMitigationAppealRequest {
pub appeals: Vec<AbuseReportsMitigationAppeal>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsMitigationAppealResult {
pub errors: Option<Vec<AbuseReportsMessage>>,
pub messages: Option<Vec<AbuseReportsMessage>>,
pub result: Option<Vec<AbuseReportsMitigationListItem>>,
pub result_info: std::collections::HashMap<String, serde_json::Value>,
pub success: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsMitigationListItem {
pub effective_date: String,
pub entity_id: String,
pub entity_type: AbuseReportsMitigatedEntityType,
pub id: String,
pub status: AbuseReportsMitigationStatus,
#[serde(rename = "type")]
pub r#type: AbuseReportsMitigationType,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsMitigationStatus {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AbuseReportsMitigationType {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApiResponseCollection {
pub result_info: Option<std::collections::HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApiResponseCommon {
pub errors: Vec<std::collections::HashMap<String, serde_json::Value>>,
pub messages: Vec<std::collections::HashMap<String, serde_json::Value>>,
pub success: bool,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplication {
pub application_source: AlexandriaApplicationSource,
pub application_type: AlexandriaApplicationType,
pub application_type_description: AlexandriaApplicationTypeDescription,
pub created_at: AlexandriaApplicationCreatedAt,
pub hostnames: Vec<String>,
pub human_id: AlexandriaApplicationHumanId,
pub id: AlexandriaApplicationId,
pub ip_subnets: Vec<String>,
pub name: AlexandriaApplicationName,
pub port_protocols: Vec<String>,
pub support_domains: Vec<String>,
pub updated_at: AlexandriaApplicationUpdatedAt,
pub version: AlexandriaApplicationVersion,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationCreatedAt {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationHostnames {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationHumanId {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationId {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationIpSubnets {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationName {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationPortProtocols {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationSource {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationSupportDomains {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationType {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationTypeDescription {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationUpdatedAt {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplicationVersion {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaApplications {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaCreateApplicationRequest {
pub application_type_id: String,
pub hostnames: Option<serde_json::Value>,
pub human_id: AlexandriaApplicationHumanId,
pub ip_subnets: Option<Vec<String>>,
pub name: AlexandriaApplicationName,
pub port_protocols: Option<Vec<String>>,
pub support_domains: Option<Vec<String>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaGetApplicationResponse {
pub result: Option<AlexandriaApplication>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaGetApplicationsResponse {
pub result: Option<Vec<AlexandriaApplication>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaMessages {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct AlexandriaUpdateApplicationVersionRequest {
pub hostnames: Option<Vec<String>>,
pub ip_subnets: Option<Vec<String>>,
pub port_protocols: Option<Vec<String>>,
pub support_domains: Option<Vec<String>>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetApplicationsArgs {
pub account_id: String,
pub filter: Option<String>,
pub limit: Option<String>,
pub offset: Option<String>,
pub order_by: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct CreateApplicationArgs {
pub account_id: String,
pub body: AlexandriaCreateApplicationRequest,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct GetApplicationByIdArgs {
pub account_id: String,
pub id: String,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct UpdateApplicationVersionArgs {
pub account_id: String,
pub id: String,
pub body: AlexandriaUpdateApplicationVersionRequest,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct RequestReviewArgs {
pub account_id: String,
pub report_id: String,
pub body: AbuseReportsMitigationAppealRequest,
}
pub async fn get_applications_request<F>(
client: DynNetClient,
args: &GetApplicationsArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<AlexandriaGetApplicationsResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/resource-library/applications",
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("filter", args.filter.as_deref());
builder = builder.query("limit", args.limit.as_deref());
builder = builder.query("offset", args.offset.as_deref());
builder = builder.query("order_by", args.order_by.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: AlexandriaGetApplicationsResponse = 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 create_application_request<F>(
client: DynNetClient,
args: &CreateApplicationArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<AlexandriaGetApplicationResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/resource-library/applications",
args.account_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::post(&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: AlexandriaGetApplicationResponse = 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_application_by_id_request<F>(
client: DynNetClient,
args: &GetApplicationByIdArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<AlexandriaGetApplicationResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/resource-library/applications/{}",
args.account_id,
args.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: AlexandriaGetApplicationResponse = 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 update_application_version_request<F>(
client: DynNetClient,
args: &UpdateApplicationVersionArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<AlexandriaGetApplicationResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/resource-library/applications/{}",
args.account_id,
args.id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::patch(&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: AlexandriaGetApplicationResponse = 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 request_review_request<F>(
client: DynNetClient,
args: &RequestReviewArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<AbuseReportsMitigationAppealResult>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/abuse-reports/{}/mitigations/appeal",
args.account_id,
args.report_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::post(&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: AbuseReportsMitigationAppealResult = 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 })
}