use std::sync::Arc;
use crate::errors::Error;
use crate::http::ClientInner;
use crate::types_gen::*;
pub struct Client {
pub accounts: AccountsService,
pub users: UsersService,
pub regions: RegionsService,
pub region_clusters: RegionClustersService,
pub storages: StoragesService,
pub volumes: VolumesService,
pub volume_fork_trees: VolumeForkTreesService,
pub volume_fork_entries: VolumeForkEntriesService,
pub volume_fork_searches: VolumeForkSearchesService,
pub audit_logs: AuditLogsService,
pub region_audit_logs: RegionAuditLogsService,
pub service_nodes: ServiceNodesService,
pub nodes: NodesService,
pub client_sessions: ClientSessionsService,
pub discover: DiscoverService,
pub dashboard: DashboardService,
pub license: LicenseService,
pub alerts: AlertsService,
pub region_alerts: RegionAlertsService,
pub vault: VaultService,
}
impl Client {
pub fn new(config: Config) -> Result<Self, Error> {
let inner = Arc::new(ClientInner::new(config)?);
Ok(Self {
accounts: AccountsService { inner: Arc::clone(&inner) },
users: UsersService { inner: Arc::clone(&inner) },
regions: RegionsService { inner: Arc::clone(&inner) },
region_clusters: RegionClustersService { inner: Arc::clone(&inner) },
storages: StoragesService { inner: Arc::clone(&inner) },
volumes: VolumesService { inner: Arc::clone(&inner) },
volume_fork_trees: VolumeForkTreesService { inner: Arc::clone(&inner) },
volume_fork_entries: VolumeForkEntriesService { inner: Arc::clone(&inner) },
volume_fork_searches: VolumeForkSearchesService { inner: Arc::clone(&inner) },
audit_logs: AuditLogsService { inner: Arc::clone(&inner) },
region_audit_logs: RegionAuditLogsService { inner: Arc::clone(&inner) },
service_nodes: ServiceNodesService { inner: Arc::clone(&inner) },
nodes: NodesService { inner: Arc::clone(&inner) },
client_sessions: ClientSessionsService { inner: Arc::clone(&inner) },
discover: DiscoverService { inner: Arc::clone(&inner) },
dashboard: DashboardService { inner: Arc::clone(&inner) },
license: LicenseService { inner: Arc::clone(&inner) },
alerts: AlertsService { inner: Arc::clone(&inner) },
region_alerts: RegionAlertsService { inner: Arc::clone(&inner) },
vault: VaultService { inner: Arc::clone(&inner) },
})
}
}
pub struct AccountsService {
inner: Arc<ClientInner>,
}
impl AccountsService {
pub async fn create(&self, req: &CreateAccountRequest) -> Result<IdResponse, Error> {
self.inner.post("/api/v1/accounts/create", req).await
}
pub async fn list(&self, opts: Option<&AccountListOptions>) -> Result<PaginatedResponse<Account>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.is_active {
query.push(("isActive", v.to_string()));
}
if let Some(v) = &opts.page {
query.push(("page", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
}
self.inner.get("/api/v1/accounts/list", &query).await
}
pub async fn get(&self, account_id: i64) -> Result<Account, Error> {
self.inner.get(&format!("/api/v1/accounts/{}", account_id), &[]).await
}
pub async fn edit(&self, account_id: i64, req: &EditAccountRequest) -> Result<IdResponse, Error> {
self.inner.put(&format!("/api/v1/accounts/{}/edit", account_id), req).await
}
pub async fn lock(&self, account_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/accounts/{}/lock", account_id)).await
}
pub async fn unlock(&self, account_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/accounts/{}/unlock", account_id)).await
}
pub async fn deactivate(&self, account_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/accounts/{}/deactivate", account_id)).await
}
pub async fn update_quota(&self, account_id: i64, req: &UpdateAccountQuotaRequest) -> Result<IdResponse, Error> {
self.inner.put(&format!("/api/v1/accounts/{}/quota", account_id), req).await
}
}
pub struct UsersService {
inner: Arc<ClientInner>,
}
impl UsersService {
pub async fn add(&self, req: &AddUserRequest) -> Result<IdResponse, Error> {
self.inner.post("/api/v1/users/add", req).await
}
pub async fn list(&self, opts: Option<&UserListOptions>) -> Result<PaginatedResponse<User>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
query.push(("accountId", opts.account_id.to_string()));
if let Some(v) = &opts.search {
query.push(("search", v.to_string()));
}
if let Some(v) = &opts.is_active {
query.push(("isActive", v.to_string()));
}
if let Some(v) = &opts.page {
query.push(("page", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
}
self.inner.get("/api/v1/users/list", &query).await
}
pub async fn get(&self, user_id: i64) -> Result<User, Error> {
self.inner.get(&format!("/api/v1/users/{}", user_id), &[]).await
}
pub async fn bulk(&self, req: &BulkUserRequest) -> Result<BulkUserResponse, Error> {
self.inner.post("/api/v1/users/bulk", req).await
}
pub async fn edit(&self, user_id: i64, req: &EditUserRequest) -> Result<IdResponse, Error> {
self.inner.put(&format!("/api/v1/users/{}/edit", user_id), req).await
}
pub async fn deactivate(&self, user_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/users/{}/deactivate", user_id)).await
}
}
pub struct RegionsService {
inner: Arc<ClientInner>,
}
impl RegionsService {
pub async fn create(&self, req: &CreateRegionRequest) -> Result<IdResponse, Error> {
self.inner.post("/api/v1/regions/create", req).await
}
pub async fn list(&self, opts: Option<&RegionListOptions>) -> Result<PaginatedResponse<Region>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.is_active {
query.push(("isActive", v.to_string()));
}
if let Some(v) = &opts.page {
query.push(("page", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
}
self.inner.get("/api/v1/regions/list", &query).await
}
pub async fn get(&self, region_id: i64) -> Result<Region, Error> {
self.inner.get(&format!("/api/v1/regions/{}", region_id), &[]).await
}
pub async fn edit(&self, region_id: i64, req: &EditRegionRequest) -> Result<IdResponse, Error> {
self.inner.put(&format!("/api/v1/regions/{}/edit", region_id), req).await
}
pub async fn deactivate(&self, region_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/regions/{}/deactivate", region_id)).await
}
}
pub struct RegionClustersService {
inner: Arc<ClientInner>,
}
impl RegionClustersService {
pub async fn create(&self, region_id: i64, req: &CreateRegionClusterRequest) -> Result<IdResponse, Error> {
self.inner.post(&format!("/api/v1/regions/{}/clusters/create", region_id), req).await
}
pub async fn list(&self, region_id: i64, opts: Option<&RegionClusterListOptions>) -> Result<PaginatedResponse<RegionCluster>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.is_active {
query.push(("isActive", v.to_string()));
}
if let Some(v) = &opts.page {
query.push(("page", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
}
self.inner.get(&format!("/api/v1/regions/{}/clusters/list", region_id), &query).await
}
pub async fn get(&self, region_id: i64, cluster_id: i64) -> Result<RegionCluster, Error> {
self.inner.get(&format!("/api/v1/regions/{}/clusters/{}", region_id, cluster_id), &[]).await
}
pub async fn edit(&self, region_id: i64, cluster_id: i64, req: &EditRegionClusterRequest) -> Result<IdResponse, Error> {
self.inner.put(&format!("/api/v1/regions/{}/clusters/{}/edit", region_id, cluster_id), req).await
}
pub async fn set_default(&self, region_id: i64, cluster_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/regions/{}/clusters/{}/set-default", region_id, cluster_id)).await
}
pub async fn set_ready(&self, region_id: i64, cluster_id: i64, req: &SetRegionClusterReadyRequest) -> Result<SetReadyRegionClusterResponse, Error> {
self.inner.post(&format!("/api/v1/regions/{}/clusters/{}/set-ready", region_id, cluster_id), req).await
}
pub async fn deactivate(&self, region_id: i64, cluster_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/regions/{}/clusters/{}/deactivate", region_id, cluster_id)).await
}
}
pub struct StoragesService {
inner: Arc<ClientInner>,
}
impl StoragesService {
pub async fn create(&self, req: &CreateStorageRequest) -> Result<CreateStorageResponse, Error> {
self.inner.post("/api/v1/storages/create", req).await
}
pub async fn list(&self, opts: Option<&StorageListOptions>) -> Result<PaginatedResponse<Storage>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
query.push(("accountId", opts.account_id.to_string()));
if let Some(v) = &opts.search {
query.push(("search", v.to_string()));
}
if let Some(v) = &opts.region_id {
query.push(("regionId", v.to_string()));
}
if let Some(v) = &opts.storage_type {
query.push(("storageType", v.to_string()));
}
if let Some(v) = &opts.provider_type {
query.push(("providerType", v.to_string()));
}
if let Some(v) = &opts.is_active {
query.push(("isActive", v.to_string()));
}
if let Some(v) = &opts.page {
query.push(("page", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
}
self.inner.get("/api/v1/storages/list", &query).await
}
pub async fn get(&self, storage_id: i64) -> Result<Storage, Error> {
self.inner.get(&format!("/api/v1/storages/{}", storage_id), &[]).await
}
pub async fn edit(&self, storage_id: i64, req: &EditStorageRequest) -> Result<IdResponse, Error> {
self.inner.put(&format!("/api/v1/storages/{}/edit", storage_id), req).await
}
pub async fn deactivate(&self, storage_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/storages/{}/deactivate", storage_id)).await
}
pub async fn test_bucket(&self, req: &TestStorageBucketRequest) -> Result<TestBucketStorageResponse, Error> {
self.inner.post("/api/v1/storages/test-bucket", req).await
}
pub async fn test_storage_bucket(&self, storage_id: i64) -> Result<TestStorageBucketStorageResponse, Error> {
self.inner.post_empty(&format!("/api/v1/storages/{}/test-bucket", storage_id)).await
}
}
pub struct VolumesService {
inner: Arc<ClientInner>,
}
impl VolumesService {
pub async fn create(&self, req: &CreateVolumeRequest) -> Result<CreateVolumeResponse, Error> {
self.inner.post("/api/v1/volumes/create", req).await
}
pub async fn list(&self, opts: Option<&VolumeListOptions>) -> Result<PaginatedResponse<Volume>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
query.push(("accountId", opts.account_id.to_string()));
if let Some(v) = &opts.region_id {
query.push(("regionId", v.to_string()));
}
if let Some(v) = &opts.region_cluster_id {
query.push(("regionClusterId", v.to_string()));
}
if let Some(v) = &opts.storage_id {
query.push(("storageId", v.to_string()));
}
if let Some(v) = &opts.volume_type {
query.push(("volumeType", v.to_string()));
}
if let Some(v) = &opts.locked {
query.push(("locked", v.to_string()));
}
if let Some(v) = &opts.is_active {
query.push(("isActive", v.to_string()));
}
if let Some(v) = &opts.page {
query.push(("page", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
}
self.inner.get("/api/v1/volumes/list", &query).await
}
pub async fn get(&self, volume_id: i64) -> Result<Volume, Error> {
self.inner.get(&format!("/api/v1/volumes/{}", volume_id), &[]).await
}
pub async fn edit(&self, volume_id: i64, req: &EditVolumeRequest) -> Result<IdResponse, Error> {
self.inner.put(&format!("/api/v1/volumes/{}/edit", volume_id), req).await
}
pub async fn lock(&self, volume_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/volumes/{}/lock", volume_id)).await
}
pub async fn unlock(&self, volume_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/volumes/{}/unlock", volume_id)).await
}
pub async fn move_cluster(&self, volume_id: i64, req: &MoveVolumeClusterRequest) -> Result<MoveClusterVolumeResponse, Error> {
self.inner.post(&format!("/api/v1/volumes/{}/move-cluster", volume_id), req).await
}
pub async fn deactivate(&self, volume_id: i64, req: &DeactivateVolumeRequest) -> Result<IdResponse, Error> {
self.inner.post(&format!("/api/v1/volumes/{}/deactivate", volume_id), req).await
}
pub async fn activate(&self, volume_id: i64) -> Result<IdResponse, Error> {
self.inner.post_empty(&format!("/api/v1/volumes/{}/activate", volume_id)).await
}
pub async fn generate_api_keys(&self, volume_id: i64, req: &GenerateVolumeAPIKeysRequest) -> Result<GenerateAPIKeysVolumeResponse, Error> {
self.inner.post(&format!("/api/v1/volumes/{}/api-keys/generate", volume_id), req).await
}
pub async fn revoke_api_key(&self, volume_id: i64, req: &RevokeVolumeAPIKeyRequest) -> Result<(), Error> {
self.inner.post::<serde_json::Value, _>(&format!("/api/v1/volumes/{}/api-keys/revoke", volume_id), req).await.map(|_| ())
}
pub async fn revoke_api_keys_by_user(&self, volume_id: i64, req: &RevokeVolumeAPIKeysByUserRequest) -> Result<(), Error> {
self.inner.post::<serde_json::Value, _>(&format!("/api/v1/volumes/{}/api-keys/revoke-by-user", volume_id), req).await.map(|_| ())
}
pub async fn update_quota(&self, volume_id: i64, req: &UpdateVolumeQuotaRequest) -> Result<IdResponse, Error> {
self.inner.put(&format!("/api/v1/volumes/{}/quota", volume_id), req).await
}
pub async fn stats(&self, volume_id: i64) -> Result<StatsVolumeResponse, Error> {
self.inner.get(&format!("/api/v1/volumes/{}/stats", volume_id), &[]).await
}
pub async fn size_history(&self, volume_id: i64, from: Option<&str>, to: Option<&str>) -> Result<SizeHistoryVolumeResponse, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(v) = from {
query.push(("from", v.to_string()));
}
if let Some(v) = to {
query.push(("to", v.to_string()));
}
self.inner.get(&format!("/api/v1/volumes/{}/size-history", volume_id), &query).await
}
pub async fn create_fork(&self, volume_id: i64, req: &CreateVolumeForkRequest) -> Result<Fork, Error> {
self.inner.post(&format!("/api/v1/volumes/{}/forks/create", volume_id), req).await
}
pub async fn list_forks(&self, volume_id: i64, volume_type: Option<&str>) -> Result<Vec<Fork>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(v) = volume_type {
query.push(("volumeType", v.to_string()));
}
self.inner.get(&format!("/api/v1/volumes/{}/forks", volume_id), &query).await
}
pub async fn list_all_forks(&self, volume_id: i64, volume_type: Option<&str>) -> Result<Vec<Fork>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(v) = volume_type {
query.push(("volumeType", v.to_string()));
}
self.inner.get(&format!("/api/v1/volumes/{}/forks?include_inactive=true", volume_id), &query).await
}
pub async fn delete_fork(&self, volume_id: i64, fork_name: &str, req: &DeleteVolumeForkRequest) -> Result<DeleteForkVolumeResponse, Error> {
self.inner.post(&format!("/api/v1/volumes/{}/forks/{}/delete", volume_id, fork_name), req).await
}
pub async fn restore_fork(&self, volume_id: i64, fork_name: &str, req: &RestoreVolumeForkRequest) -> Result<Fork, Error> {
self.inner.post(&format!("/api/v1/volumes/{}/forks/{}/restore", volume_id, fork_name), req).await
}
}
pub struct VolumeForkTreesService {
inner: Arc<ClientInner>,
}
impl VolumeForkTreesService {
pub async fn list(&self, volume_id: i64, fork_name: &str, opts: Option<&VolumeForkTreeListOptions>) -> Result<CursorPaginatedResponse<ForkTreeEntry>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.path {
query.push(("path", v.to_string()));
}
if let Some(v) = &opts.as_of {
query.push(("asOf", v.to_string()));
}
if let Some(v) = &opts.cursor {
query.push(("cursor", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
if let Some(v) = &opts.sort {
query.push(("sort", v.to_string()));
}
if let Some(v) = &opts.kind {
query.push(("kind", v.to_string()));
}
}
self.inner.get(&format!("/api/v1/volumes/{}/forks/{}/tree", volume_id, fork_name), &query).await
}
}
pub struct VolumeForkEntriesService {
inner: Arc<ClientInner>,
}
impl VolumeForkEntriesService {
pub async fn get(&self, volume_id: i64, fork_name: &str, path: Option<&str>, inode: Option<i64>, as_of: Option<i64>) -> Result<ForkEntryDetail, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(v) = path {
query.push(("path", v.to_string()));
}
if let Some(v) = inode {
query.push(("inode", v.to_string()));
}
if let Some(v) = as_of {
query.push(("asOf", v.to_string()));
}
self.inner.get(&format!("/api/v1/volumes/{}/forks/{}/entry", volume_id, fork_name), &query).await
}
pub async fn versions(&self, volume_id: i64, fork_name: &str, opts: Option<&VolumeForkEntryListOptions>) -> Result<CursorPaginatedResponse<ForkEntryVersion>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.path {
query.push(("path", v.to_string()));
}
if let Some(v) = &opts.cursor {
query.push(("cursor", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
}
self.inner.get(&format!("/api/v1/volumes/{}/forks/{}/entry/versions", volume_id, fork_name), &query).await
}
}
pub struct VolumeForkSearchesService {
inner: Arc<ClientInner>,
}
impl VolumeForkSearchesService {
pub async fn find(&self, volume_id: i64, fork_name: &str, opts: Option<&VolumeForkSearchListOptions>) -> Result<CursorPaginatedResponse<ForkTreeMatch>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.q {
query.push(("q", v.to_string()));
}
if let Some(v) = &opts.path {
query.push(("path", v.to_string()));
}
if let Some(v) = &opts.as_of {
query.push(("asOf", v.to_string()));
}
if let Some(v) = &opts.exact {
query.push(("exact", v.to_string()));
}
if let Some(v) = &opts.cursor {
query.push(("cursor", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
if let Some(v) = &opts.kind {
query.push(("kind", v.to_string()));
}
}
self.inner.get(&format!("/api/v1/volumes/{}/forks/{}/search", volume_id, fork_name), &query).await
}
}
pub struct AuditLogsService {
inner: Arc<ClientInner>,
}
impl AuditLogsService {
pub async fn list(&self, opts: Option<&AuditLogListOptions>) -> Result<CursorPaginatedResponse<AuditLog>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.account_id {
query.push(("accountId", v.to_string()));
}
if let Some(v) = &opts.region_id {
query.push(("regionId", v.to_string()));
}
if let Some(v) = &opts.region_cluster_id {
query.push(("regionClusterId", v.to_string()));
}
if let Some(v) = &opts.cursor {
query.push(("cursor", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
if let Some(v) = &opts.subject {
query.push(("subject", v.to_string()));
}
}
self.inner.get("/api/v1/audit-logs/list", &query).await
}
}
pub struct RegionAuditLogsService {
inner: Arc<ClientInner>,
}
impl RegionAuditLogsService {
pub async fn list(&self, region_id: i64, opts: Option<&RegionAuditLogListOptions>) -> Result<CursorPaginatedResponse<AuditLog>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.region_cluster_id {
query.push(("regionClusterId", v.to_string()));
}
if let Some(v) = &opts.cursor {
query.push(("cursor", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
if let Some(v) = &opts.subject {
query.push(("subject", v.to_string()));
}
if let Some(v) = &opts.node {
query.push(("node", v.to_string()));
}
}
self.inner.get(&format!("/api/v1/regions/{}/audit-logs/list", region_id), &query).await
}
}
pub struct ServiceNodesService {
inner: Arc<ClientInner>,
}
impl ServiceNodesService {
pub async fn list(&self, region_id: i64, service_type: Option<&str>, status: Option<&str>, inactive_hours: Option<i64>, region_cluster_id: Option<i64>) -> Result<Vec<ServiceNode>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(v) = service_type {
query.push(("serviceType", v.to_string()));
}
if let Some(v) = status {
query.push(("status", v.to_string()));
}
if let Some(v) = inactive_hours {
query.push(("inactiveHours", v.to_string()));
}
if let Some(v) = region_cluster_id {
query.push(("regionClusterId", v.to_string()));
}
self.inner.get(&format!("/api/v1/regions/{}/nodes", region_id), &query).await
}
pub async fn stats(&self, region_id: i64, node_id: &str) -> Result<String, Error> {
self.inner.get(&format!("/api/v1/regions/{}/nodes/{}/stats", region_id, crate::http::encode_segment(node_id)), &[]).await
}
}
pub struct NodesService {
inner: Arc<ClientInner>,
}
impl NodesService {
pub async fn list_all(&self, service_type: Option<&str>, status: Option<&str>, inactive_hours: Option<i64>) -> Result<Vec<ServiceNode>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(v) = service_type {
query.push(("serviceType", v.to_string()));
}
if let Some(v) = status {
query.push(("status", v.to_string()));
}
if let Some(v) = inactive_hours {
query.push(("inactiveHours", v.to_string()));
}
self.inner.get("/api/v1/nodes", &query).await
}
}
pub struct ClientSessionsService {
inner: Arc<ClientInner>,
}
impl ClientSessionsService {
pub async fn list(&self, opts: Option<&ClientSessionListOptions>) -> Result<PaginatedResponse<ClientSession>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.account_id {
query.push(("accountId", v.to_string()));
}
if let Some(v) = &opts.region_id {
query.push(("regionId", v.to_string()));
}
if let Some(v) = &opts.region_cluster_id {
query.push(("regionClusterId", v.to_string()));
}
if let Some(v) = &opts.volume_id {
query.push(("volumeId", v.to_string()));
}
if let Some(v) = &opts.user_id {
query.push(("userId", v.to_string()));
}
if let Some(v) = &opts.client_type {
query.push(("clientType", v.to_string()));
}
if let Some(v) = &opts.status {
query.push(("status", v.to_string()));
}
if let Some(v) = &opts.is_active {
query.push(("isActive", v.to_string()));
}
if let Some(v) = &opts.os_name {
query.push(("osName", v.to_string()));
}
if let Some(v) = &opts.platform {
query.push(("platform", v.to_string()));
}
if let Some(v) = &opts.search {
query.push(("search", v.to_string()));
}
if let Some(v) = &opts.page {
query.push(("page", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
}
self.inner.get("/api/v1/client-sessions/list", &query).await
}
pub async fn get(&self, session_id: i64) -> Result<ClientSession, Error> {
self.inner.get(&format!("/api/v1/client-sessions/{}", session_id), &[]).await
}
pub async fn summary(&self, account_id: Option<i64>, region_id: Option<i64>, region_cluster_id: Option<i64>, volume_id: Option<i64>, user_id: Option<i64>) -> Result<SessionSummary, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(v) = account_id {
query.push(("accountId", v.to_string()));
}
if let Some(v) = region_id {
query.push(("regionId", v.to_string()));
}
if let Some(v) = region_cluster_id {
query.push(("regionClusterId", v.to_string()));
}
if let Some(v) = volume_id {
query.push(("volumeId", v.to_string()));
}
if let Some(v) = user_id {
query.push(("userId", v.to_string()));
}
self.inner.get("/api/v1/client-sessions/summary", &query).await
}
}
pub struct DiscoverService {
inner: Arc<ClientInner>,
}
impl DiscoverService {
pub async fn meta(&self, access_key_id: &str) -> Result<DiscoverMetaResponse, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
query.push(("access_key_id", access_key_id.to_string()));
self.inner.get("/api/v1/discover/meta", &query).await
}
}
pub struct DashboardService {
inner: Arc<ClientInner>,
}
impl DashboardService {
pub async fn stats(&self, account_id: i64) -> Result<DashboardStats, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
query.push(("accountId", account_id.to_string()));
self.inner.get("/api/v1/dashboard/stats", &query).await
}
}
pub struct LicenseService {
inner: Arc<ClientInner>,
}
impl LicenseService {
pub async fn get(&self) -> Result<LicenseDetails, Error> {
self.inner.get("/api/v1/license", &[]).await
}
pub async fn terms(&self) -> Result<LicenseTerms, Error> {
self.inner.get("/api/v1/license/terms", &[]).await
}
}
pub struct AlertsService {
inner: Arc<ClientInner>,
}
impl AlertsService {
pub async fn list(&self, opts: Option<&AlertListOptions>) -> Result<PaginatedResponse<ServiceAlert>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.active {
query.push(("active", v.to_string()));
}
if let Some(v) = &opts.account_id {
query.push(("accountId", v.to_string()));
}
if let Some(v) = &opts.region_id {
query.push(("regionId", v.to_string()));
}
if let Some(v) = &opts.severity {
query.push(("severity", v.to_string()));
}
if let Some(v) = &opts.category {
query.push(("category", v.to_string()));
}
if let Some(v) = &opts.since {
query.push(("since", v.to_string()));
}
if let Some(v) = &opts.page {
query.push(("page", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
}
self.inner.get("/api/v1/alerts/list", &query).await
}
pub async fn count(&self) -> Result<AlertCountResponse, Error> {
self.inner.get("/api/v1/alerts/count", &[]).await
}
pub async fn resolve(&self, alert_id: &str) -> Result<(), Error> {
self.inner.post_empty::<serde_json::Value>(&format!("/api/v1/alerts/{}/resolve", alert_id)).await.map(|_| ())
}
}
pub struct RegionAlertsService {
inner: Arc<ClientInner>,
}
impl RegionAlertsService {
pub async fn list(&self, region_id: i64, opts: Option<&RegionAlertListOptions>) -> Result<PaginatedResponse<RegionAlert>, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(opts) = opts {
if let Some(v) = &opts.active {
query.push(("active", v.to_string()));
}
if let Some(v) = &opts.severity {
query.push(("severity", v.to_string()));
}
if let Some(v) = &opts.category {
query.push(("category", v.to_string()));
}
if let Some(v) = &opts.node_id {
query.push(("nodeId", v.to_string()));
}
if let Some(v) = &opts.region_cluster_id {
query.push(("regionClusterId", v.to_string()));
}
if let Some(v) = &opts.since {
query.push(("since", v.to_string()));
}
if let Some(v) = &opts.page {
query.push(("page", v.to_string()));
}
if let Some(v) = &opts.limit {
query.push(("limit", v.to_string()));
}
}
self.inner.get(&format!("/api/v1/regions/{}/alerts/list", region_id), &query).await
}
pub async fn count(&self, region_id: i64, region_cluster_id: Option<i64>) -> Result<AlertCountResponse, Error> {
let mut query: Vec<(&str, String)> = Vec::new();
if let Some(v) = region_cluster_id {
query.push(("regionClusterId", v.to_string()));
}
self.inner.get(&format!("/api/v1/regions/{}/alerts/count", region_id), &query).await
}
pub async fn resolve(&self, region_id: i64, alert_id: &str) -> Result<(), Error> {
self.inner.post_empty::<serde_json::Value>(&format!("/api/v1/regions/{}/alerts/{}/resolve", region_id, alert_id)).await.map(|_| ())
}
}
pub struct VaultService {
inner: Arc<ClientInner>,
}
impl VaultService {
pub async fn resync(&self) -> Result<(), Error> {
self.inner.post_empty::<serde_json::Value>("/api/v1/vault/resync").await.map(|_| ())
}
}