use serde::{Deserialize, Serialize};
use crate::Client;
impl Client {
pub async fn list_projects(&self) -> Result<Vec<Project>, crate::error::Error> {
self.get("projects".into()).await
}
pub async fn pause_project(&self, project_id: &str) -> Result<(), crate::Error> {
self.post(format!("projects/{}/pause", project_id), None::<()>)
.await
}
pub async fn restore_project(&self, project_id: &str) -> Result<(), crate::Error> {
self.post(format!("projects/{}/restore", project_id), None::<()>)
.await
}
pub async fn get_project_health(
&self,
project_id: &str,
) -> Result<Vec<ServiceHealth>, crate::Error> {
self.get(format!(
"projects/{}/health?services=auth,db,pooler,storage",
project_id
))
.await
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Project {
pub id: String,
pub organization_id: String,
pub name: String,
pub region: String,
pub created_at: String,
pub status: Status,
pub database: Database,
}
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Copy)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Status {
Inactive,
ActiveHealthy,
ActiveUnhealthy,
ComingUp,
Unknown,
GoingDown,
InitFailed,
Removed,
Restoring,
Upgrading,
Pausing,
RestoreFailed,
Restarting,
PauseFailed,
Resizing,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Database {
pub host: String,
pub version: String,
pub postgres_engine: String,
pub release_channel: String,
}
#[derive(Debug, Deserialize, Clone)]
pub struct ServiceHealth {
pub name: String,
pub healthy: bool,
pub status: Status,
}