redis_cloud/connectivity/
psc.rs

1//! Private Service Connect (PSC) operations
2//!
3//! Manages Google Cloud Private Service Connect endpoints for secure connectivity
4//! to Redis Cloud databases without traversing the public internet.
5
6use crate::{CloudClient, Result};
7use serde::{Deserialize, Serialize};
8
9/// Private Service Connect endpoint update request
10#[derive(Debug, Clone, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct PscEndpointUpdateRequest {
13    pub subscription_id: i32,
14    pub psc_service_id: i32,
15    pub endpoint_id: i32,
16
17    /// Google Cloud project ID
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub gcp_project_id: Option<String>,
20
21    /// Name of the Google Cloud VPC that hosts your application
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub gcp_vpc_name: Option<String>,
24
25    /// Name of your VPC's subnet of IP address ranges
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub gcp_vpc_subnet_name: Option<String>,
28
29    /// Prefix used to create PSC endpoints in the consumer application VPC
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub endpoint_connection_name: Option<String>,
32}
33
34/// Task state update response
35pub use crate::types::TaskStateUpdate;
36
37/// Private Service Connect handler
38pub struct PscHandler {
39    client: CloudClient,
40}
41
42impl PscHandler {
43    /// Create a new PSC handler
44    pub fn new(client: CloudClient) -> Self {
45        Self { client }
46    }
47
48    // ========================================================================
49    // Standard PSC Operations
50    // ========================================================================
51
52    /// Delete Private Service Connect service
53    pub async fn delete_service(&self, subscription_id: i32) -> Result<serde_json::Value> {
54        self.client
55            .delete(&format!(
56                "/subscriptions/{}/private-service-connect",
57                subscription_id
58            ))
59            .await?;
60        Ok(serde_json::Value::Null)
61    }
62
63    /// Get Private Service Connect service
64    pub async fn get_service(&self, subscription_id: i32) -> Result<TaskStateUpdate> {
65        self.client
66            .get(&format!(
67                "/subscriptions/{}/private-service-connect",
68                subscription_id
69            ))
70            .await
71    }
72
73    /// Create Private Service Connect service
74    pub async fn create_service(&self, subscription_id: i32) -> Result<TaskStateUpdate> {
75        self.client
76            .post(
77                &format!("/subscriptions/{}/private-service-connect", subscription_id),
78                &serde_json::json!({}),
79            )
80            .await
81    }
82
83    /// Get Private Service Connect endpoints
84    pub async fn get_endpoints(&self, subscription_id: i32) -> Result<TaskStateUpdate> {
85        self.client
86            .get(&format!(
87                "/subscriptions/{}/private-service-connect/endpoints",
88                subscription_id
89            ))
90            .await
91    }
92
93    /// Create Private Service Connect endpoint
94    pub async fn create_endpoint(
95        &self,
96        subscription_id: i32,
97        request: &PscEndpointUpdateRequest,
98    ) -> Result<TaskStateUpdate> {
99        self.client
100            .post(
101                &format!(
102                    "/subscriptions/{}/private-service-connect/endpoints",
103                    subscription_id
104                ),
105                request,
106            )
107            .await
108    }
109
110    /// Delete Private Service Connect endpoint
111    pub async fn delete_endpoint(
112        &self,
113        subscription_id: i32,
114        endpoint_id: i32,
115    ) -> Result<serde_json::Value> {
116        self.client
117            .delete(&format!(
118                "/subscriptions/{}/private-service-connect/endpoints/{}",
119                subscription_id, endpoint_id
120            ))
121            .await?;
122        Ok(serde_json::Value::Null)
123    }
124
125    /// Update Private Service Connect endpoint
126    pub async fn update_endpoint(
127        &self,
128        subscription_id: i32,
129        endpoint_id: i32,
130        request: &PscEndpointUpdateRequest,
131    ) -> Result<TaskStateUpdate> {
132        // Use psc_service_id from request
133        let psc_service_id = request.psc_service_id;
134        self.client
135            .put(
136                &format!(
137                    "/subscriptions/{}/private-service-connect/{}/endpoints/{}",
138                    subscription_id, psc_service_id, endpoint_id
139                ),
140                request,
141            )
142            .await
143    }
144
145    /// Get PSC endpoint creation script
146    pub async fn get_endpoint_creation_script(
147        &self,
148        subscription_id: i32,
149        endpoint_id: i32,
150    ) -> Result<String> {
151        self.client
152            .get(&format!(
153                "/subscriptions/{}/private-service-connect/endpoints/{}/creationScripts",
154                subscription_id, endpoint_id
155            ))
156            .await
157    }
158
159    /// Get PSC endpoint deletion script
160    pub async fn get_endpoint_deletion_script(
161        &self,
162        subscription_id: i32,
163        endpoint_id: i32,
164    ) -> Result<String> {
165        self.client
166            .get(&format!(
167                "/subscriptions/{}/private-service-connect/endpoints/{}/deletionScripts",
168                subscription_id, endpoint_id
169            ))
170            .await
171    }
172
173    // ========================================================================
174    // Active-Active PSC Operations
175    // ========================================================================
176
177    /// Delete Active-Active PSC service
178    pub async fn delete_service_active_active(
179        &self,
180        subscription_id: i32,
181    ) -> Result<serde_json::Value> {
182        self.client
183            .delete(&format!(
184                "/subscriptions/{}/regions/private-service-connect",
185                subscription_id
186            ))
187            .await?;
188        Ok(serde_json::Value::Null)
189    }
190
191    /// Get Active-Active PSC service
192    pub async fn get_service_active_active(&self, subscription_id: i32) -> Result<TaskStateUpdate> {
193        self.client
194            .get(&format!(
195                "/subscriptions/{}/regions/private-service-connect",
196                subscription_id
197            ))
198            .await
199    }
200
201    /// Create Active-Active PSC service
202    pub async fn create_service_active_active(
203        &self,
204        subscription_id: i32,
205    ) -> Result<TaskStateUpdate> {
206        self.client
207            .post(
208                &format!(
209                    "/subscriptions/{}/regions/private-service-connect",
210                    subscription_id
211                ),
212                &serde_json::json!({}),
213            )
214            .await
215    }
216
217    /// Get Active-Active PSC endpoints
218    pub async fn get_endpoints_active_active(
219        &self,
220        subscription_id: i32,
221    ) -> Result<TaskStateUpdate> {
222        self.client
223            .get(&format!(
224                "/subscriptions/{}/regions/private-service-connect/endpoints",
225                subscription_id
226            ))
227            .await
228    }
229
230    /// Create Active-Active PSC endpoint
231    pub async fn create_endpoint_active_active(
232        &self,
233        subscription_id: i32,
234        request: &PscEndpointUpdateRequest,
235    ) -> Result<TaskStateUpdate> {
236        self.client
237            .post(
238                &format!(
239                    "/subscriptions/{}/regions/private-service-connect/endpoints",
240                    subscription_id
241                ),
242                request,
243            )
244            .await
245    }
246
247    /// Delete Active-Active PSC endpoint
248    pub async fn delete_endpoint_active_active(
249        &self,
250        subscription_id: i32,
251        region_id: i32,
252        endpoint_id: i32,
253    ) -> Result<serde_json::Value> {
254        self.client
255            .delete(&format!(
256                "/subscriptions/{}/regions/{}/private-service-connect/endpoints/{}",
257                subscription_id, region_id, endpoint_id
258            ))
259            .await?;
260        Ok(serde_json::Value::Null)
261    }
262
263    /// Update Active-Active PSC endpoint
264    pub async fn update_endpoint_active_active(
265        &self,
266        subscription_id: i32,
267        region_id: i32,
268        endpoint_id: i32,
269        request: &PscEndpointUpdateRequest,
270    ) -> Result<TaskStateUpdate> {
271        self.client
272            .put(
273                &format!(
274                    "/subscriptions/{}/regions/{}/private-service-connect/{}/endpoints/{}",
275                    subscription_id, region_id, subscription_id, endpoint_id
276                ),
277                request,
278            )
279            .await
280    }
281
282    /// Get Active-Active PSC endpoint creation script
283    pub async fn get_endpoint_creation_script_active_active(
284        &self,
285        subscription_id: i32,
286        region_id: i32,
287        psc_service_id: i32,
288        endpoint_id: i32,
289    ) -> Result<String> {
290        self.client
291            .get(&format!(
292                "/subscriptions/{}/regions/{}/private-service-connect/{}/endpoints/{}/creationScripts",
293                subscription_id, region_id, psc_service_id, endpoint_id
294            ))
295            .await
296    }
297
298    /// Get Active-Active PSC endpoint deletion script
299    pub async fn get_endpoint_deletion_script_active_active(
300        &self,
301        subscription_id: i32,
302        region_id: i32,
303        psc_service_id: i32,
304        endpoint_id: i32,
305    ) -> Result<String> {
306        self.client
307            .get(&format!(
308                "/subscriptions/{}/regions/{}/private-service-connect/{}/endpoints/{}/deletionScripts",
309                subscription_id, region_id, psc_service_id, endpoint_id
310            ))
311            .await
312    }
313}