-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubscriptions.rs
More file actions
1112 lines (937 loc) · 43.4 KB
/
subscriptions.rs
File metadata and controls
1112 lines (937 loc) · 43.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Subscription management for Pro (Flexible) plans
//!
//! This module provides comprehensive management of Redis Cloud Pro subscriptions,
//! which offer flexible, scalable Redis deployments with advanced features like
//! auto-scaling, multi-region support, and Active-Active configurations.
//!
//! # Overview
//!
//! Pro subscriptions are Redis Cloud's most flexible offering, supporting everything
//! from small development instances to large-scale production deployments with
//! automatic scaling, clustering, and global distribution.
//!
//! # Key Features
//!
//! - **Flexible Scaling**: Auto-scaling based on usage patterns
//! - **Multi-Region**: Deploy across multiple regions and cloud providers
//! - **Active-Active**: Global database replication with local reads/writes
//! - **Advanced Networking**: VPC peering, Transit Gateway, Private endpoints
//! - **Maintenance Windows**: Configurable maintenance scheduling
//! - **CIDR Management**: IP allowlist and security group configuration
//! - **Custom Pricing**: Usage-based pricing with detailed cost tracking
//!
//! # Subscription Types
//!
//! - **Single-Region**: Standard deployment in one region
//! - **Multi-Region**: Replicated across multiple regions
//! - **Active-Active**: CRDB with conflict-free replicated data types
//!
//! # Example Usage
//!
//! ```no_run
//! use redis_cloud::{CloudClient, SubscriptionHandler};
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let client = CloudClient::builder()
//! .api_key("your-api-key")
//! .api_secret("your-api-secret")
//! .build()?;
//!
//! let handler = SubscriptionHandler::new(client);
//!
//! // List all Pro subscriptions
//! let subscriptions = handler.get_all_subscriptions().await?;
//!
//! // Get subscription details (subscription ID 123)
//! let subscription = handler.get_subscription_by_id(123).await?;
//!
//! // Manage maintenance windows
//! let windows = handler.get_subscription_maintenance_windows(123).await?;
//! # Ok(())
//! # }
//! ```
use crate::types::{Link, ProcessorResponse};
use crate::{CloudClient, Result};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
use typed_builder::TypedBuilder;
// ============================================================================
// Models
// ============================================================================
/// Subscription update request message
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BaseSubscriptionUpdateRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription_id: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub command_type: Option<String>,
}
/// Subscription update request message
///
/// # Example
///
/// ```
/// use redis_cloud::flexible::subscriptions::SubscriptionUpdateRequest;
///
/// let request = SubscriptionUpdateRequest::builder()
/// .name("updated-subscription")
/// .build();
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionUpdateRequest {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
pub subscription_id: Option<i32>,
/// Optional. Updated subscription name.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub name: Option<String>,
/// Optional. The payment method ID you'd like to use for this subscription. Must be a valid payment method ID for this account. Use GET /payment-methods to get all payment methods for your account. This value is optional if 'paymentMethod' is 'marketplace', but required if 'paymentMethod' is 'credit-card'.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
pub payment_method_id: Option<i32>,
/// Optional. The payment method for the subscription. If set to 'credit-card' , 'paymentMethodId' must be defined.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub payment_method: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub command_type: Option<String>,
}
/// Cloud provider, region, and networking details.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionSpec {
/// Optional. Cloud provider. Default: 'AWS'
#[serde(skip_serializing_if = "Option::is_none")]
pub provider: Option<String>,
/// Optional. Cloud account identifier. Default: Redis internal cloud account (Cloud Account ID = 1). Use GET /cloud-accounts to list all available cloud accounts. Note: A subscription on Google Cloud can be created only with Redis internal cloud account.
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_account_id: Option<i32>,
/// The cloud provider region or list of regions (Active-Active only) and networking details.
pub regions: Vec<SubscriptionRegionSpec>,
}
/// Object representing a customer managed key (CMK), along with the region it is associated to.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CustomerManagedKey {
/// Required. Resource name of the customer managed key as defined by the cloud provider.
pub resource_name: String,
/// Name of region to for the customer managed key as defined by the cloud provider. Required for active-active subscriptions.
#[serde(skip_serializing_if = "Option::is_none")]
pub region: Option<String>,
}
/// Optional. Expected read and write throughput for this region.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LocalThroughput {
/// Specify one of the selected cloud provider regions for the subscription.
#[serde(skip_serializing_if = "Option::is_none")]
pub region: Option<String>,
/// Write operations for this region per second. Default: 1000 ops/sec
#[serde(skip_serializing_if = "Option::is_none")]
pub write_operations_per_second: Option<i64>,
/// Read operations for this region per second. Default: 1000 ops/sec
#[serde(skip_serializing_if = "Option::is_none")]
pub read_operations_per_second: Option<i64>,
}
/// List of databases in the subscription with local throughput details. Default: 1000 read and write ops/sec for each database
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CrdbRegionSpec {
/// Database name.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub local_throughput_measurement: Option<LocalThroughput>,
}
/// Subscription update request message
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionUpdateCMKRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription_id: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub command_type: Option<String>,
/// Optional. The grace period for deleting the subscription. If not set, will default to immediate deletion grace period.
#[serde(skip_serializing_if = "Option::is_none")]
pub deletion_grace_period: Option<String>,
/// The customer managed keys (CMK) to use for this subscription. If is active-active subscription, must set a key for each region.
pub customer_managed_keys: Vec<CustomerManagedKey>,
}
/// `SubscriptionPricings`
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubscriptionPricings {
#[serde(skip_serializing_if = "Option::is_none")]
pub pricing: Option<Vec<SubscriptionPricing>>,
}
/// Optional. Throughput measurement method.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatabaseThroughputSpec {
/// Throughput measurement method. Use 'operations-per-second' for all new databases.
pub by: String,
/// Throughput value in the selected measurement method.
pub value: i64,
}
/// Optional. Redis advanced capabilities (also known as modules) to be provisioned in the database. Use GET /database-modules to get a list of available advanced capabilities.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatabaseModuleSpec {
/// Redis advanced capability name. Use GET /database-modules for a list of available capabilities.
pub name: String,
/// Optional. Redis advanced capability parameters. Use GET /database-modules to get the available capabilities and their parameters.
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<HashMap<String, Value>>,
}
/// Update Pro subscription
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CidrAllowlistUpdateRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription_id: Option<i32>,
/// List of CIDR values. Example: ['10.1.1.0/32']
#[serde(skip_serializing_if = "Option::is_none")]
pub cidr_ips: Option<Vec<String>>,
/// List of AWS Security group IDs.
#[serde(skip_serializing_if = "Option::is_none")]
pub security_group_ids: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub command_type: Option<String>,
}
/// `SubscriptionMaintenanceWindowsSpec`
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubscriptionMaintenanceWindowsSpec {
/// Maintenance window mode: either 'manual' or 'automatic'. Must provide 'windows' if manual.
pub mode: String,
/// Maintenance window timeframes if mode is set to 'manual'. Up to 7 maintenance windows can be provided.
#[serde(skip_serializing_if = "Option::is_none")]
pub windows: Option<Vec<MaintenanceWindowSpec>>,
}
/// `MaintenanceWindowSkipStatus`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MaintenanceWindowSkipStatus {
#[serde(skip_serializing_if = "Option::is_none")]
pub remaining_skips: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub current_skip_end: Option<String>,
}
/// List of active-active subscription regions
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActiveActiveSubscriptionRegions {
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription_id: Option<i32>,
/// HATEOAS links
#[serde(skip_serializing_if = "Option::is_none")]
pub links: Option<Vec<Link>>,
}
/// `SubscriptionPricing`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionPricing {
/// Database name this pricing applies to
#[serde(skip_serializing_if = "Option::is_none")]
pub database_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub r#type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub type_details: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub quantity: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub quantity_measurement: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub price_per_unit: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub price_currency: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub price_period: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub region: Option<String>,
}
/// Request structure for creating a new Pro subscription
///
/// Defines configuration for flexible subscriptions including cloud providers,
/// regions, deployment type, and initial database specifications.
///
/// # Example
///
/// ```
/// use redis_cloud::flexible::subscriptions::{SubscriptionCreateRequest, SubscriptionSpec, SubscriptionDatabaseSpec, SubscriptionRegionSpec};
///
/// let request = SubscriptionCreateRequest::builder()
/// .name("my-subscription")
/// .cloud_providers(vec![
/// SubscriptionSpec {
/// provider: Some("AWS".to_string()),
/// cloud_account_id: Some(1),
/// regions: vec![SubscriptionRegionSpec {
/// region: "us-east-1".to_string(),
/// multiple_availability_zones: None,
/// preferred_availability_zones: None,
/// networking: None,
/// }],
/// }
/// ])
/// .databases(vec![
/// SubscriptionDatabaseSpec {
/// name: "my-database".to_string(),
/// protocol: "redis".to_string(),
/// memory_limit_in_gb: Some(1.0),
/// dataset_size_in_gb: None,
/// support_oss_cluster_api: None,
/// data_persistence: None,
/// replication: None,
/// throughput_measurement: None,
/// local_throughput_measurement: None,
/// modules: None,
/// quantity: None,
/// average_item_size_in_bytes: None,
/// resp_version: None,
/// redis_version: None,
/// sharding_type: None,
/// query_performance_factor: None,
/// }
/// ])
/// .build();
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionCreateRequest {
/// Optional. New subscription name.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub name: Option<String>,
/// Optional. When 'false': Creates a deployment plan and deploys it, creating any resources required by the plan. When 'true': creates a read-only deployment plan and does not create any resources. Default: 'false'
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
pub dry_run: Option<bool>,
/// Optional. When 'single-region' or not set: Creates a single region subscription. When 'active-active': creates an Active-Active (multi-region) subscription.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub deployment_type: Option<String>,
/// Optional. The payment method for the subscription. If set to 'credit-card', 'paymentMethodId' must be defined. Default: 'credit-card'
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub payment_method: Option<String>,
/// Optional. A valid payment method ID for this account. Use GET /payment-methods to get a list of all payment methods for your account. This value is optional if 'paymentMethod' is 'marketplace', but required for all other account types.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option))]
pub payment_method_id: Option<i32>,
/// Optional. Memory storage preference: either 'ram' or a combination of 'ram-and-flash' (also known as Auto Tiering). Default: 'ram'
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub memory_storage: Option<String>,
/// Optional. Persistent storage encryption secures data-at-rest for database persistence. You can use 'cloud-provider-managed-key' or 'customer-managed-key'. Default: 'cloud-provider-managed-key'
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub persistent_storage_encryption_type: Option<String>,
/// Cloud provider, region, and networking details.
pub cloud_providers: Vec<SubscriptionSpec>,
/// One or more database specification(s) to create in this subscription.
pub databases: Vec<SubscriptionDatabaseSpec>,
/// Optional. Defines the Redis version of the databases created in this specific request. It doesn't determine future databases associated with this subscription. If not set, databases will use the default Redis version. This field is deprecated and will be removed in a future API version - use the database-level redisVersion property instead.
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub redis_version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default, setter(strip_option, into))]
pub command_type: Option<String>,
}
/// Configuration regarding customer managed persistent storage encryption
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CustomerManagedKeyAccessDetails {
#[serde(skip_serializing_if = "Option::is_none")]
pub redis_service_account: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub google_predefined_roles: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub google_custom_permissions: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub redis_iam_role: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub required_key_policy_statements: Option<HashMap<String, Value>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub deletion_grace_period_options: Option<Vec<String>>,
}
/// One or more database specification(s) to create in this subscription.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionDatabaseSpec {
/// Name of the database. Database name is limited to 40 characters or less and must include only letters, digits, and hyphens ('-'). It must start with a letter and end with a letter or digit.
pub name: String,
/// Optional. Database protocol. Only set to 'memcached' if you have a legacy application. Default: 'redis'
pub protocol: String,
/// Optional. Total memory in GB, including replication and other overhead. You cannot set both datasetSizeInGb and totalMemoryInGb.
#[serde(skip_serializing_if = "Option::is_none")]
pub memory_limit_in_gb: Option<f64>,
/// Optional. The maximum amount of data in the dataset for this database in GB. You cannot set both datasetSizeInGb and totalMemoryInGb. If ‘replication’ is 'true', the database’s total memory will be twice as large as the datasetSizeInGb.If ‘replication’ is false, the database’s total memory will be the datasetSizeInGb value.
#[serde(skip_serializing_if = "Option::is_none")]
pub dataset_size_in_gb: Option<f64>,
/// Optional. Support Redis [OSS Cluster API](https://redis.io/docs/latest/operate/rc/databases/configuration/clustering/#oss-cluster-api). Default: 'false'
#[serde(skip_serializing_if = "Option::is_none")]
pub support_oss_cluster_api: Option<bool>,
/// Optional. Type and rate of data persistence in persistent storage. Default: 'none'
#[serde(skip_serializing_if = "Option::is_none")]
pub data_persistence: Option<String>,
/// Optional. Databases replication. Default: 'true'
#[serde(skip_serializing_if = "Option::is_none")]
pub replication: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub throughput_measurement: Option<DatabaseThroughputSpec>,
/// Optional. Expected throughput per region for an Active-Active database. Default: 1000 read and write ops/sec for each region
#[serde(skip_serializing_if = "Option::is_none")]
pub local_throughput_measurement: Option<Vec<LocalThroughput>>,
/// Optional. Redis advanced capabilities (also known as modules) to be provisioned in the database. Use GET /database-modules to get a list of available advanced capabilities.
#[serde(skip_serializing_if = "Option::is_none")]
pub modules: Option<Vec<DatabaseModuleSpec>>,
/// Optional. Number of databases that will be created with these settings. Default: 1
#[serde(skip_serializing_if = "Option::is_none")]
pub quantity: Option<i32>,
/// Optional. Relevant only to ram-and-flash (also known as Auto Tiering) subscriptions. Estimated average size in bytes of the items stored in the database. Default: 1000
#[serde(skip_serializing_if = "Option::is_none")]
pub average_item_size_in_bytes: Option<i64>,
/// Optional. Redis Serialization Protocol version. Must be compatible with Redis version.
#[serde(skip_serializing_if = "Option::is_none")]
pub resp_version: Option<String>,
/// Optional. If specified, redisVersion defines the Redis database version. If omitted, the Redis version will be set to the default version (available in 'GET /subscriptions/redis-versions')
#[serde(skip_serializing_if = "Option::is_none")]
pub redis_version: Option<String>,
/// Optional. Database [Hashing policy](https://redis.io/docs/latest/operate/rc/databases/configuration/clustering/#manage-the-hashing-policy).
#[serde(skip_serializing_if = "Option::is_none")]
pub sharding_type: Option<String>,
/// Optional. The query performance factor adds extra compute power specifically for search and query databases. You can increase your queries per second by the selected factor.
#[serde(skip_serializing_if = "Option::is_none")]
pub query_performance_factor: Option<String>,
}
/// Optional. Cloud networking details, per region. Required if creating an Active-Active subscription.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionRegionNetworkingSpec {
/// Optional. Deployment CIDR mask. Must be a valid CIDR format with a range of 256 IP addresses. Default for single-region subscriptions: If using Redis internal cloud account, 192.168.0.0/24
#[serde(skip_serializing_if = "Option::is_none")]
pub deployment_cidr: Option<String>,
/// Optional. Enter a VPC identifier that exists in the hosted AWS account. Creates a new VPC if not set. VPC Identifier must be in a valid format (for example: 'vpc-0125be68a4625884ad') and must exist within the hosting account.
#[serde(skip_serializing_if = "Option::is_none")]
pub vpc_id: Option<String>,
/// Optional. Enter a list of subnets identifiers that exists in the hosted AWS account. Subnet Identifier must exist within the hosting account.
#[serde(skip_serializing_if = "Option::is_none")]
pub subnet_ids: Option<Vec<String>>,
/// Optional. Enter a security group identifier that exists in the hosted AWS account. Security group Identifier must be in a valid format (for example: 'sg-0125be68a4625884ad') and must exist within the hosting account.
#[serde(skip_serializing_if = "Option::is_none")]
pub security_group_id: Option<String>,
}
/// `RedisVersion`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RedisVersion {
#[serde(skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub eol_date: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_preview: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub is_default: Option<bool>,
}
/// `MaintenanceWindow`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MaintenanceWindow {
#[serde(skip_serializing_if = "Option::is_none")]
pub days: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub start_hour: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub duration_in_hours: Option<i32>,
}
/// Cloud provider details for a subscription
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CloudDetail {
/// Cloud provider (e.g., "AWS", "GCP", "Azure")
#[serde(skip_serializing_if = "Option::is_none")]
pub provider: Option<String>,
/// Cloud account ID (Redis Cloud internal or BYOA)
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_account_id: Option<i32>,
/// AWS account ID (for AWS deployments)
#[serde(skip_serializing_if = "Option::is_none")]
pub aws_account_id: Option<String>,
/// Total size of the subscription in GB
#[serde(skip_serializing_if = "Option::is_none")]
pub total_size_in_gb: Option<f64>,
/// Regions configured for this cloud provider
#[serde(skip_serializing_if = "Option::is_none")]
pub regions: Option<Vec<SubscriptionRegion>>,
}
/// Region details in a subscription response
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionRegion {
/// Region name (e.g., "us-east-1")
#[serde(skip_serializing_if = "Option::is_none")]
pub region: Option<String>,
/// Networking configuration for this region
#[serde(skip_serializing_if = "Option::is_none")]
pub networking: Option<Vec<SubscriptionNetworking>>,
/// Preferred availability zones
#[serde(skip_serializing_if = "Option::is_none")]
pub preferred_availability_zones: Option<Vec<String>>,
/// Whether multiple availability zones are enabled
#[serde(skip_serializing_if = "Option::is_none")]
pub multiple_availability_zones: Option<bool>,
}
/// Networking configuration in a subscription region
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionNetworking {
/// Deployment CIDR
#[serde(skip_serializing_if = "Option::is_none")]
pub deployment_cidr: Option<String>,
/// VPC ID
#[serde(skip_serializing_if = "Option::is_none")]
pub vpc_id: Option<String>,
/// Subnet ID
#[serde(skip_serializing_if = "Option::is_none")]
pub subnet_id: Option<String>,
}
/// `RedisLabs` Subscription information
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
/// Subscription
///
/// Represents a Redis Cloud subscription with all known API fields as first-class struct members.
/// The `extra` field is reserved only for truly unknown/future fields that may be added to the API.
pub struct Subscription {
/// Subscription ID
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<i32>,
/// Subscription name
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// Subscription status (e.g., "active", "pending", "error")
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
/// Payment method ID
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_method_id: Option<i32>,
/// Payment method type (e.g., "credit-card", "marketplace")
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_method_type: Option<String>,
/// Payment method (e.g., "credit-card", "marketplace")
#[serde(skip_serializing_if = "Option::is_none")]
pub payment_method: Option<String>,
/// Memory storage type: "ram" or "ram-and-flash" (Auto Tiering)
#[serde(skip_serializing_if = "Option::is_none")]
pub memory_storage: Option<String>,
/// Persistent storage encryption type
#[serde(skip_serializing_if = "Option::is_none")]
pub persistent_storage_encryption_type: Option<String>,
/// Deployment type: "single-region" or "active-active"
#[serde(skip_serializing_if = "Option::is_none")]
pub deployment_type: Option<String>,
/// Number of databases in this subscription
#[serde(skip_serializing_if = "Option::is_none")]
pub number_of_databases: Option<i32>,
/// Cloud provider details (AWS, GCP, Azure configurations)
#[serde(skip_serializing_if = "Option::is_none")]
pub cloud_details: Option<Vec<CloudDetail>>,
/// Pricing details for the subscription
#[serde(skip_serializing_if = "Option::is_none")]
pub pricing: Option<Vec<SubscriptionPricing>>,
/// Redis version for databases created in this subscription (deprecated)
#[serde(skip_serializing_if = "Option::is_none")]
pub redis_version: Option<String>,
/// Deletion grace period for customer-managed keys
#[serde(skip_serializing_if = "Option::is_none")]
pub deletion_grace_period: Option<String>,
/// Customer-managed key access details for encryption
#[serde(skip_serializing_if = "Option::is_none")]
pub customer_managed_key_access_details: Option<CustomerManagedKeyAccessDetails>,
/// Whether storage encryption is enabled
#[serde(skip_serializing_if = "Option::is_none")]
pub storage_encryption: Option<bool>,
/// Whether public endpoint access is enabled
#[serde(skip_serializing_if = "Option::is_none")]
pub public_endpoint_access: Option<bool>,
/// Timestamp when subscription was created
#[serde(skip_serializing_if = "Option::is_none")]
pub created_timestamp: Option<String>,
/// HATEOAS links for API navigation
#[serde(skip_serializing_if = "Option::is_none")]
pub links: Option<Vec<Link>>,
}
/// Maintenance window timeframes if mode is set to 'manual'. Up to 7 maintenance windows can be provided.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MaintenanceWindowSpec {
/// Starting hour of the maintenance window. Can be between '0' (12 AM in the deployment region's local time) and '23' (11 PM in the deployment region's local time).
pub start_hour: i32,
/// The duration of the maintenance window in hours. Can be between 4-24 hours (or 8-24 hours if using 'ram-and-flash').
pub duration_in_hours: i32,
/// Days where this maintenance window applies. Can contain one or more of: "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", or "Sunday".
pub days: Vec<String>,
}
/// `RedisLabs` list of subscriptions in current account
///
/// Response from GET /subscriptions
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct AccountSubscriptions {
/// Account ID
#[serde(skip_serializing_if = "Option::is_none")]
pub account_id: Option<i32>,
/// List of subscriptions (typically in extra as 'subscriptions' array)
#[serde(skip_serializing_if = "Option::is_none")]
pub subscriptions: Option<Vec<Subscription>>,
/// HATEOAS links for API navigation
#[serde(skip_serializing_if = "Option::is_none")]
pub links: Option<Vec<Link>>,
}
/// Active active region creation request message
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActiveActiveRegionCreateRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription_id: Option<i32>,
/// Name of region to add as defined by the cloud provider.
#[serde(skip_serializing_if = "Option::is_none")]
pub region: Option<String>,
/// Optional. Enter a VPC identifier that exists in the hosted AWS account. Creates a new VPC if not set. VPC Identifier must be in a valid format and must exist within the hosting account.
#[serde(skip_serializing_if = "Option::is_none")]
pub vpc_id: Option<String>,
/// Deployment CIDR mask. Must be a valid CIDR format with a range of 256 IP addresses.
pub deployment_cidr: String,
/// Optional. When 'false': Creates a deployment plan and deploys it, creating any resources required by the plan. When 'true': creates a read-only deployment plan, and does not create any resources. Default: 'false'
#[serde(skip_serializing_if = "Option::is_none")]
pub dry_run: Option<bool>,
/// List of databases in the subscription with local throughput details. Default: 1000 read and write ops/sec for each database
#[serde(skip_serializing_if = "Option::is_none")]
pub databases: Option<Vec<CrdbRegionSpec>>,
/// Optional. RESP version must be compatible with Redis version.
#[serde(skip_serializing_if = "Option::is_none")]
pub resp_version: Option<String>,
/// Optional. Resource name of the customer managed key as defined by the cloud provider for customer managed subscriptions.
#[serde(skip_serializing_if = "Option::is_none")]
pub customer_managed_key_resource_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub command_type: Option<String>,
}
/// `RedisVersions`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RedisVersions {
#[serde(skip_serializing_if = "Option::is_none")]
pub redis_versions: Option<Vec<RedisVersion>>,
}
/// Active active region deletion request message
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActiveActiveRegionDeleteRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub subscription_id: Option<i32>,
/// The names of the regions to delete.
#[serde(skip_serializing_if = "Option::is_none")]
pub regions: Option<Vec<ActiveActiveRegionToDelete>>,
/// Optional. When 'false': Creates a deployment plan and deploys it, deleting any resources required by the plan. When 'true': creates a read-only deployment plan and does not delete or modify any resources. Default: 'false'
#[serde(skip_serializing_if = "Option::is_none")]
pub dry_run: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub command_type: Option<String>,
}
/// The names of the regions to delete.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ActiveActiveRegionToDelete {
/// Name of the cloud provider region to delete.
#[serde(skip_serializing_if = "Option::is_none")]
pub region: Option<String>,
}
/// `TaskStateUpdate`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TaskStateUpdate {
#[serde(skip_serializing_if = "Option::is_none")]
pub task_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub command_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timestamp: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub response: Option<ProcessorResponse>,
/// HATEOAS links
#[serde(skip_serializing_if = "Option::is_none")]
pub links: Option<Vec<Link>>,
}
/// The cloud provider region or list of regions (Active-Active only) and networking details.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionRegionSpec {
/// Deployment region as defined by the cloud provider.
pub region: String,
/// Optional. Support deployment on multiple availability zones within the selected region. Default: 'false'
#[serde(skip_serializing_if = "Option::is_none")]
pub multiple_availability_zones: Option<bool>,
/// Optional. List the zone ID(s) for your preferred availability zone(s) for the cloud provider and region. If ‘multipleAvailabilityZones’ is set to 'true', you must list three availability zones. Otherwise, list one availability zone.
#[serde(skip_serializing_if = "Option::is_none")]
pub preferred_availability_zones: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub networking: Option<SubscriptionRegionNetworkingSpec>,
}
/// `SubscriptionMaintenanceWindows`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionMaintenanceWindows {
#[serde(skip_serializing_if = "Option::is_none")]
pub mode: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub time_zone: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub windows: Option<Vec<MaintenanceWindow>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub skip_status: Option<MaintenanceWindowSkipStatus>,
}
// ============================================================================
// Handler
// ============================================================================
/// Handler for Pro subscription operations
///
/// Manages flexible subscriptions with auto-scaling, multi-region support,
/// Active-Active configurations, and advanced networking features.
pub struct SubscriptionHandler {
client: CloudClient,
}
impl SubscriptionHandler {
/// Create a new handler
#[must_use]
pub fn new(client: CloudClient) -> Self {
Self { client }
}
/// Get Pro subscriptions
///
/// Gets a list of all Pro subscriptions in the current account.
///
/// GET /subscriptions
///
/// # Example
///
/// ```no_run
/// use redis_cloud::CloudClient;
///
/// # async fn example() -> redis_cloud::Result<()> {
/// let client = CloudClient::builder()
/// .api_key("your-api-key")
/// .api_secret("your-api-secret")
/// .build()?;
///
/// let subscriptions = client.subscriptions().get_all_subscriptions().await?;
///
/// // Access subscription data
/// if let Some(subs) = &subscriptions.subscriptions {
/// println!("Found {} subscriptions", subs.len());
/// }
/// # Ok(())
/// # }
/// ```
pub async fn get_all_subscriptions(&self) -> Result<AccountSubscriptions> {
self.client.get("/subscriptions").await
}
/// Create Pro subscription
/// Creates a new Redis Cloud Pro subscription.
///
/// POST /subscriptions
pub async fn create_subscription(
&self,
request: &SubscriptionCreateRequest,
) -> Result<TaskStateUpdate> {
self.client.post("/subscriptions", request).await
}
/// Get available Redis database versions
/// Gets a list of all available Redis database versions for Pro subscriptions.
///
/// GET /subscriptions/redis-versions
pub async fn get_redis_versions(&self, subscription_id: Option<i32>) -> Result<RedisVersions> {
let mut query = Vec::new();
if let Some(v) = subscription_id {
query.push(format!("subscriptionId={v}"));
}
let query_string = if query.is_empty() {
String::new()
} else {
format!("?{}", query.join("&"))
};
self.client
.get(&format!("/subscriptions/redis-versions{query_string}"))
.await
}
/// Delete Pro subscription
/// Delete the specified Pro subscription. All databases in the subscription must be deleted before deleting it.
///
/// DELETE /subscriptions/{subscriptionId}
pub async fn delete_subscription_by_id(&self, subscription_id: i32) -> Result<TaskStateUpdate> {
let response = self
.client
.delete_raw(&format!("/subscriptions/{subscription_id}"))
.await?;
serde_json::from_value(response).map_err(Into::into)
}
/// Get a single Pro subscription
///
/// Gets information on the specified Pro subscription.
///
/// GET /subscriptions/{subscriptionId}
///
/// # Example
///
/// ```no_run
/// use redis_cloud::CloudClient;
///
/// # async fn example() -> redis_cloud::Result<()> {
/// let client = CloudClient::builder()
/// .api_key("your-api-key")
/// .api_secret("your-api-secret")
/// .build()?;
///
/// let subscription = client.subscriptions().get_subscription_by_id(123).await?;
///
/// println!("Subscription: {} (status: {:?})",
/// subscription.name.unwrap_or_default(),
/// subscription.status);
/// # Ok(())
/// # }
/// ```
pub async fn get_subscription_by_id(&self, subscription_id: i32) -> Result<Subscription> {
self.client
.get(&format!("/subscriptions/{subscription_id}"))
.await
}
/// Update Pro subscription
/// Updates the specified Pro subscription.
///
/// PUT /subscriptions/{subscriptionId}
pub async fn update_subscription(
&self,
subscription_id: i32,
request: &BaseSubscriptionUpdateRequest,
) -> Result<TaskStateUpdate> {
self.client
.put(&format!("/subscriptions/{subscription_id}"), request)
.await
}
/// Get Pro subscription CIDR allowlist
/// (Self-hosted AWS subscriptions only) Gets a Pro subscription's CIDR allowlist.
///
/// GET /subscriptions/{subscriptionId}/cidr