use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct ResourcesCatalogList<'a> {
client: &'a crate::Client,
account_id: Result<types::McnAccountId, String>,
cloudflare: Result<bool, String>,
desc: Result<bool, String>,
managed: Result<bool, String>,
order_by: Result<::std::string::String, String>,
page: Result<::std::num::NonZeroU64, String>,
per_page: Result<::std::num::NonZeroU64, String>,
provider_id: Result<::std::string::String, String>,
region: Result<::std::string::String, String>,
resource_group: Result<::std::string::String, String>,
resource_id: Result<::std::vec::Vec<types::McnResourceId>, String>,
resource_type: Result<::std::vec::Vec<types::McnResourceType>, String>,
search: Result<::std::vec::Vec<::std::string::String>, String>,
v2: Result<bool, String>,
}
impl<'a> ResourcesCatalogList<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
cloudflare: Err("cloudflare was not initialized".to_string()),
desc: Err("desc was not initialized".to_string()),
managed: Err("managed was not initialized".to_string()),
order_by: Err("order_by was not initialized".to_string()),
page: Err("page was not initialized".to_string()),
per_page: Err("per_page was not initialized".to_string()),
provider_id: Err("provider_id was not initialized".to_string()),
region: Err("region was not initialized".to_string()),
resource_group: Err("resource_group was not initialized".to_string()),
resource_id: Err("resource_id was not initialized".to_string()),
resource_type: Err("resource_type was not initialized".to_string()),
search: Err("search was not initialized".to_string()),
v2: Err("v2 was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::McnAccountId>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `McnAccountId` for account_id failed".to_string());
self
}
pub fn cloudflare<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.cloudflare = value
.try_into()
.map_err(|_| "conversion to `bool` for cloudflare failed".to_string());
self
}
pub fn desc<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.desc = value
.try_into()
.map_err(|_| "conversion to `bool` for desc failed".to_string());
self
}
pub fn managed<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.managed = value
.try_into()
.map_err(|_| "conversion to `bool` for managed failed".to_string());
self
}
pub fn order_by<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.order_by = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for order_by failed".to_string()
});
self
}
pub fn page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::num::NonZeroU64>,
{
self.page = value.try_into().map_err(|_| {
"conversion to `:: std :: num :: NonZeroU64` for page failed".to_string()
});
self
}
pub fn per_page<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::num::NonZeroU64>,
{
self.per_page = value.try_into().map_err(|_| {
"conversion to `:: std :: num :: NonZeroU64` for per_page failed".to_string()
});
self
}
pub fn provider_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.provider_id = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for provider_id failed".to_string()
});
self
}
pub fn region<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.region = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for region failed".to_string()
});
self
}
pub fn resource_group<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.resource_group = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for resource_group failed".to_string()
});
self
}
pub fn resource_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::vec::Vec<types::McnResourceId>>,
{
self.resource_id = value.try_into().map_err(|_| {
"conversion to `:: std :: vec :: Vec < McnResourceId >` for resource_id failed"
.to_string()
});
self
}
pub fn resource_type<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::vec::Vec<types::McnResourceType>>,
{
self . resource_type = value . try_into () . map_err (| _ | "conversion to `:: std :: vec :: Vec < McnResourceType >` for resource_type failed" . to_string ()) ;
self
}
pub fn search<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::vec::Vec<::std::string::String>>,
{
self . search = value . try_into () . map_err (| _ | "conversion to `:: std :: vec :: Vec < :: std :: string :: String >` for search failed" . to_string ()) ;
self
}
pub fn v2<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.v2 = value
.try_into()
.map_err(|_| "conversion to `bool` for v2 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,
cloudflare,
desc,
managed,
order_by,
page,
per_page,
provider_id,
region,
resource_group,
resource_id,
resource_type,
search,
v2,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let cloudflare = cloudflare.map_err(Error::InvalidRequest)?;
let desc = desc.map_err(Error::InvalidRequest)?;
let managed = managed.map_err(Error::InvalidRequest)?;
let order_by = order_by.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let provider_id = provider_id.map_err(Error::InvalidRequest)?;
let region = region.map_err(Error::InvalidRequest)?;
let resource_group = resource_group.map_err(Error::InvalidRequest)?;
let resource_id = resource_id.map_err(Error::InvalidRequest)?;
let resource_type = resource_type.map_err(Error::InvalidRequest)?;
let search = search.map_err(Error::InvalidRequest)?;
let v2 = v2.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/magic/cloud/resources",
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(
"cloudflare",
&cloudflare,
))
.query(&progenitor_client::QueryParam::new("desc", &desc))
.query(&progenitor_client::QueryParam::new("managed", &managed))
.query(&progenitor_client::QueryParam::new("order_by", &order_by))
.query(&progenitor_client::QueryParam::new("page", &page))
.query(&progenitor_client::QueryParam::new("per_page", &per_page))
.query(&progenitor_client::QueryParam::new(
"provider_id",
&provider_id,
))
.query(&progenitor_client::QueryParam::new("region", ®ion))
.query(&progenitor_client::QueryParam::new(
"resource_group",
&resource_group,
))
.query(&progenitor_client::QueryParam::new(
"resource_id",
&resource_id,
))
.query(&progenitor_client::QueryParam::new(
"resource_type",
&resource_type,
))
.query(&progenitor_client::QueryParam::new("search", &search))
.query(&progenitor_client::QueryParam::new("v2", &v2))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "resources_catalog_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 ResourcesCatalogRead<'a> {
client: &'a crate::Client,
account_id: Result<types::McnAccountId, String>,
resource_id: Result<types::McnResourceId, String>,
v2: Result<bool, String>,
}
impl<'a> ResourcesCatalogRead<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
resource_id: Err("resource_id was not initialized".to_string()),
v2: Err("v2 was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::McnAccountId>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `McnAccountId` for account_id failed".to_string());
self
}
pub fn resource_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::McnResourceId>,
{
self.resource_id = value
.try_into()
.map_err(|_| "conversion to `McnResourceId` for resource_id failed".to_string());
self
}
pub fn v2<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.v2 = value
.try_into()
.map_err(|_| "conversion to `bool` for v2 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,
resource_id,
v2,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let resource_id = resource_id.map_err(Error::InvalidRequest)?;
let v2 = v2.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/magic/cloud/resources/{}",
client.baseurl,
encode_path(&account_id.to_string()),
encode_path(&resource_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("v2", &v2))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "resources_catalog_read",
};
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 ResourcesCatalogExport<'a> {
client: &'a crate::Client,
account_id: Result<types::McnAccountId, String>,
desc: Result<bool, String>,
order_by: Result<::std::string::String, String>,
provider_id: Result<::std::string::String, String>,
region: Result<::std::string::String, String>,
resource_group: Result<::std::string::String, String>,
resource_id: Result<::std::vec::Vec<types::McnResourceId>, String>,
resource_type: Result<::std::vec::Vec<types::McnResourceType>, String>,
search: Result<::std::vec::Vec<::std::string::String>, String>,
v2: Result<bool, String>,
}
impl<'a> ResourcesCatalogExport<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
account_id: Err("account_id was not initialized".to_string()),
desc: Err("desc was not initialized".to_string()),
order_by: Err("order_by was not initialized".to_string()),
provider_id: Err("provider_id was not initialized".to_string()),
region: Err("region was not initialized".to_string()),
resource_group: Err("resource_group was not initialized".to_string()),
resource_id: Err("resource_id was not initialized".to_string()),
resource_type: Err("resource_type was not initialized".to_string()),
search: Err("search was not initialized".to_string()),
v2: Err("v2 was not initialized".to_string()),
}
}
pub fn account_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::McnAccountId>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `McnAccountId` for account_id failed".to_string());
self
}
pub fn desc<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.desc = value
.try_into()
.map_err(|_| "conversion to `bool` for desc failed".to_string());
self
}
pub fn order_by<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.order_by = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for order_by failed".to_string()
});
self
}
pub fn provider_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.provider_id = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for provider_id failed".to_string()
});
self
}
pub fn region<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.region = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for region failed".to_string()
});
self
}
pub fn resource_group<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::string::String>,
{
self.resource_group = value.try_into().map_err(|_| {
"conversion to `:: std :: string :: String` for resource_group failed".to_string()
});
self
}
pub fn resource_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::vec::Vec<types::McnResourceId>>,
{
self.resource_id = value.try_into().map_err(|_| {
"conversion to `:: std :: vec :: Vec < McnResourceId >` for resource_id failed"
.to_string()
});
self
}
pub fn resource_type<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::vec::Vec<types::McnResourceType>>,
{
self . resource_type = value . try_into () . map_err (| _ | "conversion to `:: std :: vec :: Vec < McnResourceType >` for resource_type failed" . to_string ()) ;
self
}
pub fn search<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::vec::Vec<::std::string::String>>,
{
self . search = value . try_into () . map_err (| _ | "conversion to `:: std :: vec :: Vec < :: std :: string :: String >` for search failed" . to_string ()) ;
self
}
pub fn v2<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<bool>,
{
self.v2 = value
.try_into()
.map_err(|_| "conversion to `bool` for v2 failed".to_string());
self
}
pub async fn send(self) -> Result<ResponseValue<ByteStream>, Error<()>> {
let Self {
client,
account_id,
desc,
order_by,
provider_id,
region,
resource_group,
resource_id,
resource_type,
search,
v2,
} = self;
let account_id = account_id.map_err(Error::InvalidRequest)?;
let desc = desc.map_err(Error::InvalidRequest)?;
let order_by = order_by.map_err(Error::InvalidRequest)?;
let provider_id = provider_id.map_err(Error::InvalidRequest)?;
let region = region.map_err(Error::InvalidRequest)?;
let resource_group = resource_group.map_err(Error::InvalidRequest)?;
let resource_id = resource_id.map_err(Error::InvalidRequest)?;
let resource_type = resource_type.map_err(Error::InvalidRequest)?;
let search = search.map_err(Error::InvalidRequest)?;
let v2 = v2.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/magic/cloud/resources/export",
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)
.query(&progenitor_client::QueryParam::new("desc", &desc))
.query(&progenitor_client::QueryParam::new("order_by", &order_by))
.query(&progenitor_client::QueryParam::new(
"provider_id",
&provider_id,
))
.query(&progenitor_client::QueryParam::new("region", ®ion))
.query(&progenitor_client::QueryParam::new(
"resource_group",
&resource_group,
))
.query(&progenitor_client::QueryParam::new(
"resource_id",
&resource_id,
))
.query(&progenitor_client::QueryParam::new(
"resource_type",
&resource_type,
))
.query(&progenitor_client::QueryParam::new("search", &search))
.query(&progenitor_client::QueryParam::new("v2", &v2))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "resources_catalog_export",
};
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::stream(response)),
_ => Err(Error::UnexpectedResponse(response)),
}
}
}
#[derive(Debug, Clone)]
pub struct ResourcesCatalogPolicyPreview<'a> {
client: &'a crate::Client,
account_id: Result<types::McnAccountId, String>,
body: Result<types::builder::McnResourcesCatalogPolicyPreviewRequest, String>,
}
impl<'a> ResourcesCatalogPolicyPreview<'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::McnAccountId>,
{
self.account_id = value
.try_into()
.map_err(|_| "conversion to `McnAccountId` for account_id failed".to_string());
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::McnResourcesCatalogPolicyPreviewRequest>,
<V as std::convert::TryInto<types::McnResourcesCatalogPolicyPreviewRequest>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `McnResourcesCatalogPolicyPreviewRequest` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::McnResourcesCatalogPolicyPreviewRequest,
)
-> types::builder::McnResourcesCatalogPolicyPreviewRequest,
{
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::McnResourcesCatalogPolicyPreviewRequest::try_from(v)
.map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/accounts/{}/magic/cloud/resources/policy-preview",
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: "resources_catalog_policy_preview",
};
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)),
}
}
}