use crate::error::Error;
use crate::models::*;
#[derive(Debug, Clone)]
enum Auth {
Basic { key_id: String, key_secret: String },
Bearer { token: String },
}
#[derive(Debug, Clone)]
pub struct Client {
http: reqwest::Client,
base_url: String,
auth: Auth,
}
impl Client {
pub fn new(key_id: impl Into<String>, key_secret: impl Into<String>) -> Self {
Self::with_base_url("https://api.clickhouse.cloud", key_id, key_secret)
}
pub fn with_base_url(
base_url: impl Into<String>,
key_id: impl Into<String>,
key_secret: impl Into<String>,
) -> Self {
Self {
http: reqwest::Client::new(),
base_url: base_url.into().trim_end_matches('/').to_string(),
auth: Auth::Basic {
key_id: key_id.into(),
key_secret: key_secret.into(),
},
}
}
pub fn with_bearer_token(
base_url: impl Into<String>,
token: impl Into<String>,
) -> Self {
Self {
http: reqwest::Client::new(),
base_url: base_url.into().trim_end_matches('/').to_string(),
auth: Auth::Bearer {
token: token.into(),
},
}
}
pub fn with_http_client(
http: reqwest::Client,
base_url: impl Into<String>,
key_id: impl Into<String>,
key_secret: impl Into<String>,
) -> Self {
Self {
http,
base_url: base_url.into().trim_end_matches('/').to_string(),
auth: Auth::Basic {
key_id: key_id.into(),
key_secret: key_secret.into(),
},
}
}
pub fn with_http_client_bearer(
http: reqwest::Client,
base_url: impl Into<String>,
token: impl Into<String>,
) -> Self {
Self {
http,
base_url: base_url.into().trim_end_matches('/').to_string(),
auth: Auth::Bearer {
token: token.into(),
},
}
}
pub fn set_bearer_token(&mut self, token: impl Into<String>) -> Result<(), Error> {
match &mut self.auth {
Auth::Bearer { token: t } => {
*t = token.into();
Ok(())
}
Auth::Basic { .. } => Err(Error::AuthMismatch(
"set_bearer_token called on a Basic-auth client".into(),
)),
}
}
fn request(&self, method: reqwest::Method, path: &str) -> reqwest::RequestBuilder {
let builder = self
.http
.request(method, format!("{}{}", self.base_url, path));
match &self.auth {
Auth::Basic { key_id, key_secret } => builder.basic_auth(key_id, Some(key_secret)),
Auth::Bearer { token } => builder.bearer_auth(token),
}
}
pub async fn run_query(
&self,
service_id: &str,
key_id: &str,
key_secret: &str,
sql: &str,
database: Option<&str>,
format: &str,
) -> Result<reqwest::Response, Error> {
#[derive(serde::Serialize)]
#[serde(rename_all = "camelCase")]
struct RunQueryBody<'a> {
run_id: String,
sql: &'a str,
#[serde(skip_serializing_if = "Option::is_none")]
database: Option<&'a str>,
}
let host = std::env::var("CLICKHOUSE_CLOUD_QUERY_HOST")
.unwrap_or_else(|_| "https://queries.clickhouse.cloud".to_string());
let url = format!(
"{}/service/{}/run",
host.trim_end_matches('/'),
service_id,
);
let body = RunQueryBody {
run_id: uuid::Uuid::new_v4().to_string(),
sql,
database,
};
let response = self
.http
.post(url)
.query(&[("format", format)])
.basic_auth(key_id, Some(key_secret))
.header("content-type", "text/plain;charset=UTF-8")
.header("x-service-type", "clickhouse")
.header("auth-provider", "custom")
.json(&body)
.send()
.await?;
let status = response.status();
if !status.is_success() {
let body_text = response.text().await.unwrap_or_default();
return Err(Error::Api {
status: status.as_u16(),
message: if body_text.is_empty() {
format!("Query API returned {status}")
} else {
body_text
},
});
}
Ok(response)
}
pub async fn organization_get_list(
&self,
) -> Result<ApiResponse<Vec<Organization>>, Error> {
let path = "/v1/organizations".to_string();
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_get(
&self,
organization_id: &str,
) -> Result<ApiResponse<Organization>, Error> {
let path = format!("/v1/organizations/{organization_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_update(
&self,
organization_id: &str,
body: &OrganizationPatchRequest,
) -> Result<ApiResponse<Organization>, Error> {
let path = format!("/v1/organizations/{organization_id}");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn activity_get_list(
&self,
organization_id: &str,
from_date: Option<&str>,
to_date: Option<&str>,
) -> Result<ApiResponse<Vec<Activity>>, Error> {
let path = format!("/v1/organizations/{organization_id}/activities");
let mut req = self.request(reqwest::Method::GET, &path);
if let Some(v) = from_date {
req = req.query(&[("from_date", v)]);
}
if let Some(v) = to_date {
req = req.query(&[("to_date", v)]);
}
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn activity_get(
&self,
organization_id: &str,
activity_id: &str,
) -> Result<ApiResponse<Activity>, Error> {
let path = format!("/v1/organizations/{organization_id}/activities/{activity_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_byoc_infrastructure_create(
&self,
organization_id: &str,
body: &ByocInfrastructurePostRequest,
) -> Result<ApiResponse<ByocConfig>, Error> {
let path = format!("/v1/organizations/{organization_id}/byocInfrastructure");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_byoc_infrastructure_delete(
&self,
organization_id: &str,
byoc_infrastructure_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/byocInfrastructure/{byoc_infrastructure_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_byoc_infrastructure_update(
&self,
organization_id: &str,
byoc_infrastructure_id: &str,
body: &ByocInfrastructurePatchRequest,
) -> Result<ApiResponse<ByocConfig>, Error> {
let path = format!("/v1/organizations/{organization_id}/byocInfrastructure/{byoc_infrastructure_id}");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn invitation_get_list(
&self,
organization_id: &str,
) -> Result<ApiResponse<Vec<Invitation>>, Error> {
let path = format!("/v1/organizations/{organization_id}/invitations");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn invitation_create(
&self,
organization_id: &str,
body: &InvitationPostRequest,
) -> Result<ApiResponse<Invitation>, Error> {
let path = format!("/v1/organizations/{organization_id}/invitations");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn invitation_get(
&self,
organization_id: &str,
invitation_id: &str,
) -> Result<ApiResponse<Invitation>, Error> {
let path = format!("/v1/organizations/{organization_id}/invitations/{invitation_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn invitation_delete(
&self,
organization_id: &str,
invitation_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/invitations/{invitation_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn openapi_key_get_list(
&self,
organization_id: &str,
) -> Result<ApiResponse<Vec<ApiKey>>, Error> {
let path = format!("/v1/organizations/{organization_id}/keys");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn openapi_key_create(
&self,
organization_id: &str,
body: &ApiKeyPostRequest,
) -> Result<ApiResponse<ApiKeyPostResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/keys");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn openapi_key_get(
&self,
organization_id: &str,
key_id: &str,
) -> Result<ApiResponse<ApiKey>, Error> {
let path = format!("/v1/organizations/{organization_id}/keys/{key_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn openapi_key_update(
&self,
organization_id: &str,
key_id: &str,
body: &ApiKeyPatchRequest,
) -> Result<ApiResponse<ApiKey>, Error> {
let path = format!("/v1/organizations/{organization_id}/keys/{key_id}");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn openapi_key_delete(
&self,
organization_id: &str,
key_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/keys/{key_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn member_get_list(
&self,
organization_id: &str,
) -> Result<ApiResponse<Vec<Member>>, Error> {
let path = format!("/v1/organizations/{organization_id}/members");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn member_get(
&self,
organization_id: &str,
user_id: &str,
) -> Result<ApiResponse<Member>, Error> {
let path = format!("/v1/organizations/{organization_id}/members/{user_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn member_update(
&self,
organization_id: &str,
user_id: &str,
body: &MemberPatchRequest,
) -> Result<ApiResponse<Member>, Error> {
let path = format!("/v1/organizations/{organization_id}/members/{user_id}");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn member_delete(
&self,
organization_id: &str,
user_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/members/{user_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_roles_get_list(
&self,
organization_id: &str,
) -> Result<ApiResponse<Vec<RBACRole>>, Error> {
let path = format!("/v1/organizations/{organization_id}/roles");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_role_post(
&self,
organization_id: &str,
body: &RoleCreateRequest,
) -> Result<ApiResponse<RBACRole>, Error> {
let path = format!("/v1/organizations/{organization_id}/roles");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_role_get(
&self,
organization_id: &str,
role_id: &str,
) -> Result<ApiResponse<RBACRole>, Error> {
let path = format!("/v1/organizations/{organization_id}/roles/{role_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_role_patch(
&self,
organization_id: &str,
role_id: &str,
body: &RoleUpdateRequest,
) -> Result<ApiResponse<RBACRole>, Error> {
let path = format!("/v1/organizations/{organization_id}/roles/{role_id}");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_role_delete(
&self,
organization_id: &str,
role_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/roles/{role_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_service_create(
&self,
organization_id: &str,
body: &PostgresServicePostRequest,
) -> Result<ApiResponse<PostgresService>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_service_get_list(
&self,
organization_id: &str,
) -> Result<ApiResponse<Vec<PostgresServiceListItem>>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_service_get(
&self,
organization_id: &str,
postgres_id: &str,
) -> Result<ApiResponse<PostgresService>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_service_delete(
&self,
organization_id: &str,
postgres_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_service_patch(
&self,
organization_id: &str,
postgres_id: &str,
body: &PostgresServicePatchRequest,
) -> Result<ApiResponse<PostgresService>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_service_certs_get(
&self,
organization_id: &str,
postgres_id: &str,
) -> Result<String, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}/caCertificates");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(body_text)
}
pub async fn postgres_instance_config_get(
&self,
organization_id: &str,
postgres_id: &str,
) -> Result<ApiResponse<PostgresInstanceConfig>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}/config");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_instance_config_post(
&self,
organization_id: &str,
postgres_id: &str,
body: &PostgresInstanceConfig,
) -> Result<ApiResponse<PostgresInstanceUpdateConfigResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}/config");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_instance_config_patch(
&self,
organization_id: &str,
postgres_id: &str,
body: &PostgresInstanceConfig,
) -> Result<ApiResponse<PostgresInstanceUpdateConfigResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}/config");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_service_set_password(
&self,
organization_id: &str,
postgres_id: &str,
body: &PostgresServiceSetPassword,
) -> Result<ApiResponse<PostgresServicePasswordResource>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}/password");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_instance_create_read_replica(
&self,
organization_id: &str,
postgres_id: &str,
body: &PostgresServiceReadReplicaRequest,
) -> Result<ApiResponse<PostgresService>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}/readReplica");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_instance_prometheus_get(
&self,
organization_id: &str,
postgres_id: &str,
) -> Result<String, Error> {
let path =
format!("/v1/organizations/{organization_id}/postgres/{postgres_id}/prometheus");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
if !status.is_success() {
let body_text = resp.text().await?;
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text),
});
}
Ok(resp.text().await?)
}
pub async fn postgres_org_prometheus_get(
&self,
organization_id: &str,
) -> Result<String, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/prometheus");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
if !status.is_success() {
let body_text = resp.text().await?;
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text),
});
}
Ok(resp.text().await?)
}
pub async fn postgres_instance_restore(
&self,
organization_id: &str,
postgres_id: &str,
body: &PostgresServiceRestoreRequest,
) -> Result<ApiResponse<PostgresService>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}/restoredService");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn postgres_service_patch_state(
&self,
organization_id: &str,
postgres_id: &str,
body: &PostgresServiceSetState,
) -> Result<ApiResponse<PostgresService>, Error> {
let path = format!("/v1/organizations/{organization_id}/postgres/{postgres_id}/state");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
#[deprecated]
#[allow(deprecated)]
pub async fn organization_private_endpoint_config_get_list(
&self,
organization_id: &str,
cloud_provider: &str,
region_id: &str,
) -> Result<ApiResponse<OrganizationCloudRegionPrivateEndpointConfig>, Error> {
let path = format!("/v1/organizations/{organization_id}/privateEndpointConfig");
let mut req = self.request(reqwest::Method::GET, &path);
req = req.query(&[("cloud_provider", cloud_provider)]);
req = req.query(&[("region_id", region_id)]);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn organization_prometheus_get(
&self,
organization_id: &str,
filtered_metrics: Option<&str>,
) -> Result<String, Error> {
let path = format!("/v1/organizations/{organization_id}/prometheus");
let mut req = self.request(reqwest::Method::GET, &path);
if let Some(v) = filtered_metrics {
req = req.query(&[("filtered_metrics", v)]);
}
let resp = req.send().await?;
let status = resp.status();
if !status.is_success() {
let body_text = resp.text().await?;
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text),
});
}
Ok(resp.text().await?)
}
pub async fn instance_get_list(
&self,
organization_id: &str,
filters: &[&str],
) -> Result<ApiResponse<Vec<Service>>, Error> {
let path = format!("/v1/organizations/{organization_id}/services");
let mut req = self.request(reqwest::Method::GET, &path);
for f in filters {
req = req.query(&[("filter", f)]);
}
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_create(
&self,
organization_id: &str,
body: &ServicePostRequest,
) -> Result<ApiResponse<ServicePostResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/services");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_get(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<Service>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_update(
&self,
organization_id: &str,
service_id: &str,
body: &ServicePatchRequest,
) -> Result<ApiResponse<Service>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_delete(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn backup_bucket_get(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<BackupBucket>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/backupBucket");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn backup_bucket_create(
&self,
organization_id: &str,
service_id: &str,
body: &BackupBucketPostRequest,
) -> Result<ApiResponse<BackupBucket>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/backupBucket");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn backup_bucket_update(
&self,
organization_id: &str,
service_id: &str,
body: &BackupBucketPatchRequest,
) -> Result<ApiResponse<BackupBucket>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/backupBucket");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn backup_bucket_delete(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/backupBucket");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn backup_configuration_get(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<BackupConfiguration>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/backupConfiguration");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn backup_configuration_update(
&self,
organization_id: &str,
service_id: &str,
body: &BackupConfigurationPatchRequest,
) -> Result<ApiResponse<BackupConfiguration>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/backupConfiguration");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn backup_get_list(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<Vec<Backup>>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/backups");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn backup_get(
&self,
organization_id: &str,
service_id: &str,
backup_id: &str,
) -> Result<ApiResponse<Backup>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/backups/{backup_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_get_list(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<Vec<ClickPipe>>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipes");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_create(
&self,
organization_id: &str,
service_id: &str,
body: &ClickPipePostRequest,
) -> Result<ApiResponse<ClickPipe>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipes");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_get(
&self,
organization_id: &str,
service_id: &str,
click_pipe_id: &str,
) -> Result<ApiResponse<ClickPipe>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipes/{click_pipe_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_update(
&self,
organization_id: &str,
service_id: &str,
click_pipe_id: &str,
body: &ClickPipePatchRequest,
) -> Result<ApiResponse<ClickPipe>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipes/{click_pipe_id}");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_delete(
&self,
organization_id: &str,
service_id: &str,
click_pipe_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipes/{click_pipe_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_scaling_update(
&self,
organization_id: &str,
service_id: &str,
click_pipe_id: &str,
body: &ClickPipeScalingPatchRequest,
) -> Result<ApiResponse<ClickPipe>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipes/{click_pipe_id}/scaling");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_settings_get(
&self,
organization_id: &str,
service_id: &str,
click_pipe_id: &str,
) -> Result<ApiResponse<ClickPipeSettings>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipes/{click_pipe_id}/settings");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_settings_update(
&self,
organization_id: &str,
service_id: &str,
click_pipe_id: &str,
body: &ClickPipeSettingsPutRequest,
) -> Result<ApiResponse<ClickPipeSettings>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipes/{click_pipe_id}/settings");
let mut req = self.request(reqwest::Method::PUT, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_state_update(
&self,
organization_id: &str,
service_id: &str,
click_pipe_id: &str,
body: &ClickPipeStatePatchRequest,
) -> Result<ApiResponse<ClickPipe>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipes/{click_pipe_id}/state");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_cdc_scaling_get(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<ClickPipesCdcScaling>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipesCdcScaling");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_cdc_scaling_update(
&self,
organization_id: &str,
service_id: &str,
body: &ClickPipesCdcScalingPatchRequest,
) -> Result<ApiResponse<ClickPipesCdcScaling>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipesCdcScaling");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_reverse_private_endpoint_get_list(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<Vec<ReversePrivateEndpoint>>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipesReversePrivateEndpoints");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_reverse_private_endpoint_create(
&self,
organization_id: &str,
service_id: &str,
body: &CreateReversePrivateEndpoint,
) -> Result<ApiResponse<ReversePrivateEndpoint>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipesReversePrivateEndpoints");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_reverse_private_endpoint_get(
&self,
organization_id: &str,
service_id: &str,
reverse_private_endpoint_id: &str,
) -> Result<ApiResponse<ReversePrivateEndpoint>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipesReversePrivateEndpoints/{reverse_private_endpoint_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_pipe_reverse_private_endpoint_delete(
&self,
organization_id: &str,
service_id: &str,
reverse_private_endpoint_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickpipesReversePrivateEndpoints/{reverse_private_endpoint_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_list_alerts(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<Vec<ClickStackAlertResponse>>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/alerts");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_create_alert(
&self,
organization_id: &str,
service_id: &str,
body: &ClickStackCreateAlertRequest,
) -> Result<ApiResponse<ClickStackAlertResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/alerts");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_get_alert(
&self,
organization_id: &str,
service_id: &str,
click_stack_alert_id: &str,
) -> Result<ApiResponse<ClickStackAlertResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/alerts/{click_stack_alert_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_update_alert(
&self,
organization_id: &str,
service_id: &str,
click_stack_alert_id: &str,
body: &ClickStackUpdateAlertRequest,
) -> Result<ApiResponse<ClickStackAlertResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/alerts/{click_stack_alert_id}");
let mut req = self.request(reqwest::Method::PUT, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_delete_alert(
&self,
organization_id: &str,
service_id: &str,
click_stack_alert_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/alerts/{click_stack_alert_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_list_dashboards(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<Vec<ClickStackDashboardResponse>>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/dashboards");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_create_dashboard(
&self,
organization_id: &str,
service_id: &str,
body: &ClickStackCreateDashboardRequest,
) -> Result<ApiResponse<ClickStackDashboardResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/dashboards");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_get_dashboard(
&self,
organization_id: &str,
service_id: &str,
click_stack_dashboard_id: &str,
) -> Result<ApiResponse<ClickStackDashboardResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/dashboards/{click_stack_dashboard_id}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_update_dashboard(
&self,
organization_id: &str,
service_id: &str,
click_stack_dashboard_id: &str,
body: &ClickStackUpdateDashboardRequest,
) -> Result<ApiResponse<ClickStackDashboardResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/dashboards/{click_stack_dashboard_id}");
let mut req = self.request(reqwest::Method::PUT, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_delete_dashboard(
&self,
organization_id: &str,
service_id: &str,
click_stack_dashboard_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/dashboards/{click_stack_dashboard_id}");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_list_sources(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<Vec<ClickStackSource>>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/sources");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn click_stack_list_webhooks(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<Vec<ClickStackWebhook>>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickstack/webhooks");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_password_update(
&self,
organization_id: &str,
service_id: &str,
body: &ServicePasswordPatchRequest,
) -> Result<ApiResponse<ServicePasswordPatchResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/password");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_private_endpoint_create(
&self,
organization_id: &str,
service_id: &str,
body: &ServicPrivateEndpointePostRequest,
) -> Result<ApiResponse<InstancePrivateEndpoint>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/privateEndpoint");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_private_endpoint_config_get(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<PrivateEndpointConfig>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/privateEndpointConfig");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_prometheus_get(
&self,
organization_id: &str,
service_id: &str,
filtered_metrics: Option<&str>,
) -> Result<String, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/prometheus");
let mut req = self.request(reqwest::Method::GET, &path);
if let Some(v) = filtered_metrics {
req = req.query(&[("filtered_metrics", v)]);
}
let resp = req.send().await?;
let status = resp.status();
if !status.is_success() {
let body_text = resp.text().await?;
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text),
});
}
Ok(resp.text().await?)
}
pub async fn instance_replica_scaling_update(
&self,
organization_id: &str,
service_id: &str,
body: &ServiceReplicaScalingPatchRequest,
) -> Result<ApiResponse<ServiceScalingPatchResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/replicaScaling");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
#[deprecated]
#[allow(deprecated)]
pub async fn instance_scaling_update(
&self,
organization_id: &str,
service_id: &str,
body: &ServiceScalingPatchRequest,
) -> Result<ApiResponse<Service>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/scaling");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn scaling_schedule_get(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<ScalingSchedule>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/scalingSchedule");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn scaling_schedule_upsert(
&self,
organization_id: &str,
service_id: &str,
body: &ScalingSchedulePostRequest,
) -> Result<ApiResponse<ScalingSchedule>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/scalingSchedule");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn scaling_schedule_delete(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/scalingSchedule");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn upgrade_window_get(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<UpgradeWindow>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/upgradeWindow");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn upgrade_window_update(
&self,
organization_id: &str,
service_id: &str,
body: &UpgradeWindowPutRequest,
) -> Result<ApiResponse<UpgradeWindow>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/upgradeWindow");
let mut req = self.request(reqwest::Method::PUT, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn upgrade_window_delete(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/upgradeWindow");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_query_endpoint_get(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<ServiceQueryAPIEndpoint>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/serviceQueryEndpoint");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_query_endpoint_delete(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<serde_json::Value>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/serviceQueryEndpoint");
let req = self.request(reqwest::Method::DELETE, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_query_endpoint_upsert(
&self,
organization_id: &str,
service_id: &str,
body: &InstanceServiceQueryApiEndpointsPostRequest,
) -> Result<ApiResponse<ServiceQueryAPIEndpoint>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/serviceQueryEndpoint");
let mut req = self.request(reqwest::Method::POST, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn instance_state_update(
&self,
organization_id: &str,
service_id: &str,
body: &ServiceStatePatchRequest,
) -> Result<ApiResponse<Service>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/state");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn usage_cost_get(
&self,
organization_id: &str,
from_date: &str,
to_date: &str,
filters: &[&str],
) -> Result<ApiResponse<UsageCost>, Error> {
let path = format!("/v1/organizations/{organization_id}/usageCost");
let mut req = self.request(reqwest::Method::GET, &path);
req = req.query(&[("from_date", from_date)]);
req = req.query(&[("to_date", to_date)]);
for f in filters {
req = req.query(&[("filter", f)]);
}
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn service_clickhouse_settings_list_get(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<ServiceClickhouseSettingsList>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickhouseSettings");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn service_clickhouse_settings_update(
&self,
organization_id: &str,
service_id: &str,
body: &ServiceClickhouseSettingsPatchRequest,
) -> Result<ApiResponse<ServiceClickhouseSettingsPatchResponse>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickhouseSettings");
let mut req = self.request(reqwest::Method::PATCH, &path);
req = req.json(body);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn service_clickhouse_settings_schema_get(
&self,
organization_id: &str,
service_id: &str,
) -> Result<ApiResponse<ServiceClickhouseSettingsSchema>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickhouseSettings/schema");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
pub async fn service_clickhouse_setting_get(
&self,
organization_id: &str,
service_id: &str,
setting_name: &str,
) -> Result<ApiResponse<ServiceClickhouseSetting>, Error> {
let path = format!("/v1/organizations/{organization_id}/services/{service_id}/clickhouseSettings/{setting_name}");
let req = self.request(reqwest::Method::GET, &path);
let resp = req.send().await?;
let status = resp.status();
let body_text = resp.text().await?;
if !status.is_success() {
return Err(Error::Api {
status: status.as_u16(),
message: serde_json::from_str::<ApiResponse<serde_json::Value>>(&body_text)
.ok()
.and_then(|r| r.error)
.unwrap_or(body_text.clone()),
});
}
Ok(serde_json::from_str(&body_text)?)
}
}