redis_cloud/lib.rs
1// Allow doc strings with quoted values like 'true'/'false' from OpenAPI spec
2#![allow(clippy::doc_link_with_quotes)]
3
4//! Redis Cloud REST API Client
5//!
6//! A comprehensive Rust client for the Redis Cloud REST API, providing full access to
7//! subscription management, database operations, billing, monitoring, and advanced features
8//! like VPC peering, SSO/SAML, and Private Service Connect.
9//!
10//! ## Features
11//!
12//! - **Subscription Management**: Create, update, delete subscriptions across AWS, GCP, Azure
13//! - **Database Operations**: Full CRUD operations, backups, imports, metrics
14//! - **Advanced Networking**: VPC peering, Transit Gateway, Private Service Connect
15//! - **Security & Access**: ACLs, SSO/SAML integration, API key management
16//! - **Monitoring & Billing**: Comprehensive metrics, logs, billing and payment management
17//! - **Enterprise Features**: Active-Active databases (CRDB), fixed/essentials plans
18//!
19//! ## Quick Start
20//!
21//! ```rust,no_run
22//! use redis_cloud::{CloudClient, DatabaseHandler};
23//!
24//! #[tokio::main]
25//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
26//! // Create client with API credentials
27//! let client = CloudClient::builder()
28//! .api_key("your-api-key")
29//! .api_secret("your-api-secret")
30//! .build()?;
31//!
32//! // List all databases
33//! let db_handler = DatabaseHandler::new(client.clone());
34//! let databases = db_handler.get_subscription_databases(123, None, None).await?;
35//! println!("Found databases: {:?}", databases);
36//!
37//! Ok(())
38//! }
39//! ```
40//!
41//! ## Core Usage Patterns
42//!
43//! ### Client Creation
44//!
45//! The client uses a builder pattern for flexible configuration:
46//!
47//! ```rust,no_run
48//! use redis_cloud::CloudClient;
49//!
50//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
51//! // Basic client with default settings
52//! let client = CloudClient::builder()
53//! .api_key("your-api-key")
54//! .api_secret("your-api-secret")
55//! .build()?;
56//!
57//! // Custom configuration
58//! let client2 = CloudClient::builder()
59//! .api_key("your-api-key")
60//! .api_secret("your-api-secret")
61//! .base_url("https://api.redislabs.com/v1".to_string())
62//! .timeout(std::time::Duration::from_secs(60))
63//! .build()?;
64//! # Ok(())
65//! # }
66//! ```
67//!
68//! ### Typed vs Raw API
69//!
70//! This client offers typed handlers for common operations as well as raw helpers when you
71//! need full control over request/response payloads:
72//!
73//! - Prefer typed handlers (e.g., `CloudDatabaseHandler`) for structured, ergonomic access.
74//! - Use raw helpers for passthroughs: `get_raw`, `post_raw`, `put_raw`, `patch_raw`, `delete_raw`.
75//!
76//! ```rust,no_run
77//! use redis_cloud::CloudClient;
78//! use serde_json::json;
79//!
80//! # #[tokio::main]
81//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
82//! let client = CloudClient::builder()
83//! .api_key("key")
84//! .api_secret("secret")
85//! .build()?;
86//!
87//! // Raw call example
88//! let created = client.post_raw("/subscriptions", json!({ "name": "example" })).await?;
89//! println!("{}", created);
90//! # Ok(())
91//! # }
92//! ```
93//!
94//! ### Working with Subscriptions
95//!
96//! ```rust,no_run
97//! use redis_cloud::{CloudClient, SubscriptionHandler};
98//! use serde_json::json;
99//!
100//! # #[tokio::main]
101//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
102//! let client = CloudClient::builder()
103//! .api_key("key")
104//! .api_secret("secret")
105//! .build()?;
106//!
107//! let sub_handler = SubscriptionHandler::new(client.clone());
108//!
109//! // List subscriptions
110//! let subscriptions = sub_handler.get_all_subscriptions().await?;
111//!
112//! // Create a new subscription using raw API
113//! let new_subscription = json!({
114//! "name": "my-redis-subscription",
115//! "provider": "AWS",
116//! "region": "us-east-1",
117//! "plan": "cache.m5.large"
118//! });
119//! let created = client.post_raw("/subscriptions", new_subscription).await?;
120//! # Ok(())
121//! # }
122//! ```
123//!
124//! ### Database Management
125//!
126//! ```rust,no_run
127//! use redis_cloud::{CloudClient, DatabaseHandler};
128//! use serde_json::json;
129//!
130//! # #[tokio::main]
131//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
132//! let client = CloudClient::builder()
133//! .api_key("key")
134//! .api_secret("secret")
135//! .build()?;
136//!
137//! let db_handler = DatabaseHandler::new(client.clone());
138//!
139//! // Create database using raw API
140//! let database_config = json!({
141//! "name": "my-database",
142//! "memoryLimitInGb": 1.0,
143//! "support_oss_cluster_api": false,
144//! "replication": true
145//! });
146//! let database = client.post_raw("/subscriptions/123/databases", database_config).await?;
147//!
148//! // Get database info
149//! let db_info = db_handler.get_subscription_database_by_id(123, 456).await?;
150//! # Ok(())
151//! # }
152//! ```
153//!
154//! ### Advanced Features
155//!
156//! #### VPC Peering
157//! ```rust,no_run
158//! use redis_cloud::{CloudClient, ConnectivityHandler};
159//! use serde_json::json;
160//!
161//! # #[tokio::main]
162//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
163//! let client = CloudClient::builder()
164//! .api_key("key")
165//! .api_secret("secret")
166//! .build()?;
167//!
168//! let peering_handler = ConnectivityHandler::new(client.clone());
169//!
170//! let peering_request = json!({
171//! "aws_account_id": "123456789012",
172//! "vpc_id": "vpc-12345678",
173//! "vpc_cidr": "10.0.0.0/16",
174//! "region": "us-east-1"
175//! });
176//! let peering = client.post_raw("/subscriptions/123/peerings", peering_request).await?;
177//! # Ok(())
178//! # }
179//! ```
180//!
181//! #### SSO/SAML Management
182//! ```rust,no_run
183//! use redis_cloud::{CloudClient, AccountHandler};
184//! use serde_json::json;
185//!
186//! # #[tokio::main]
187//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
188//! let client = CloudClient::builder()
189//! .api_key("key")
190//! .api_secret("secret")
191//! .build()?;
192//!
193//! let sso_handler = AccountHandler::new(client.clone());
194//!
195//! // Configure SSO using raw API
196//! let sso_config = json!({
197//! "enabled": true,
198//! "auto_provision": true
199//! });
200//! let config = client.put_raw("/sso", sso_config).await?;
201//! # Ok(())
202//! # }
203//! ```
204//!
205//! #### API Keys (Typed)
206//! ```rust,no_run
207//! use redis_cloud::{CloudClient, AccountHandler};
208//! use serde_json::json;
209//!
210//! # #[tokio::main]
211//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
212//! let client = CloudClient::builder()
213//! .api_key("key")
214//! .api_secret("secret")
215//! .build()?;
216//!
217//! let account = AccountHandler::new(client.clone());
218//! let account_info = account.get_current_account().await?;
219//! # Ok(())
220//! # }
221//! ```
222//!
223//! ## Error Handling
224//!
225//! The client provides comprehensive error handling for different failure scenarios:
226//!
227//! ```rust,no_run
228//! use redis_cloud::{CloudClient, CloudError, DatabaseHandler};
229//!
230//! # #[tokio::main]
231//! # async fn main() {
232//! let client = CloudClient::builder()
233//! .api_key("key")
234//! .api_secret("secret")
235//! .build().unwrap();
236//!
237//! let db_handler = DatabaseHandler::new(client.clone());
238//!
239//! match db_handler.get_subscription_database_by_id(123, 456).await {
240//! Ok(database) => println!("Database: {:?}", database),
241//! Err(CloudError::ApiError { code: 404, .. }) => {
242//! println!("Database not found");
243//! },
244//! Err(CloudError::AuthenticationFailed { message }) => {
245//! println!("Invalid API credentials");
246//! },
247//! Err(e) => println!("Other error: {}", e),
248//! }
249//! # }
250//! ```
251//!
252//! ## Handler Overview
253//!
254//! The client provides specialized handlers for different API domains:
255//!
256//! | Handler | Purpose | Key Operations |
257//! |---------|---------|----------------|
258//! | [`SubscriptionHandler`] | Pro subscriptions | create, list, update, delete, pricing |
259//! | [`FixedSubscriptionHandler`] | Essentials subscriptions | fixed plans, create, update, delete |
260//! | [`DatabaseHandler`] | Pro databases | create, backup, import, metrics, resize |
261//! | [`FixedDatabaseHandler`] | Essentials databases | fixed capacity, backup, import |
262//! | [`AccountHandler`] | Account management | info, API keys, payment methods, SSO |
263//! | [`UserHandler`] | User management | create, update, delete, invite, roles |
264//! | [`AclHandler`] | Access control | users, roles, Redis rules, database ACLs |
265//! | [`ConnectivityHandler`] | Network connectivity | VPC peering, Transit Gateway, PSC |
266//! | [`CloudAccountHandler`] | Cloud providers | AWS, GCP, Azure account integration |
267//! | [`TaskHandler`] | Async operations | track long-running operations |
268//!
269//! ## Authentication
270//!
271//! Redis Cloud uses API key authentication with two required headers:
272//! - `x-api-key`: Your API key
273//! - `x-api-secret-key`: Your API secret
274//!
275//! These credentials can be obtained from the Redis Cloud console under Account Settings > API Keys.
276//!
277//! Environment variables commonly used with this client:
278//! - `REDIS_CLOUD_API_KEY`
279//! - `REDIS_CLOUD_API_SECRET`
280//! - Optional: set a custom base URL via the builder for non‑prod/test environments (defaults to `https://api.redislabs.com/v1`).
281
282pub mod client;
283pub mod error;
284
285#[cfg(test)]
286mod lib_tests;
287
288// Re-export client types
289pub use client::{CloudClient, CloudClientBuilder};
290
291// Re-export error types
292pub use error::{CloudError, Result};
293
294// Re-export Tower integration when feature is enabled
295#[cfg(feature = "tower-integration")]
296pub use client::tower_support;
297
298// Test support module - only available with test-support feature
299#[cfg(feature = "test-support")]
300pub mod testing;
301
302// Types module for shared models
303pub mod types;
304
305// Handler modules - each handles a specific API domain
306pub mod account;
307pub mod acl;
308pub mod cloud_accounts;
309pub mod connectivity;
310pub mod cost_report;
311pub mod fixed;
312pub mod flexible;
313pub mod tasks;
314pub mod users;
315
316// Backward compatibility module aliases
317pub use fixed::databases as fixed_databases;
318pub use fixed::subscriptions as fixed_subscriptions;
319pub use flexible::databases;
320pub use flexible::subscriptions;
321
322// Re-export handlers with standard naming
323pub use account::AccountHandler;
324pub use acl::AclHandler;
325pub use cloud_accounts::CloudAccountsHandler as CloudAccountHandler;
326
327// Connectivity handlers
328pub use connectivity::private_link::PrivateLinkHandler;
329pub use connectivity::psc::PscHandler;
330pub use connectivity::transit_gateway::TransitGatewayHandler;
331pub use connectivity::vpc_peering::VpcPeeringHandler;
332// Connectivity types
333pub use connectivity::{PrincipalType, PrivateLinkAddPrincipalRequest, PrivateLinkCreateRequest};
334// Legacy connectivity export for backward compatibility
335pub use connectivity::ConnectivityHandler;
336
337// Fixed plan handlers
338pub use fixed::databases::FixedDatabaseHandler;
339pub use fixed::subscriptions::FixedSubscriptionHandler;
340// Legacy exports for backward compatibility
341pub use fixed::databases::FixedDatabaseHandler as FixedDatabasesHandler;
342pub use fixed::subscriptions::FixedSubscriptionHandler as FixedSubscriptionsHandler;
343
344// Flexible plan handlers (pay-as-you-go)
345pub use flexible::databases::DatabaseHandler;
346pub use flexible::subscriptions::SubscriptionHandler;
347// Legacy exports for backward compatibility
348pub use flexible::databases::DatabaseHandler as DatabasesHandler;
349pub use flexible::subscriptions::SubscriptionHandler as SubscriptionsHandler;
350
351pub use cost_report::CostReportHandler;
352pub use cost_report::{CostReportCreateRequest, CostReportFormat, SubscriptionType, Tag};
353pub use tasks::TasksHandler as TaskHandler;
354pub use users::UsersHandler as UserHandler;