use reqwest;
#[allow(unused_imports)]
use serde::{de::Error as _};
use crate::{apis::ResponseContent, models};
#[allow(unused_imports)]
use super::{Error, ContentType};
use dtz_config::Configuration;
fn build_url(config: &Configuration) -> String {
if let Some(base_path) = &config.base_path {
let base = url::Url::parse(base_path).unwrap();
let mut target_url = url::Url::parse(crate::apis::SVC_URL).unwrap();
let _ = target_url.set_scheme(base.scheme());
let _ = target_url.set_port(base.port());
let _ = target_url.set_host(Some(base.host_str().unwrap()));
format!("{target_url}")
} else {
crate::apis::SVC_URL.to_string()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DisableError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EnableError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetBuildInfoError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLogActivityError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLogAttributesError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetLogsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetMetricMetadataError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetStatsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListLabelValuesError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListLabelsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostLogError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostMetricError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PostPrometheusError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum QueryLogActivityError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum QueryLogsError {
UnknownValue(serde_json::Value),
}
pub async fn disable(configuration: &Configuration) -> Result<(), Error<DisableError>> {
let uri_str = format!("{}/disable", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DisableError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn enable(configuration: &Configuration) -> Result<(), Error<EnableError>> {
let uri_str = format!("{}/enable", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<EnableError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_build_info(configuration: &Configuration) -> Result<models::GetBuildInfo200Response, Error<GetBuildInfoError>> {
let uri_str = format!("{}/prometheus/api/v1/status/buildinfo", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", 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::GetBuildInfo200Response`"))),
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::GetBuildInfo200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetBuildInfoError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_log_activity(configuration: &Configuration) -> Result<Vec<models::GetLogActivity200ResponseInner>, Error<GetLogActivityError>> {
let uri_str = format!("{}/log/activity", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", 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 `Vec<models::GetLogActivity200ResponseInner>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::GetLogActivity200ResponseInner>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLogActivityError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_log_attributes(configuration: &Configuration) -> Result<Vec<models::GetLogAttributes200ResponseInner>, Error<GetLogAttributesError>> {
let uri_str = format!("{}/log/attribute", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", 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 `Vec<models::GetLogAttributes200ResponseInner>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::GetLogAttributes200ResponseInner>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLogAttributesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_logs(configuration: &Configuration) -> Result<Vec<models::DtzLogsInner>, Error<GetLogsError>> {
let uri_str = format!("{}/log", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", 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 `Vec<models::DtzLogsInner>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::DtzLogsInner>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetLogsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_metric_metadata(configuration: &Configuration) -> Result<models::GetMetricMetadata200Response, Error<GetMetricMetadataError>> {
let uri_str = format!("{}/prometheus/api/v1/metadata", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", 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::GetMetricMetadata200Response`"))),
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::GetMetricMetadata200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetMetricMetadataError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_stats(configuration: &Configuration) -> Result<models::GetStats200Response, Error<GetStatsError>> {
let uri_str = format!("{}/stats", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", 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::GetStats200Response`"))),
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::GetStats200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetStatsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_label_values(configuration: &Configuration, label: &str) -> Result<models::ListLabelValues200Response, Error<ListLabelValuesError>> {
let p_path_label = label;
let uri_str = format!("{}/prometheus/api/v1/label/{label}/values", build_url(configuration), label=crate::apis::urlencode(p_path_label));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", 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::ListLabelValues200Response`"))),
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::ListLabelValues200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListLabelValuesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn list_labels(configuration: &Configuration) -> Result<models::ListLabelValues200Response, Error<ListLabelsError>> {
let uri_str = format!("{}/prometheus/api/v1/labels", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", 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::ListLabelValues200Response`"))),
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::ListLabelValues200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<ListLabelsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn post_log(configuration: &Configuration, post_log_request_inner: Option<Vec<models::PostLogRequestInner>>) -> Result<(), Error<PostLogError>> {
let p_body_post_log_request_inner = post_log_request_inner;
let uri_str = format!("{}/log/push", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
req_builder = req_builder.json(&p_body_post_log_request_inner);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<PostLogError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn post_metric(configuration: &Configuration, dtz_metric: Option<Vec<models::DtzMetric>>) -> Result<(), Error<PostMetricError>> {
let p_body_dtz_metric = dtz_metric;
let uri_str = format!("{}/metric", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
req_builder = req_builder.json(&p_body_dtz_metric);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<PostMetricError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn post_prometheus(configuration: &Configuration, body: Option<&str>) -> Result<(), Error<PostPrometheusError>> {
let p_body_body = body;
let uri_str = format!("{}/prometheus", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
req_builder = req_builder.json(&p_body_body);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<PostPrometheusError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn query_log_activity(configuration: &Configuration, query_logs_request: Option<models::QueryLogsRequest>) -> Result<Vec<models::GetLogActivity200ResponseInner>, Error<QueryLogActivityError>> {
let p_body_query_logs_request = query_logs_request;
let uri_str = format!("{}/log/activity", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
req_builder = req_builder.json(&p_body_query_logs_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 `Vec<models::GetLogActivity200ResponseInner>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::GetLogActivity200ResponseInner>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<QueryLogActivityError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn query_logs(configuration: &Configuration, query_logs_request: Option<models::QueryLogsRequest>) -> Result<Vec<models::DtzLogsInner>, Error<QueryLogsError>> {
let p_body_query_logs_request = query_logs_request;
let uri_str = format!("{}/log", build_url(configuration));
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref value) = configuration.api_key {
req_builder = req_builder.header("X-API-KEY", value);
};
req_builder = req_builder.json(&p_body_query_logs_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 `Vec<models::DtzLogsInner>`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::DtzLogsInner>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<QueryLogsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}