1use std::sync::Arc;
4
5use crate::errors::Error;
6use crate::http::ClientInner;
7use crate::types_gen::*;
8
9pub struct Client {
11 pub accounts: AccountsService,
12 pub users: UsersService,
13 pub regions: RegionsService,
14 pub clusters: ClustersService,
15 pub region_clusters: RegionClustersService,
16 pub storages: StoragesService,
17 pub volumes: VolumesService,
18 pub volume_fork_trees: VolumeForkTreesService,
19 pub volume_fork_entries: VolumeForkEntriesService,
20 pub volume_fork_searches: VolumeForkSearchesService,
21 pub audit_logs: AuditLogsService,
22 pub region_audit_logs: RegionAuditLogsService,
23 pub service_nodes: ServiceNodesService,
24 pub nodes: NodesService,
25 pub client_sessions: ClientSessionsService,
26 pub discover: DiscoverService,
27 pub dashboard: DashboardService,
28 pub license: LicenseService,
29 pub alerts: AlertsService,
30 pub region_alerts: RegionAlertsService,
31 pub vault: VaultService,
32}
33
34impl Client {
35 pub fn new(config: Config) -> Result<Self, Error> {
37 let inner = Arc::new(ClientInner::new(config)?);
38 Ok(Self {
39 accounts: AccountsService { inner: Arc::clone(&inner) },
40 users: UsersService { inner: Arc::clone(&inner) },
41 regions: RegionsService { inner: Arc::clone(&inner) },
42 clusters: ClustersService { inner: Arc::clone(&inner) },
43 region_clusters: RegionClustersService { inner: Arc::clone(&inner) },
44 storages: StoragesService { inner: Arc::clone(&inner) },
45 volumes: VolumesService { inner: Arc::clone(&inner) },
46 volume_fork_trees: VolumeForkTreesService { inner: Arc::clone(&inner) },
47 volume_fork_entries: VolumeForkEntriesService { inner: Arc::clone(&inner) },
48 volume_fork_searches: VolumeForkSearchesService { inner: Arc::clone(&inner) },
49 audit_logs: AuditLogsService { inner: Arc::clone(&inner) },
50 region_audit_logs: RegionAuditLogsService { inner: Arc::clone(&inner) },
51 service_nodes: ServiceNodesService { inner: Arc::clone(&inner) },
52 nodes: NodesService { inner: Arc::clone(&inner) },
53 client_sessions: ClientSessionsService { inner: Arc::clone(&inner) },
54 discover: DiscoverService { inner: Arc::clone(&inner) },
55 dashboard: DashboardService { inner: Arc::clone(&inner) },
56 license: LicenseService { inner: Arc::clone(&inner) },
57 alerts: AlertsService { inner: Arc::clone(&inner) },
58 region_alerts: RegionAlertsService { inner: Arc::clone(&inner) },
59 vault: VaultService { inner: Arc::clone(&inner) },
60 })
61 }
62}
63
64pub struct AccountsService {
66 inner: Arc<ClientInner>,
67}
68
69impl AccountsService {
70 pub async fn create(&self, req: &CreateAccountRequest) -> Result<IdResponse, Error> {
71 self.inner.post("/api/v1/accounts/create", req).await
72 }
73
74 pub async fn list(&self, opts: Option<&AccountListOptions>) -> Result<PaginatedResponse<Account>, Error> {
75 let mut query: Vec<(&str, String)> = Vec::new();
76 if let Some(opts) = opts {
77 if let Some(v) = &opts.is_active {
78 query.push(("isActive", v.to_string()));
79 }
80 if let Some(v) = &opts.page {
81 query.push(("page", v.to_string()));
82 }
83 if let Some(v) = &opts.limit {
84 query.push(("limit", v.to_string()));
85 }
86 }
87 self.inner.get("/api/v1/accounts/list", &query).await
88 }
89
90 pub async fn get(&self, account_id: i64) -> Result<Account, Error> {
91 self.inner.get(&format!("/api/v1/accounts/{}", account_id), &[]).await
92 }
93
94 pub async fn edit(&self, account_id: i64, req: &EditAccountRequest) -> Result<IdResponse, Error> {
95 self.inner.put(&format!("/api/v1/accounts/{}/edit", account_id), req).await
96 }
97
98 pub async fn lock(&self, account_id: i64) -> Result<IdResponse, Error> {
99 self.inner.post_empty(&format!("/api/v1/accounts/{}/lock", account_id)).await
100 }
101
102 pub async fn unlock(&self, account_id: i64) -> Result<IdResponse, Error> {
103 self.inner.post_empty(&format!("/api/v1/accounts/{}/unlock", account_id)).await
104 }
105
106 pub async fn deactivate(&self, account_id: i64) -> Result<IdResponse, Error> {
107 self.inner.post_empty(&format!("/api/v1/accounts/{}/deactivate", account_id)).await
108 }
109
110 pub async fn update_quota(&self, account_id: i64, req: &UpdateAccountQuotaRequest) -> Result<IdResponse, Error> {
111 self.inner.put(&format!("/api/v1/accounts/{}/quota", account_id), req).await
112 }
113}
114
115pub struct UsersService {
117 inner: Arc<ClientInner>,
118}
119
120impl UsersService {
121 pub async fn add(&self, req: &AddUserRequest) -> Result<IdResponse, Error> {
122 self.inner.post("/api/v1/users/add", req).await
123 }
124
125 pub async fn list(&self, opts: &UserListOptions) -> Result<PaginatedResponse<User>, Error> {
126 let mut query: Vec<(&str, String)> = Vec::new();
127 query.push(("accountId", opts.account_id.to_string()));
128 if let Some(v) = &opts.search {
129 query.push(("search", v.to_string()));
130 }
131 if let Some(v) = &opts.is_active {
132 query.push(("isActive", v.to_string()));
133 }
134 if let Some(v) = &opts.page {
135 query.push(("page", v.to_string()));
136 }
137 if let Some(v) = &opts.limit {
138 query.push(("limit", v.to_string()));
139 }
140 self.inner.get("/api/v1/users/list", &query).await
141 }
142
143 pub async fn get(&self, user_id: i64) -> Result<User, Error> {
144 self.inner.get(&format!("/api/v1/users/{}", user_id), &[]).await
145 }
146
147 pub async fn bulk(&self, req: &BulkUserRequest) -> Result<BulkUserResponse, Error> {
148 self.inner.post("/api/v1/users/bulk", req).await
149 }
150
151 pub async fn edit(&self, user_id: i64, req: &EditUserRequest) -> Result<IdResponse, Error> {
152 self.inner.put(&format!("/api/v1/users/{}/edit", user_id), req).await
153 }
154
155 pub async fn deactivate(&self, user_id: i64) -> Result<IdResponse, Error> {
156 self.inner.post_empty(&format!("/api/v1/users/{}/deactivate", user_id)).await
157 }
158}
159
160pub struct RegionsService {
162 inner: Arc<ClientInner>,
163}
164
165impl RegionsService {
166 pub async fn create(&self, req: &CreateRegionRequest) -> Result<IdResponse, Error> {
167 self.inner.post("/api/v1/regions/create", req).await
168 }
169
170 pub async fn list(&self, opts: &RegionListOptions) -> Result<PaginatedResponse<Region>, Error> {
171 let mut query: Vec<(&str, String)> = Vec::new();
172 query.push(("accountId", opts.account_id.to_string()));
173 if let Some(v) = &opts.is_active {
174 query.push(("isActive", v.to_string()));
175 }
176 if let Some(v) = &opts.page {
177 query.push(("page", v.to_string()));
178 }
179 if let Some(v) = &opts.limit {
180 query.push(("limit", v.to_string()));
181 }
182 self.inner.get("/api/v1/regions/list", &query).await
183 }
184
185 pub async fn get(&self, region_id: i64) -> Result<Region, Error> {
186 self.inner.get(&format!("/api/v1/regions/{}", region_id), &[]).await
187 }
188
189 pub async fn edit(&self, region_id: i64, req: &EditRegionRequest) -> Result<IdResponse, Error> {
190 self.inner.put(&format!("/api/v1/regions/{}/edit", region_id), req).await
191 }
192
193 pub async fn deactivate(&self, region_id: i64) -> Result<IdResponse, Error> {
194 self.inner.post_empty(&format!("/api/v1/regions/{}/deactivate", region_id)).await
195 }
196}
197
198pub struct ClustersService {
200 inner: Arc<ClientInner>,
201}
202
203impl ClustersService {
204 pub async fn list(&self, opts: &ClusterListOptions) -> Result<PaginatedResponse<RegionCluster>, Error> {
205 let mut query: Vec<(&str, String)> = Vec::new();
206 query.push(("accountId", opts.account_id.to_string()));
207 if let Some(v) = &opts.region_id {
208 query.push(("regionId", v.to_string()));
209 }
210 if let Some(v) = &opts.is_active {
211 query.push(("isActive", v.to_string()));
212 }
213 if let Some(v) = &opts.page {
214 query.push(("page", v.to_string()));
215 }
216 if let Some(v) = &opts.limit {
217 query.push(("limit", v.to_string()));
218 }
219 self.inner.get("/api/v1/clusters/list", &query).await
220 }
221}
222
223pub struct RegionClustersService {
225 inner: Arc<ClientInner>,
226}
227
228impl RegionClustersService {
229 pub async fn create(&self, region_id: i64, req: &CreateRegionClusterRequest) -> Result<IdResponse, Error> {
230 self.inner.post(&format!("/api/v1/regions/{}/clusters/create", region_id), req).await
231 }
232
233 pub async fn list(&self, region_id: i64, opts: Option<&RegionClusterListOptions>) -> Result<PaginatedResponse<RegionCluster>, Error> {
234 let mut query: Vec<(&str, String)> = Vec::new();
235 if let Some(opts) = opts {
236 if let Some(v) = &opts.is_active {
237 query.push(("isActive", v.to_string()));
238 }
239 if let Some(v) = &opts.page {
240 query.push(("page", v.to_string()));
241 }
242 if let Some(v) = &opts.limit {
243 query.push(("limit", v.to_string()));
244 }
245 }
246 self.inner.get(&format!("/api/v1/regions/{}/clusters/list", region_id), &query).await
247 }
248
249 pub async fn get(&self, region_id: i64, cluster_id: i64) -> Result<RegionCluster, Error> {
250 self.inner.get(&format!("/api/v1/regions/{}/clusters/{}", region_id, cluster_id), &[]).await
251 }
252
253 pub async fn edit(&self, region_id: i64, cluster_id: i64, req: &EditRegionClusterRequest) -> Result<IdResponse, Error> {
254 self.inner.put(&format!("/api/v1/regions/{}/clusters/{}/edit", region_id, cluster_id), req).await
255 }
256
257 pub async fn set_default(&self, region_id: i64, cluster_id: i64) -> Result<IdResponse, Error> {
258 self.inner.post_empty(&format!("/api/v1/regions/{}/clusters/{}/set-default", region_id, cluster_id)).await
259 }
260
261 pub async fn set_ready(&self, region_id: i64, cluster_id: i64, req: &SetRegionClusterReadyRequest) -> Result<SetReadyRegionClusterResponse, Error> {
262 self.inner.post(&format!("/api/v1/regions/{}/clusters/{}/set-ready", region_id, cluster_id), req).await
263 }
264
265 pub async fn deactivate(&self, region_id: i64, cluster_id: i64) -> Result<IdResponse, Error> {
266 self.inner.post_empty(&format!("/api/v1/regions/{}/clusters/{}/deactivate", region_id, cluster_id)).await
267 }
268}
269
270pub struct StoragesService {
272 inner: Arc<ClientInner>,
273}
274
275impl StoragesService {
276 pub async fn create(&self, req: &CreateStorageRequest) -> Result<CreateStorageResponse, Error> {
277 self.inner.post("/api/v1/storages/create", req).await
278 }
279
280 pub async fn list(&self, opts: &StorageListOptions) -> Result<PaginatedResponse<Storage>, Error> {
281 let mut query: Vec<(&str, String)> = Vec::new();
282 query.push(("accountId", opts.account_id.to_string()));
283 if let Some(v) = &opts.search {
284 query.push(("search", v.to_string()));
285 }
286 if let Some(v) = &opts.region_id {
287 query.push(("regionId", v.to_string()));
288 }
289 if let Some(v) = &opts.storage_type {
290 query.push(("storageType", v.to_string()));
291 }
292 if let Some(v) = &opts.provider_type {
293 query.push(("providerType", v.to_string()));
294 }
295 if let Some(v) = &opts.is_active {
296 query.push(("isActive", v.to_string()));
297 }
298 if let Some(v) = &opts.page {
299 query.push(("page", v.to_string()));
300 }
301 if let Some(v) = &opts.limit {
302 query.push(("limit", v.to_string()));
303 }
304 self.inner.get("/api/v1/storages/list", &query).await
305 }
306
307 pub async fn get(&self, storage_id: i64) -> Result<Storage, Error> {
308 self.inner.get(&format!("/api/v1/storages/{}", storage_id), &[]).await
309 }
310
311 pub async fn list_block_volumes(&self, storage_id: i64) -> Result<Vec<BlockVolume>, Error> {
312 self.inner.get(&format!("/api/v1/storages/{}/block-volumes", storage_id), &[]).await
313 }
314
315 pub async fn edit(&self, storage_id: i64, req: &EditStorageRequest) -> Result<IdResponse, Error> {
316 self.inner.put(&format!("/api/v1/storages/{}/edit", storage_id), req).await
317 }
318
319 pub async fn deactivate(&self, storage_id: i64) -> Result<IdResponse, Error> {
320 self.inner.post_empty(&format!("/api/v1/storages/{}/deactivate", storage_id)).await
321 }
322
323 pub async fn test_bucket(&self, req: &TestStorageBucketRequest) -> Result<TestBucketStorageResponse, Error> {
324 self.inner.post("/api/v1/storages/test-bucket", req).await
325 }
326
327 pub async fn test_storage_bucket(&self, storage_id: i64) -> Result<TestStorageBucketStorageResponse, Error> {
328 self.inner.post_empty(&format!("/api/v1/storages/{}/test-bucket", storage_id)).await
329 }
330}
331
332pub struct VolumesService {
334 inner: Arc<ClientInner>,
335}
336
337impl VolumesService {
338 pub async fn create(&self, req: &CreateVolumeRequest) -> Result<CreateVolumeResponse, Error> {
339 self.inner.post("/api/v1/volumes/create", req).await
340 }
341
342 pub async fn list(&self, opts: &VolumeListOptions) -> Result<PaginatedResponse<Volume>, Error> {
343 let mut query: Vec<(&str, String)> = Vec::new();
344 query.push(("accountId", opts.account_id.to_string()));
345 if let Some(v) = &opts.region_id {
346 query.push(("regionId", v.to_string()));
347 }
348 if let Some(v) = &opts.region_cluster_id {
349 query.push(("regionClusterId", v.to_string()));
350 }
351 if let Some(v) = &opts.storage_id {
352 query.push(("storageId", v.to_string()));
353 }
354 if let Some(v) = &opts.volume_type {
355 query.push(("volumeType", v.to_string()));
356 }
357 if let Some(v) = &opts.locked {
358 query.push(("locked", v.to_string()));
359 }
360 if let Some(v) = &opts.is_active {
361 query.push(("isActive", v.to_string()));
362 }
363 if let Some(v) = &opts.page {
364 query.push(("page", v.to_string()));
365 }
366 if let Some(v) = &opts.limit {
367 query.push(("limit", v.to_string()));
368 }
369 self.inner.get("/api/v1/volumes/list", &query).await
370 }
371
372 pub async fn get(&self, volume_id: i64) -> Result<Volume, Error> {
373 self.inner.get(&format!("/api/v1/volumes/{}", volume_id), &[]).await
374 }
375
376 pub async fn edit(&self, volume_id: i64, req: &EditVolumeRequest) -> Result<IdResponse, Error> {
377 self.inner.put(&format!("/api/v1/volumes/{}/edit", volume_id), req).await
378 }
379
380 pub async fn lock(&self, volume_id: i64) -> Result<IdResponse, Error> {
381 self.inner.post_empty(&format!("/api/v1/volumes/{}/lock", volume_id)).await
382 }
383
384 pub async fn unlock(&self, volume_id: i64) -> Result<IdResponse, Error> {
385 self.inner.post_empty(&format!("/api/v1/volumes/{}/unlock", volume_id)).await
386 }
387
388 pub async fn move_cluster(&self, volume_id: i64, req: &MoveVolumeClusterRequest) -> Result<MoveClusterVolumeResponse, Error> {
389 self.inner.post(&format!("/api/v1/volumes/{}/move-cluster", volume_id), req).await
390 }
391
392 pub async fn deactivate(&self, volume_id: i64, req: &DeactivateVolumeRequest) -> Result<IdResponse, Error> {
393 self.inner.post(&format!("/api/v1/volumes/{}/deactivate", volume_id), req).await
394 }
395
396 pub async fn activate(&self, volume_id: i64) -> Result<IdResponse, Error> {
397 self.inner.post_empty(&format!("/api/v1/volumes/{}/activate", volume_id)).await
398 }
399
400 pub async fn generate_api_keys(&self, volume_id: i64, req: &GenerateVolumeAPIKeysRequest) -> Result<GenerateAPIKeysVolumeResponse, Error> {
401 self.inner.post(&format!("/api/v1/volumes/{}/api-keys/generate", volume_id), req).await
402 }
403
404 pub async fn revoke_api_key(&self, volume_id: i64, req: &RevokeVolumeAPIKeyRequest) -> Result<(), Error> {
405 self.inner.post::<serde_json::Value, _>(&format!("/api/v1/volumes/{}/api-keys/revoke", volume_id), req).await.map(|_| ())
406 }
407
408 pub async fn revoke_api_keys_by_user(&self, volume_id: i64, req: &RevokeVolumeAPIKeysByUserRequest) -> Result<(), Error> {
409 self.inner.post::<serde_json::Value, _>(&format!("/api/v1/volumes/{}/api-keys/revoke-by-user", volume_id), req).await.map(|_| ())
410 }
411
412 pub async fn update_quota(&self, volume_id: i64, req: &UpdateVolumeQuotaRequest) -> Result<IdResponse, Error> {
413 self.inner.put(&format!("/api/v1/volumes/{}/quota", volume_id), req).await
414 }
415
416 pub async fn stats(&self, volume_id: i64) -> Result<StatsVolumeResponse, Error> {
417 self.inner.get(&format!("/api/v1/volumes/{}/stats", volume_id), &[]).await
418 }
419
420 pub async fn size_history(&self, volume_id: i64, from: Option<&str>, to: Option<&str>) -> Result<SizeHistoryVolumeResponse, Error> {
421 let mut query: Vec<(&str, String)> = Vec::new();
422 if let Some(v) = from {
423 query.push(("from", v.to_string()));
424 }
425 if let Some(v) = to {
426 query.push(("to", v.to_string()));
427 }
428 self.inner.get(&format!("/api/v1/volumes/{}/size-history", volume_id), &query).await
429 }
430
431 pub async fn create_fork(&self, volume_id: i64, req: &CreateVolumeForkRequest) -> Result<Fork, Error> {
432 self.inner.post(&format!("/api/v1/volumes/{}/forks/create", volume_id), req).await
433 }
434
435 pub async fn list_forks(&self, volume_id: i64, volume_type: Option<&str>) -> Result<Vec<Fork>, Error> {
436 let mut query: Vec<(&str, String)> = Vec::new();
437 if let Some(v) = volume_type {
438 query.push(("volumeType", v.to_string()));
439 }
440 self.inner.get(&format!("/api/v1/volumes/{}/forks", volume_id), &query).await
441 }
442
443 pub async fn list_all_forks(&self, volume_id: i64, volume_type: Option<&str>) -> Result<Vec<Fork>, Error> {
444 let mut query: Vec<(&str, String)> = Vec::new();
445 if let Some(v) = volume_type {
446 query.push(("volumeType", v.to_string()));
447 }
448 self.inner.get(&format!("/api/v1/volumes/{}/forks?include_inactive=true", volume_id), &query).await
449 }
450
451 pub async fn delete_fork(&self, volume_id: i64, fork_name: &str, req: &DeleteVolumeForkRequest) -> Result<DeleteForkVolumeResponse, Error> {
452 self.inner.post(&format!("/api/v1/volumes/{}/forks/{}/delete", volume_id, fork_name), req).await
453 }
454
455 pub async fn restore_fork(&self, volume_id: i64, fork_name: &str, req: &RestoreVolumeForkRequest) -> Result<Fork, Error> {
456 self.inner.post(&format!("/api/v1/volumes/{}/forks/{}/restore", volume_id, fork_name), req).await
457 }
458}
459
460pub struct VolumeForkTreesService {
462 inner: Arc<ClientInner>,
463}
464
465impl VolumeForkTreesService {
466 pub async fn list(&self, volume_id: i64, fork_name: &str, opts: Option<&VolumeForkTreeListOptions>) -> Result<CursorPaginatedResponse<ForkTreeEntry>, Error> {
467 let mut query: Vec<(&str, String)> = Vec::new();
468 if let Some(opts) = opts {
469 if let Some(v) = &opts.path {
470 query.push(("path", v.to_string()));
471 }
472 if let Some(v) = &opts.as_of {
473 query.push(("asOf", v.to_string()));
474 }
475 if let Some(v) = &opts.cursor {
476 query.push(("cursor", v.to_string()));
477 }
478 if let Some(v) = &opts.limit {
479 query.push(("limit", v.to_string()));
480 }
481 if let Some(v) = &opts.sort {
482 query.push(("sort", v.to_string()));
483 }
484 if let Some(v) = &opts.kind {
485 query.push(("kind", v.to_string()));
486 }
487 }
488 self.inner.get(&format!("/api/v1/volumes/{}/forks/{}/tree", volume_id, fork_name), &query).await
489 }
490}
491
492pub struct VolumeForkEntriesService {
494 inner: Arc<ClientInner>,
495}
496
497impl VolumeForkEntriesService {
498 pub async fn get(&self, volume_id: i64, fork_name: &str, path: Option<&str>, inode: Option<i64>, as_of: Option<i64>) -> Result<ForkEntryDetail, Error> {
499 let mut query: Vec<(&str, String)> = Vec::new();
500 if let Some(v) = path {
501 query.push(("path", v.to_string()));
502 }
503 if let Some(v) = inode {
504 query.push(("inode", v.to_string()));
505 }
506 if let Some(v) = as_of {
507 query.push(("asOf", v.to_string()));
508 }
509 self.inner.get(&format!("/api/v1/volumes/{}/forks/{}/entry", volume_id, fork_name), &query).await
510 }
511
512 pub async fn versions(&self, volume_id: i64, fork_name: &str, opts: Option<&VolumeForkEntryListOptions>) -> Result<CursorPaginatedResponse<ForkEntryVersion>, Error> {
513 let mut query: Vec<(&str, String)> = Vec::new();
514 if let Some(opts) = opts {
515 if let Some(v) = &opts.path {
516 query.push(("path", v.to_string()));
517 }
518 if let Some(v) = &opts.cursor {
519 query.push(("cursor", v.to_string()));
520 }
521 if let Some(v) = &opts.limit {
522 query.push(("limit", v.to_string()));
523 }
524 }
525 self.inner.get(&format!("/api/v1/volumes/{}/forks/{}/entry/versions", volume_id, fork_name), &query).await
526 }
527}
528
529pub struct VolumeForkSearchesService {
531 inner: Arc<ClientInner>,
532}
533
534impl VolumeForkSearchesService {
535 pub async fn find(&self, volume_id: i64, fork_name: &str, opts: Option<&VolumeForkSearchListOptions>) -> Result<CursorPaginatedResponse<ForkTreeMatch>, Error> {
536 let mut query: Vec<(&str, String)> = Vec::new();
537 if let Some(opts) = opts {
538 if let Some(v) = &opts.q {
539 query.push(("q", v.to_string()));
540 }
541 if let Some(v) = &opts.path {
542 query.push(("path", v.to_string()));
543 }
544 if let Some(v) = &opts.as_of {
545 query.push(("asOf", v.to_string()));
546 }
547 if let Some(v) = &opts.exact {
548 query.push(("exact", v.to_string()));
549 }
550 if let Some(v) = &opts.cursor {
551 query.push(("cursor", v.to_string()));
552 }
553 if let Some(v) = &opts.limit {
554 query.push(("limit", v.to_string()));
555 }
556 if let Some(v) = &opts.kind {
557 query.push(("kind", v.to_string()));
558 }
559 }
560 self.inner.get(&format!("/api/v1/volumes/{}/forks/{}/search", volume_id, fork_name), &query).await
561 }
562}
563
564pub struct AuditLogsService {
566 inner: Arc<ClientInner>,
567}
568
569impl AuditLogsService {
570 pub async fn list(&self, opts: &AuditLogListOptions) -> Result<CursorPaginatedResponse<AuditLog>, Error> {
571 let mut query: Vec<(&str, String)> = Vec::new();
572 query.push(("accountId", opts.account_id.to_string()));
573 if let Some(v) = &opts.region_id {
574 query.push(("regionId", v.to_string()));
575 }
576 if let Some(v) = &opts.region_cluster_id {
577 query.push(("regionClusterId", v.to_string()));
578 }
579 if let Some(v) = &opts.cursor {
580 query.push(("cursor", v.to_string()));
581 }
582 if let Some(v) = &opts.limit {
583 query.push(("limit", v.to_string()));
584 }
585 if let Some(v) = &opts.subject {
586 query.push(("subject", v.to_string()));
587 }
588 self.inner.get("/api/v1/audit-logs/list", &query).await
589 }
590}
591
592pub struct RegionAuditLogsService {
594 inner: Arc<ClientInner>,
595}
596
597impl RegionAuditLogsService {
598 pub async fn list(&self, region_id: i64, opts: Option<&RegionAuditLogListOptions>) -> Result<CursorPaginatedResponse<AuditLog>, Error> {
599 let mut query: Vec<(&str, String)> = Vec::new();
600 if let Some(opts) = opts {
601 if let Some(v) = &opts.region_cluster_id {
602 query.push(("regionClusterId", v.to_string()));
603 }
604 if let Some(v) = &opts.cursor {
605 query.push(("cursor", v.to_string()));
606 }
607 if let Some(v) = &opts.limit {
608 query.push(("limit", v.to_string()));
609 }
610 if let Some(v) = &opts.subject {
611 query.push(("subject", v.to_string()));
612 }
613 if let Some(v) = &opts.node {
614 query.push(("node", v.to_string()));
615 }
616 }
617 self.inner.get(&format!("/api/v1/regions/{}/audit-logs/list", region_id), &query).await
618 }
619}
620
621pub struct ServiceNodesService {
623 inner: Arc<ClientInner>,
624}
625
626impl ServiceNodesService {
627 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> {
628 let mut query: Vec<(&str, String)> = Vec::new();
629 if let Some(v) = service_type {
630 query.push(("serviceType", v.to_string()));
631 }
632 if let Some(v) = status {
633 query.push(("status", v.to_string()));
634 }
635 if let Some(v) = inactive_hours {
636 query.push(("inactiveHours", v.to_string()));
637 }
638 if let Some(v) = region_cluster_id {
639 query.push(("regionClusterId", v.to_string()));
640 }
641 self.inner.get(&format!("/api/v1/regions/{}/nodes", region_id), &query).await
642 }
643
644 pub async fn stats(&self, region_id: i64, node_id: &str) -> Result<String, Error> {
645 self.inner.get(&format!("/api/v1/regions/{}/nodes/{}/stats", region_id, crate::http::encode_segment(node_id)), &[]).await
646 }
647}
648
649pub struct NodesService {
651 inner: Arc<ClientInner>,
652}
653
654impl NodesService {
655 pub async fn list_all(&self, account_id: i64, service_type: Option<&str>, status: Option<&str>, inactive_hours: Option<i64>) -> Result<Vec<ServiceNode>, Error> {
656 let mut query: Vec<(&str, String)> = Vec::new();
657 query.push(("accountId", account_id.to_string()));
658 if let Some(v) = service_type {
659 query.push(("serviceType", v.to_string()));
660 }
661 if let Some(v) = status {
662 query.push(("status", v.to_string()));
663 }
664 if let Some(v) = inactive_hours {
665 query.push(("inactiveHours", v.to_string()));
666 }
667 self.inner.get("/api/v1/nodes", &query).await
668 }
669}
670
671pub struct ClientSessionsService {
673 inner: Arc<ClientInner>,
674}
675
676impl ClientSessionsService {
677 pub async fn list(&self, opts: &ClientSessionListOptions) -> Result<PaginatedResponse<ClientSession>, Error> {
678 let mut query: Vec<(&str, String)> = Vec::new();
679 query.push(("accountId", opts.account_id.to_string()));
680 if let Some(v) = &opts.region_id {
681 query.push(("regionId", v.to_string()));
682 }
683 if let Some(v) = &opts.region_cluster_id {
684 query.push(("regionClusterId", v.to_string()));
685 }
686 if let Some(v) = &opts.volume_id {
687 query.push(("volumeId", v.to_string()));
688 }
689 if let Some(v) = &opts.user_id {
690 query.push(("userId", v.to_string()));
691 }
692 if let Some(v) = &opts.client_type {
693 query.push(("clientType", v.to_string()));
694 }
695 if let Some(v) = &opts.status {
696 query.push(("status", v.to_string()));
697 }
698 if let Some(v) = &opts.is_active {
699 query.push(("isActive", v.to_string()));
700 }
701 if let Some(v) = &opts.os_name {
702 query.push(("osName", v.to_string()));
703 }
704 if let Some(v) = &opts.platform {
705 query.push(("platform", v.to_string()));
706 }
707 if let Some(v) = &opts.search {
708 query.push(("search", v.to_string()));
709 }
710 if let Some(v) = &opts.page {
711 query.push(("page", v.to_string()));
712 }
713 if let Some(v) = &opts.limit {
714 query.push(("limit", v.to_string()));
715 }
716 self.inner.get("/api/v1/client-sessions/list", &query).await
717 }
718
719 pub async fn get(&self, session_id: i64) -> Result<ClientSession, Error> {
720 self.inner.get(&format!("/api/v1/client-sessions/{}", session_id), &[]).await
721 }
722
723 pub async fn summary(&self, account_id: i64, region_id: Option<i64>, region_cluster_id: Option<i64>, volume_id: Option<i64>, user_id: Option<i64>) -> Result<SessionSummary, Error> {
724 let mut query: Vec<(&str, String)> = Vec::new();
725 query.push(("accountId", account_id.to_string()));
726 if let Some(v) = region_id {
727 query.push(("regionId", v.to_string()));
728 }
729 if let Some(v) = region_cluster_id {
730 query.push(("regionClusterId", v.to_string()));
731 }
732 if let Some(v) = volume_id {
733 query.push(("volumeId", v.to_string()));
734 }
735 if let Some(v) = user_id {
736 query.push(("userId", v.to_string()));
737 }
738 self.inner.get("/api/v1/client-sessions/summary", &query).await
739 }
740}
741
742pub struct DiscoverService {
744 inner: Arc<ClientInner>,
745}
746
747impl DiscoverService {
748 pub async fn meta(&self, access_key_id: &str) -> Result<DiscoverMetaResponse, Error> {
749 let mut query: Vec<(&str, String)> = Vec::new();
750 query.push(("access_key_id", access_key_id.to_string()));
751 self.inner.get("/api/v1/discover/meta", &query).await
752 }
753}
754
755pub struct DashboardService {
757 inner: Arc<ClientInner>,
758}
759
760impl DashboardService {
761 pub async fn stats(&self, account_id: i64) -> Result<DashboardStats, Error> {
762 let mut query: Vec<(&str, String)> = Vec::new();
763 query.push(("accountId", account_id.to_string()));
764 self.inner.get("/api/v1/dashboard/stats", &query).await
765 }
766}
767
768pub struct LicenseService {
770 inner: Arc<ClientInner>,
771}
772
773impl LicenseService {
774 pub async fn get(&self) -> Result<LicenseDetails, Error> {
775 self.inner.get("/api/v1/license", &[]).await
776 }
777
778 pub async fn terms(&self) -> Result<LicenseTerms, Error> {
779 self.inner.get("/api/v1/license/terms", &[]).await
780 }
781}
782
783pub struct AlertsService {
785 inner: Arc<ClientInner>,
786}
787
788impl AlertsService {
789 pub async fn list(&self, opts: Option<&AlertListOptions>) -> Result<PaginatedResponse<ServiceAlert>, Error> {
790 let mut query: Vec<(&str, String)> = Vec::new();
791 if let Some(opts) = opts {
792 if let Some(v) = &opts.active {
793 query.push(("active", v.to_string()));
794 }
795 if let Some(v) = &opts.account_id {
796 query.push(("accountId", v.to_string()));
797 }
798 if let Some(v) = &opts.region_id {
799 query.push(("regionId", v.to_string()));
800 }
801 if let Some(v) = &opts.severity {
802 query.push(("severity", v.to_string()));
803 }
804 if let Some(v) = &opts.category {
805 query.push(("category", v.to_string()));
806 }
807 if let Some(v) = &opts.since {
808 query.push(("since", v.to_string()));
809 }
810 if let Some(v) = &opts.page {
811 query.push(("page", v.to_string()));
812 }
813 if let Some(v) = &opts.limit {
814 query.push(("limit", v.to_string()));
815 }
816 }
817 self.inner.get("/api/v1/alerts/list", &query).await
818 }
819
820 pub async fn count(&self) -> Result<AlertCountResponse, Error> {
821 self.inner.get("/api/v1/alerts/count", &[]).await
822 }
823
824 pub async fn resolve(&self, alert_id: &str) -> Result<(), Error> {
825 self.inner.post_empty::<serde_json::Value>(&format!("/api/v1/alerts/{}/resolve", alert_id)).await.map(|_| ())
826 }
827}
828
829pub struct RegionAlertsService {
831 inner: Arc<ClientInner>,
832}
833
834impl RegionAlertsService {
835 pub async fn list(&self, region_id: i64, opts: Option<&RegionAlertListOptions>) -> Result<PaginatedResponse<RegionAlert>, Error> {
836 let mut query: Vec<(&str, String)> = Vec::new();
837 if let Some(opts) = opts {
838 if let Some(v) = &opts.active {
839 query.push(("active", v.to_string()));
840 }
841 if let Some(v) = &opts.severity {
842 query.push(("severity", v.to_string()));
843 }
844 if let Some(v) = &opts.category {
845 query.push(("category", v.to_string()));
846 }
847 if let Some(v) = &opts.node_id {
848 query.push(("nodeId", v.to_string()));
849 }
850 if let Some(v) = &opts.region_cluster_id {
851 query.push(("regionClusterId", v.to_string()));
852 }
853 if let Some(v) = &opts.since {
854 query.push(("since", v.to_string()));
855 }
856 if let Some(v) = &opts.page {
857 query.push(("page", v.to_string()));
858 }
859 if let Some(v) = &opts.limit {
860 query.push(("limit", v.to_string()));
861 }
862 }
863 self.inner.get(&format!("/api/v1/regions/{}/alerts/list", region_id), &query).await
864 }
865
866 pub async fn count(&self, region_id: i64, region_cluster_id: Option<i64>) -> Result<AlertCountResponse, Error> {
867 let mut query: Vec<(&str, String)> = Vec::new();
868 if let Some(v) = region_cluster_id {
869 query.push(("regionClusterId", v.to_string()));
870 }
871 self.inner.get(&format!("/api/v1/regions/{}/alerts/count", region_id), &query).await
872 }
873
874 pub async fn resolve(&self, region_id: i64, alert_id: &str) -> Result<(), Error> {
875 self.inner.post_empty::<serde_json::Value>(&format!("/api/v1/regions/{}/alerts/{}/resolve", region_id, alert_id)).await.map(|_| ())
876 }
877}
878
879pub struct VaultService {
881 inner: Arc<ClientInner>,
882}
883
884impl VaultService {
885 pub async fn resync(&self) -> Result<(), Error> {
886 self.inner.post_empty::<serde_json::Value>("/api/v1/vault/resync").await.map(|_| ())
887 }
888}