use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccessTfaCreateTfaError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccessTfaDeleteTfaError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccessTfaGetAccessTfaByUseridError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccessTfaGetAccessTfaByUseridByIdError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccessTfaGetTfaError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AccessTfaUpdateTfaError {
Status400(models::PbsError),
Status401(models::PbsError),
Status403(models::PbsError),
Status404(models::PbsError),
Status500(models::PbsError),
Status501(models::PbsError),
Status503(models::PbsError),
UnknownValue(serde_json::Value),
}
pub async fn access_tfa_create_tfa(configuration: &configuration::Configuration, userid: &str, access_tfa_create_tfa_request: models::AccessTfaCreateTfaRequest) -> Result<models::AccessTfaCreateTfaResponse, Error<AccessTfaCreateTfaError>> {
let p_path_userid = userid;
let p_body_access_tfa_create_tfa_request = access_tfa_create_tfa_request;
let uri_str = format!("{}/access/tfa/{userid}", configuration.base_path, userid=crate::apis::urlencode(p_path_userid));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
req_builder = req_builder.json(&p_body_access_tfa_create_tfa_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaCreateTfaResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccessTfaCreateTfaResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccessTfaCreateTfaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn access_tfa_delete_tfa(configuration: &configuration::Configuration, id: &str, userid: &str, password: Option<&str>) -> Result<models::AccessTfaDeleteTfaResponse, Error<AccessTfaDeleteTfaError>> {
let p_path_id = id;
let p_path_userid = userid;
let p_query_password = password;
let uri_str = format!("{}/access/tfa/{userid}/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id), userid=crate::apis::urlencode(p_path_userid));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref param_value) = p_query_password {
req_builder = req_builder.query(&[("password", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaDeleteTfaResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccessTfaDeleteTfaResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccessTfaDeleteTfaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn access_tfa_get_access_tfa_by_userid(configuration: &configuration::Configuration, userid: &str) -> Result<models::AccessTfaGetAccessTfaByUseridResponse, Error<AccessTfaGetAccessTfaByUseridError>> {
let p_path_userid = userid;
let uri_str = format!("{}/access/tfa/{userid}", configuration.base_path, userid=crate::apis::urlencode(p_path_userid));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaGetAccessTfaByUseridResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccessTfaGetAccessTfaByUseridResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccessTfaGetAccessTfaByUseridError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn access_tfa_get_access_tfa_by_userid_by_id(configuration: &configuration::Configuration, id: &str, userid: &str) -> Result<models::AccessTfaGetAccessTfaByUseridByIdResponse, Error<AccessTfaGetAccessTfaByUseridByIdError>> {
let p_path_id = id;
let p_path_userid = userid;
let uri_str = format!("{}/access/tfa/{userid}/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id), userid=crate::apis::urlencode(p_path_userid));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaGetAccessTfaByUseridByIdResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccessTfaGetAccessTfaByUseridByIdResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccessTfaGetAccessTfaByUseridByIdError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn access_tfa_get_tfa(configuration: &configuration::Configuration, ) -> Result<models::AccessTfaGetTfaResponse, Error<AccessTfaGetTfaError>> {
let uri_str = format!("{}/access/tfa", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaGetTfaResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccessTfaGetTfaResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccessTfaGetTfaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn access_tfa_update_tfa(configuration: &configuration::Configuration, id: &str, userid: &str, access_tfa_update_tfa_request: Option<models::AccessTfaUpdateTfaRequest>) -> Result<models::AccessTfaUpdateTfaResponse, Error<AccessTfaUpdateTfaError>> {
let p_path_id = id;
let p_path_userid = userid;
let p_body_access_tfa_update_tfa_request = access_tfa_update_tfa_request;
let uri_str = format!("{}/access/tfa/{userid}/{id}", configuration.base_path, id=crate::apis::urlencode(p_path_id), userid=crate::apis::urlencode(p_path_userid));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("CSRFPreventionToken", value);
};
req_builder = req_builder.json(&p_body_access_tfa_update_tfa_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTfaUpdateTfaResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccessTfaUpdateTfaResponse`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AccessTfaUpdateTfaError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}