use super::types;
use crate::{
ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
ResponseValue, encode_path,
};
#[derive(Debug, Clone)]
pub struct TokenValidationRulesList<'a> {
client: &'a crate::Client,
zone_id: Result<types::ApiShieldSchemasIdentifier, String>,
action: Result<types::ApiShieldAction, String>,
enabled: Result<types::ApiShieldEnabled, String>,
host: Result<types::ApiShieldHost, String>,
hostname: Result<types::ApiShieldHost, String>,
id: Result<types::ApiShieldSchemasUuid, String>,
page: Result<::std::num::NonZeroU64, String>,
per_page: Result<i64, String>,
rule_id: Result<types::ApiShieldSchemasUuid, String>,
token_configuration: Result<::std::vec::Vec<types::ApiShieldSchemasUuid>, String>,
}
impl<'a> TokenValidationRulesList<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
zone_id: Err("zone_id was not initialized".to_string()),
action: Err("action was not initialized".to_string()),
enabled: Err("enabled was not initialized".to_string()),
host: Err("host was not initialized".to_string()),
hostname: Err("hostname was not initialized".to_string()),
id: Err("id was not initialized".to_string()),
page: Err("page was not initialized".to_string()),
per_page: Err("per_page was not initialized".to_string()),
rule_id: Err("rule_id was not initialized".to_string()),
token_configuration: Err("token_configuration was not initialized".to_string()),
}
}
pub fn zone_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ApiShieldSchemasIdentifier>,
{
self.zone_id = value.try_into().map_err(|_| {
"conversion to `ApiShieldSchemasIdentifier` for zone_id failed".to_string()
});
self
}
pub fn action<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ApiShieldAction>,
{
self.action = value
.try_into()
.map_err(|_| "conversion to `ApiShieldAction` for action failed".to_string());
self
}
pub fn enabled<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ApiShieldEnabled>,
{
self.enabled = value
.try_into()
.map_err(|_| "conversion to `ApiShieldEnabled` for enabled failed".to_string());
self
}
pub fn host<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ApiShieldHost>,
{
self.host = value
.try_into()
.map_err(|_| "conversion to `ApiShieldHost` for host failed".to_string());
self
}
pub fn hostname<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ApiShieldHost>,
{
self.hostname = value
.try_into()
.map_err(|_| "conversion to `ApiShieldHost` for hostname failed".to_string());
self
}
pub fn id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ApiShieldSchemasUuid>,
{
self.id = value
.try_into()
.map_err(|_| "conversion to `ApiShieldSchemasUuid` for id 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<i64>,
{
self.per_page = value
.try_into()
.map_err(|_| "conversion to `i64` for per_page failed".to_string());
self
}
pub fn rule_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ApiShieldSchemasUuid>,
{
self.rule_id = value
.try_into()
.map_err(|_| "conversion to `ApiShieldSchemasUuid` for rule_id failed".to_string());
self
}
pub fn token_configuration<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<::std::vec::Vec<types::ApiShieldSchemasUuid>>,
{
self . token_configuration = value . try_into () . map_err (| _ | "conversion to `:: std :: vec :: Vec < ApiShieldSchemasUuid >` for token_configuration failed" . to_string ()) ;
self
}
pub async fn send(
self,
) -> Result<
ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
Error<()>,
> {
let Self {
client,
zone_id,
action,
enabled,
host,
hostname,
id,
page,
per_page,
rule_id,
token_configuration,
} = self;
let zone_id = zone_id.map_err(Error::InvalidRequest)?;
let action = action.map_err(Error::InvalidRequest)?;
let enabled = enabled.map_err(Error::InvalidRequest)?;
let host = host.map_err(Error::InvalidRequest)?;
let hostname = hostname.map_err(Error::InvalidRequest)?;
let id = id.map_err(Error::InvalidRequest)?;
let page = page.map_err(Error::InvalidRequest)?;
let per_page = per_page.map_err(Error::InvalidRequest)?;
let rule_id = rule_id.map_err(Error::InvalidRequest)?;
let token_configuration = token_configuration.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/zones/{}/token_validation/rules",
client.baseurl,
encode_path(&zone_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("action", &action))
.query(&progenitor_client::QueryParam::new("enabled", &enabled))
.query(&progenitor_client::QueryParam::new("host", &host))
.query(&progenitor_client::QueryParam::new("hostname", &hostname))
.query(&progenitor_client::QueryParam::new("id", &id))
.query(&progenitor_client::QueryParam::new("page", &page))
.query(&progenitor_client::QueryParam::new("per_page", &per_page))
.query(&progenitor_client::QueryParam::new("rule_id", &rule_id))
.query(&progenitor_client::QueryParam::new(
"token_configuration",
&token_configuration,
))
.headers(header_map)
.build()?;
let info = OperationInfo {
operation_id: "token_validation_rules_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 TokenValidationRulesCreate<'a> {
client: &'a crate::Client,
zone_id: Result<types::ApiShieldSchemasIdentifier, String>,
body: Result<types::builder::ApiShieldCreateSingleRuleRequest, String>,
}
impl<'a> TokenValidationRulesCreate<'a> {
pub fn new(client: &'a crate::Client) -> Self {
Self {
client: client,
zone_id: Err("zone_id was not initialized".to_string()),
body: Ok(::std::default::Default::default()),
}
}
pub fn zone_id<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ApiShieldSchemasIdentifier>,
{
self.zone_id = value.try_into().map_err(|_| {
"conversion to `ApiShieldSchemasIdentifier` for zone_id failed".to_string()
});
self
}
pub fn body<V>(mut self, value: V) -> Self
where
V: std::convert::TryInto<types::ApiShieldCreateSingleRuleRequest>,
<V as std::convert::TryInto<types::ApiShieldCreateSingleRuleRequest>>::Error:
std::fmt::Display,
{
self.body = value.try_into().map(From::from).map_err(|s| {
format!(
"conversion to `ApiShieldCreateSingleRuleRequest` for body failed: {}",
s
)
});
self
}
pub fn body<F>(mut self, f: F) -> Self
where
F: std::ops::FnOnce(
types::builder::ApiShieldCreateSingleRuleRequest,
) -> types::builder::ApiShieldCreateSingleRuleRequest,
{
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,
zone_id,
body,
} = self;
let zone_id = zone_id.map_err(Error::InvalidRequest)?;
let body = body
.and_then(|v| {
types::ApiShieldCreateSingleRuleRequest::try_from(v).map_err(|e| e.to_string())
})
.map_err(Error::InvalidRequest)?;
let url = format!(
"{}/zones/{}/token_validation/rules",
client.baseurl,
encode_path(&zone_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: "token_validation_rules_create",
};
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)),
}
}
}