#![cfg(feature = "cloudflare_targets")]
#![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 InfraApiResponseCollection {
pub result_info: Option<std::collections::HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraApiResponseCommon {
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 InfraApiResponseSingle {
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraIPInfo {
pub ipv4: Option<std::collections::HashMap<String, serde_json::Value>>,
pub ipv6: Option<std::collections::HashMap<String, serde_json::Value>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraMessages {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTarget {
pub created_at: String,
pub hostname: String,
pub id: InfraTargetId,
pub ip: InfraIPInfo,
pub modified_at: String,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetArray {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetId {
#[serde(flatten)]
pub data: std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetsDeleteBatchPostRequest {
pub target_ids: Vec<InfraTargetId>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetsGetResponse {
pub result: Option<InfraTarget>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetsListResponse {
pub result: Option<Vec<InfraTarget>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetsPostRequest {
pub hostname: String,
pub ip: InfraIPInfo,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetsPostResponse {
pub result: Option<InfraTarget>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetsPutBatchRequestItem {
pub hostname: String,
pub ip: InfraIPInfo,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetsPutBatchResponse {
pub result: Option<Vec<InfraTarget>>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetsPutRequest {
pub hostname: String,
pub ip: InfraIPInfo,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct InfraTargetsPutResponse {
pub result: Option<InfraTarget>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct InfraTargetsListArgs {
pub account_id: String,
pub hostname: Option<String>,
pub hostname_contains: Option<String>,
pub virtual_network_id: Option<String>,
pub ip_v4: Option<String>,
pub ip_v6: Option<String>,
pub created_before: Option<String>,
pub created_after: Option<String>,
pub modified_before: Option<String>,
pub modified_after: Option<String>,
pub ips: Option<String>,
pub target_ids: Option<String>,
pub ip_like: Option<String>,
pub ipv4_start: Option<String>,
pub ipv4_end: Option<String>,
pub ipv6_start: Option<String>,
pub ipv6_end: Option<String>,
pub page: Option<String>,
pub per_page: Option<String>,
pub order: Option<String>,
pub direction: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct InfraTargetsPostArgs {
pub account_id: String,
pub body: InfraTargetsPostRequest,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct InfraTargetsPutBatchArgs {
pub account_id: String,
pub body: Vec<InfraTargetsPutBatchRequestItem>,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct InfraTargetsDeleteBatchPostArgs {
pub account_id: String,
pub body: InfraTargetsDeleteBatchPostRequest,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct InfraTargetsGetArgs {
pub account_id: String,
pub target_id: String,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct InfraTargetsPutArgs {
pub account_id: String,
pub target_id: String,
pub body: InfraTargetsPutRequest,
}
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct InfraTargetsDeleteArgs {
pub account_id: String,
pub target_id: String,
}
pub async fn infra_targets_list_request<F>(
client: DynNetClient,
args: &InfraTargetsListArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<InfraTargetsListResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/infrastructure/targets",
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("hostname", args.hostname.as_deref());
builder = builder.query("hostname_contains", args.hostname_contains.as_deref());
builder = builder.query("virtual_network_id", args.virtual_network_id.as_deref());
builder = builder.query("ip_v4", args.ip_v4.as_deref());
builder = builder.query("ip_v6", args.ip_v6.as_deref());
builder = builder.query("created_before", args.created_before.as_deref());
builder = builder.query("created_after", args.created_after.as_deref());
builder = builder.query("modified_before", args.modified_before.as_deref());
builder = builder.query("modified_after", args.modified_after.as_deref());
builder = builder.query("ips", args.ips.as_deref());
builder = builder.query("target_ids", args.target_ids.as_deref());
builder = builder.query("ip_like", args.ip_like.as_deref());
builder = builder.query("ipv4_start", args.ipv4_start.as_deref());
builder = builder.query("ipv4_end", args.ipv4_end.as_deref());
builder = builder.query("ipv6_start", args.ipv6_start.as_deref());
builder = builder.query("ipv6_end", args.ipv6_end.as_deref());
builder = builder.query("page", args.page.as_deref());
builder = builder.query("per_page", args.per_page.as_deref());
builder = builder.query("order", args.order.as_deref());
builder = builder.query("direction", args.direction.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: InfraTargetsListResponse = 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 infra_targets_post_request<F>(
client: DynNetClient,
args: &InfraTargetsPostArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<InfraTargetsPostResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/infrastructure/targets",
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: InfraTargetsPostResponse = 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 infra_targets_put_batch_request<F>(
client: DynNetClient,
args: &InfraTargetsPutBatchArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<InfraTargetsPutBatchResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/infrastructure/targets/batch",
args.account_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: InfraTargetsPutBatchResponse = 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 infra_targets_delete_batch_post_request<F>(
client: DynNetClient,
args: &InfraTargetsDeleteBatchPostArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<()>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/infrastructure/targets/batch_delete",
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 });
}
Ok(ApiResponse { status: status as u16, headers, body: () })
}
pub async fn infra_targets_get_request<F>(
client: DynNetClient,
args: &InfraTargetsGetArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<InfraTargetsGetResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/infrastructure/targets/{}",
args.account_id,
args.target_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: InfraTargetsGetResponse = 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 infra_targets_put_request<F>(
client: DynNetClient,
args: &InfraTargetsPutArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<InfraTargetsPutResponse>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/infrastructure/targets/{}",
args.account_id,
args.target_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: InfraTargetsPutResponse = 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 infra_targets_delete_request<F>(
client: DynNetClient,
args: &InfraTargetsDeleteArgs,
base_url: &str,
builder_mod: Option<F>,
) -> Result<ApiResponse<()>, super::shared::ApiError>
where
F: FnOnce(&mut PreparedRequestBuilder),
{
let path = format!("/accounts/{}/infrastructure/targets/{}",
args.account_id,
args.target_id,
);
let endpoint_url = format!("{}{}", base_url, path);
let mut builder = PreparedRequestBuilder::delete(&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 });
}
Ok(ApiResponse { status: status as u16, headers, body: () })
}