use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct InfraTargetsList<'a> {
client: &'a crate::Client,
account_id: Result<types::InfraAccountTag, String>,
created_after: Result<Option<::chrono::DateTime<::chrono::offset::Utc>>, String>,
created_before: Result<Option<::chrono::DateTime<::chrono::offset::Utc>>, String>,
direction: Result<types::InfraSortingDirection, String>,
hostname: Result<Option<::std::string::String>, String>,
hostname_contains: Result<Option<::std::string::String>, String>,
ip_like: Result<Option<::std::string::String>, String>,
ip_v4: Result<Option<::std::string::String>, String>,
ip_v6: Result<Option<::std::string::String>, String>,
ips: Result<::std::vec::Vec<::std::string::String>, String>,
ipv4_end: Result<Option<::std::string::String>, String>,
ipv4_start: Result<Option<::std::string::String>, String>,
ipv6_end: Result<Option<::std::string::String>, String>,
ipv6_start: Result<Option<::std::string::String>, String>,
modified_after: Result<Option<::chrono::DateTime<::chrono::offset::Utc>>, String>,
modified_before: Result<Option<::chrono::DateTime<::chrono::offset::Utc>>, String>,
order: Result<types::InfraTargetsListOrder, String>,
page: Result<::std::num::NonZeroU32, String>,
per_page: Result<::std::num::NonZeroU32, String>,
target_ids: Result<::std::vec::Vec<::uuid::Uuid>, String>,
virtual_network_id: Result<Option<::uuid::Uuid>, String>,
}
impl<'a> InfraTargetsList<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
created_after: Ok(None),
created_before: Ok(None),
direction: Err("direction was not initialized".to_string()),
hostname: Ok(None),
hostname_contains: Ok(None),
ip_like: Ok(None),
ip_v4: Ok(None),
ip_v6: Ok(None),
ips: Err("ips was not initialized".to_string()),
ipv4_end: Ok(None),
ipv4_start: Ok(None),
ipv6_end: Ok(None),
ipv6_start: Ok(None),
modified_after: Ok(None),
modified_before: Ok(None),
order: Err("order was not initialized".to_string()),
page: Err("page was not initialized".to_string()),
per_page: Err("per_page was not initialized".to_string()),
target_ids: Err("target_ids was not initialized".to_string()),
virtual_network_id: Ok(None),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraAccountTag>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `InfraAccountTag` for account_id failed".to_string());
self
}
pub fn created_after<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
{
self . created_after = value . try_into () . map (Some) . map_err (| _ | "conversion to `:: chrono :: DateTime < :: chrono :: offset :: Utc >` for created_after failed" . to_string ()) ;
self
}
pub fn created_before<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
{
self . created_before = value . try_into () . map (Some) . map_err (| _ | "conversion to `:: chrono :: DateTime < :: chrono :: offset :: Utc >` for created_before failed" . to_string ()) ;
self
}
pub fn direction<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraSortingDirection>,
{
self.direction = value.try_into().map_err(|_| {
"conversion to `InfraSortingDirection` for direction failed".to_string()
});
self
}
pub fn hostname<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.hostname = value.try_into().map(Some).map_err(|_| {
"conversion to `:: std :: string :: String` for hostname failed".to_string()
});
self
}
pub fn hostname_contains<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.hostname_contains = value.try_into().map(Some).map_err(|_| {
"conversion to `:: std :: string :: String` for hostname_contains failed"
.to_string()
});
self
}
pub fn ip_like<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.ip_like = value.try_into().map(Some).map_err(|_| {
"conversion to `:: std :: string :: String` for ip_like failed".to_string()
});
self
}
pub fn ip_v4<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.ip_v4 = value.try_into().map(Some).map_err(|_| {
"conversion to `:: std :: string :: String` for ip_v4 failed".to_string()
});
self
}
pub fn ip_v6<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.ip_v6 = value.try_into().map(Some).map_err(|_| {
"conversion to `:: std :: string :: String` for ip_v6 failed".to_string()
});
self
}
pub fn ips<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::vec::Vec<::std::string::String>>,
{
self . ips = value . try_into () . map_err (| _ | "conversion to `:: std :: vec :: Vec < :: std :: string :: String >` for ips failed" . to_string ()) ;
self
}
pub fn ipv4_end<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.ipv4_end = value.try_into().map(Some).map_err(|_| {
"conversion to `:: std :: string :: String` for ipv4_end failed".to_string()
});
self
}
pub fn ipv4_start<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.ipv4_start = value.try_into().map(Some).map_err(|_| {
"conversion to `:: std :: string :: String` for ipv4_start failed".to_string()
});
self
}
pub fn ipv6_end<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.ipv6_end = value.try_into().map(Some).map_err(|_| {
"conversion to `:: std :: string :: String` for ipv6_end failed".to_string()
});
self
}
pub fn ipv6_start<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.ipv6_start = value.try_into().map(Some).map_err(|_| {
"conversion to `:: std :: string :: String` for ipv6_start failed".to_string()
});
self
}
pub fn modified_after<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
{
self . modified_after = value . try_into () . map (Some) . map_err (| _ | "conversion to `:: chrono :: DateTime < :: chrono :: offset :: Utc >` for modified_after failed" . to_string ()) ;
self
}
pub fn modified_before<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::chrono::DateTime<::chrono::offset::Utc>>,
{
self . modified_before = value . try_into () . map (Some) . map_err (| _ | "conversion to `:: chrono :: DateTime < :: chrono :: offset :: Utc >` for modified_before failed" . to_string ()) ;
self
}
pub fn order<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraTargetsListOrder>,
{
self.order = value
.try_into()
.map_err(|_| "conversion to `InfraTargetsListOrder` for order failed".to_string());
self
}
pub fn page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::num::NonZeroU32>,
{
self.page = value.try_into().map_err(|_| {
"conversion to `:: std :: num :: NonZeroU32` for page failed".to_string()
});
self
}
pub fn per_page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::num::NonZeroU32>,
{
self.per_page = value.try_into().map_err(|_| {
"conversion to `:: std :: num :: NonZeroU32` for per_page failed".to_string()
});
self
}
pub fn target_ids<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::vec::Vec<::uuid::Uuid>>,
{
self.target_ids = value.try_into().map_err(|_| {
"conversion to `:: std :: vec :: Vec < :: uuid :: Uuid >` for target_ids failed"
.to_string()
});
self
}
pub fn virtual_network_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::uuid::Uuid>,
{
self.virtual_network_id = value.try_into().map(Some).map_err(|_| {
"conversion to `:: uuid :: Uuid` for virtual_network_id failed".to_string()
});
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
created_after,
created_before,
direction,
hostname,
hostname_contains,
ip_like,
ip_v4,
ip_v6,
ips,
ipv4_end,
ipv4_start,
ipv6_end,
ipv6_start,
modified_after,
modified_before,
order,
page,
per_page,
target_ids,
virtual_network_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let created_after = created_after.map_err(Error::InvalidRequest)?;
let created_before = created_before.map_err(Error::InvalidRequest)?;
let direction = direction.map_err(Error::InvalidRequest)?;
let hostname = hostname.map_err(Error::InvalidRequest)?;
let hostname_contains = hostname_contains.map_err(Error::InvalidRequest)?;
let ip_like = ip_like.map_err(Error::InvalidRequest)?;
let ip_v4 = ip_v4.map_err(Error::InvalidRequest)?;
let ip_v6 = ip_v6.map_err(Error::InvalidRequest)?;
let ips = ips.map_err(Error::InvalidRequest)?;
let ipv4_end = ipv4_end.map_err(Error::InvalidRequest)?;
let ipv4_start = ipv4_start.map_err(Error::InvalidRequest)?;
let ipv6_end = ipv6_end.map_err(Error::InvalidRequest)?;
let ipv6_start = ipv6_start.map_err(Error::InvalidRequest)?;
let modified_after = modified_after.map_err(Error::InvalidRequest)?;
let modified_before = modified_before.map_err(Error::InvalidRequest)?;
let order = order.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let target_ids = target_ids.map_err(Error::InvalidRequest)?;
let virtual_network_id = virtual_network_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/infrastructure/targets",
client.baseurl,
encode_path(&account_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.get(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.query(&progenitor_client::QueryParam::new(
"created_after",
&created_after,
))
.query(&progenitor_client::QueryParam::new(
"created_before",
&created_before,
))
.query(&progenitor_client::QueryParam::new("direction", &direction))
.query(&progenitor_client::QueryParam::new("hostname", &hostname))
.query(&progenitor_client::QueryParam::new(
"hostname_contains",
&hostname_contains,
))
.query(&progenitor_client::QueryParam::new("ip_like", &ip_like))
.query(&progenitor_client::QueryParam::new("ip_v4", &ip_v4))
.query(&progenitor_client::QueryParam::new("ip_v6", &ip_v6))
.query(&progenitor_client::QueryParam::new("ips", &ips))
.query(&progenitor_client::QueryParam::new("ipv4_end", &ipv4_end))
.query(&progenitor_client::QueryParam::new(
"ipv4_start",
&ipv4_start,
))
.query(&progenitor_client::QueryParam::new("ipv6_end", &ipv6_end))
.query(&progenitor_client::QueryParam::new(
"ipv6_start",
&ipv6_start,
))
.query(&progenitor_client::QueryParam::new(
"modified_after",
&modified_after,
))
.query(&progenitor_client::QueryParam::new(
"modified_before",
&modified_before,
))
.query(&progenitor_client::QueryParam::new("order", &order))
.query(&progenitor_client::QueryParam::new("page", &page))
.query(&progenitor_client::QueryParam::new("per_page", &per_page))
.query(&progenitor_client::QueryParam::new(
"target_ids",
&target_ids,
))
.query(&progenitor_client::QueryParam::new(
"virtual_network_id",
&virtual_network_id,
))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "infra_targets_list",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct InfraTargetsPost<'a> {
client: &'a crate::Client,
account_id: Result<types::InfraAccountTag, String>,
body: Result<types::builder::InfraTargetsPostBody, String>,
}
impl<'a> InfraTargetsPost<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraAccountTag>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `InfraAccountTag` for account_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraTargetsPostBody>,
<V as std::convert::TryInto<types::InfraTargetsPostBody>>::Error: std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `InfraTargetsPostBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::InfraTargetsPostBody,
) -> types::builder::InfraTargetsPostBody,
{
self.body = self.body.map(f);
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| types::InfraTargetsPostBody::try_from(v).map_err(|e| e.to_string()))
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/infrastructure/targets",
client.baseurl,
encode_path(&account_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.post(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "infra_targets_post",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct InfraTargetsGet<'a> {
client: &'a crate::Client,
account_id: Result<types::InfraAccountTag, String>,
target_id: Result<types::InfraTargetId, String>,
}
impl<'a> InfraTargetsGet<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
target_id: Err("target_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraAccountTag>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `InfraAccountTag` for account_id failed".to_string());
self
}
pub fn target_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraTargetId>,
{
self.target_id = value
.try_into()
.map_err(|_| "conversion to `InfraTargetId` for target_id failed".to_string());
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
target_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let target_id = target_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/infrastructure/targets/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&target_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.get(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "infra_targets_get",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct InfraTargetsPut<'a> {
client: &'a crate::Client,
account_id: Result<types::InfraAccountTag, String>,
target_id: Result<types::InfraTargetId, String>,
body: Result<types::builder::InfraTargetsPutBody, String>,
}
impl<'a> InfraTargetsPut<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
target_id: Err("target_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraAccountTag>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `InfraAccountTag` for account_id failed".to_string());
self
}
pub fn target_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraTargetId>,
{
self.target_id = value
.try_into()
.map_err(|_| "conversion to `InfraTargetId` for target_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraTargetsPutBody>,
<V as std::convert::TryInto<types::InfraTargetsPutBody>>::Error: std::fmt::Display,
{
self.body = value
.try_into()
.map(From::from)
.map_err(|s| format!("conversion to `InfraTargetsPutBody` for body failed: {}", s));
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::InfraTargetsPutBody,
) -> types::builder::InfraTargetsPutBody,
{
self.body = self.body.map(f);
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
target_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let target_id = target_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| types::InfraTargetsPutBody::try_from(v).map_err(|e| e.to_string()))
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/infrastructure/targets/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&target_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "infra_targets_put",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct InfraTargetsDelete<'a> {
client: &'a crate::Client,
account_id: Result<types::InfraAccountTag, String>,
target_id: Result<types::InfraTargetId, String>,
}
impl<'a> InfraTargetsDelete<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
target_id: Err("target_id was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraAccountTag>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `InfraAccountTag` for account_id failed".to_string());
self
}
pub fn target_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraTargetId>,
{
self.target_id = value
.try_into()
.map_err(|_| "conversion to `InfraTargetId` for target_id failed".to_string());
self
}
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self {
client,
account_id,
target_id,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let target_id = target_id.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/infrastructure/targets/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&target_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client.client.delete(url).headers(header_map).build()?;
let info = OperationInfo {
operation_id: "infra_targets_delete",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => Ok(ResponseValue::empty(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct InfraTargetsPutBatch<'a> {
client: &'a crate::Client,
account_id: Result<types::InfraAccountTag, String>,
body: Result<::std::vec::Vec<types::InfraTargetsPutBatchBodyItem>, String>,
}
impl<'a> InfraTargetsPutBatch<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
body: Err("body was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraAccountTag>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `InfraAccountTag` for account_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::vec::Vec<types::InfraTargetsPutBatchBodyItem>>,
{
self . body = value . try_into () . map_err (| _ | "conversion to `:: std :: vec :: Vec < InfraTargetsPutBatchBodyItem >` for body failed" . to_string ()) ;
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
account_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let body = body.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/infrastructure/targets/batch",
client.baseurl,
encode_path(&account_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.put(url)
.header(
::reqwest::header::ACCEPT,
::reqwest::header::HeaderValue::from_static("application/json"),
)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "infra_targets_put_batch",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => ResponseValue::from_response(response).await,
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct InfraTargetsDeleteBatch<'a> {
client: &'a crate::Client,
account_id: Result<types::InfraAccountTag, String>,
body: Result<types::builder::InfraTargetsDeleteBatchBody, String>,
}
impl<'a> InfraTargetsDeleteBatch<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraAccountTag>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `InfraAccountTag` for account_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraTargetsDeleteBatchBody>,
<V as std::convert::TryInto<types::InfraTargetsDeleteBatchBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `InfraTargetsDeleteBatchBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::InfraTargetsDeleteBatchBody,
) -> types::builder::InfraTargetsDeleteBatchBody,
{
self.body = self.body.map(f);
self
}
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self {
client,
account_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::InfraTargetsDeleteBatchBody::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/infrastructure/targets/batch",
client.baseurl,
encode_path(&account_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.delete(url)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "infra_targets_delete_batch",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => Ok(ResponseValue::empty(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct InfraTargetsDeleteBatchPost<'a> {
client: &'a crate::Client,
account_id: Result<types::InfraAccountTag, String>,
body: Result<types::builder::InfraTargetsDeleteBatchPostBody, String>,
}
impl<'a> InfraTargetsDeleteBatchPost<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraAccountTag>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `InfraAccountTag` for account_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::InfraTargetsDeleteBatchPostBody>,
<V as std::convert::TryInto<types::InfraTargetsDeleteBatchPostBody>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `InfraTargetsDeleteBatchPostBody` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::InfraTargetsDeleteBatchPostBody,
) -> types::builder::InfraTargetsDeleteBatchPostBody,
{
self.body = self.body.map(f);
self
}
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
let Self {
client,
account_id,
body,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::InfraTargetsDeleteBatchPostBody::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/infrastructure/targets/batch_delete",
client.baseurl,
encode_path(&account_id.to_string()),
);
let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
header_map.append(
::reqwest::header::HeaderName::from_static("api-version"),
::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
);
#[allow(unused_mut)]
let mut request = client
.client
.post(url)
.json(&body)
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "infra_targets_delete_batch_post",
};
client.pre(&mut request, &info).await?;
let result = client.exec(request, &info).await;
client.post(&result, &info).await?;
let response = result?;
match response.status().as_u16() {
200u16 => Ok(ResponseValue::empty(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}