redis_cloud/
endpoint_redirections.rs1use crate::{CloudClient, Result};
8use serde::{Deserialize, Serialize};
9use typed_builder::TypedBuilder;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13#[serde(rename_all = "lowercase")]
14#[non_exhaustive]
15pub enum EndpointTargetType {
16 Public,
18 Private,
20 #[serde(other)]
22 Unknown,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
27#[serde(rename_all = "camelCase")]
28pub struct CreateEndpointsRedirectionRequest {
29 pub source_database_id: i32,
31
32 pub target_database_id: i32,
34
35 pub endpoint_target_type: EndpointTargetType,
37
38 #[serde(rename = "duplicateACLs", skip_serializing_if = "Option::is_none")]
40 #[builder(default, setter(strip_option))]
41 pub duplicate_acls: Option<bool>,
42
43 pub migration_protection: bool,
45}
46
47#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
49#[serde(rename_all = "kebab-case")]
50#[non_exhaustive]
51pub enum EndpointRedirectionStatus {
52 Initiated,
54 Pending,
56 InProgress,
58 Completed,
60 Failed,
62 Reverted,
64 #[serde(other)]
66 Unknown,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(rename_all = "camelCase")]
72pub struct EndpointRedirection {
73 #[serde(skip_serializing_if = "Option::is_none")]
75 pub source_endpoint_name: Option<String>,
76
77 #[serde(skip_serializing_if = "Option::is_none")]
79 pub target_endpoint_name: Option<String>,
80
81 #[serde(skip_serializing_if = "Option::is_none")]
83 pub source_endpoint_type: Option<EndpointTargetType>,
84
85 #[serde(skip_serializing_if = "Option::is_none")]
87 pub target_endpoint_type: Option<EndpointTargetType>,
88
89 #[serde(skip_serializing_if = "Option::is_none")]
91 pub error_message: Option<String>,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(rename_all = "camelCase")]
97pub struct EndpointsRedirectionResponse {
98 #[serde(skip_serializing_if = "Option::is_none")]
100 pub redirection_id: Option<String>,
101
102 #[serde(skip_serializing_if = "Option::is_none")]
104 pub status: Option<EndpointRedirectionStatus>,
105
106 #[serde(skip_serializing_if = "Option::is_none")]
108 pub source_database_id: Option<i32>,
109
110 #[serde(skip_serializing_if = "Option::is_none")]
112 pub target_database_id: Option<i32>,
113
114 #[serde(skip_serializing_if = "Option::is_none")]
116 pub is_revert: Option<bool>,
117
118 #[serde(rename = "duplicateACLs", skip_serializing_if = "Option::is_none")]
120 pub duplicate_acls: Option<bool>,
121
122 #[serde(skip_serializing_if = "Option::is_none")]
124 pub started_at: Option<String>,
125
126 #[serde(skip_serializing_if = "Option::is_none")]
128 pub completed_at: Option<String>,
129
130 #[serde(skip_serializing_if = "Option::is_none")]
132 pub reverted_at: Option<String>,
133
134 #[serde(skip_serializing_if = "Option::is_none")]
136 pub error_message: Option<String>,
137
138 #[serde(skip_serializing_if = "Option::is_none")]
140 pub endpoints: Option<Vec<EndpointRedirection>>,
141}
142
143pub struct EndpointRedirectionsHandler {
145 client: CloudClient,
146}
147
148impl EndpointRedirectionsHandler {
149 #[must_use]
151 pub fn new(client: CloudClient) -> Self {
152 Self { client }
153 }
154
155 pub async fn create(
157 &self,
158 request: &CreateEndpointsRedirectionRequest,
159 ) -> Result<EndpointsRedirectionResponse> {
160 self.client.post("/endpoint-redirections", request).await
161 }
162
163 pub async fn get(&self, redirection_id: &str) -> Result<EndpointsRedirectionResponse> {
165 self.client
166 .get(&format!("/endpoint-redirections/{redirection_id}"))
167 .await
168 }
169
170 pub async fn revert(&self, redirection_id: &str) -> Result<EndpointsRedirectionResponse> {
172 self.client
173 .post_empty(&format!("/endpoint-redirections/{redirection_id}/revert"))
174 .await
175 }
176}