redis_enterprise/
bootstrap.rs1use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12use typed_builder::TypedBuilder;
13
14#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
34pub struct BootstrapConfig {
35 #[builder(setter(into))]
37 pub action: String,
38 #[serde(skip_serializing_if = "Option::is_none")]
40 #[builder(default, setter(strip_option))]
41 pub cluster: Option<ClusterBootstrap>,
42 #[serde(skip_serializing_if = "Option::is_none")]
44 #[builder(default, setter(strip_option))]
45 pub node: Option<NodeBootstrap>,
46 #[serde(skip_serializing_if = "Option::is_none")]
48 #[builder(default, setter(strip_option))]
49 pub credentials: Option<CredentialsBootstrap>,
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
54pub struct ClusterBootstrap {
55 #[builder(setter(into))]
57 pub name: String,
58 #[serde(skip_serializing_if = "Option::is_none")]
60 #[builder(default, setter(strip_option))]
61 pub dns_suffixes: Option<Vec<String>>,
62 #[serde(skip_serializing_if = "Option::is_none")]
64 #[builder(default, setter(strip_option))]
65 pub rack_aware: Option<bool>,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
70pub struct NodeBootstrap {
71 #[serde(skip_serializing_if = "Option::is_none")]
73 #[builder(default, setter(strip_option))]
74 pub paths: Option<NodePaths>,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
79pub struct NodePaths {
80 #[serde(skip_serializing_if = "Option::is_none")]
82 #[builder(default, setter(into, strip_option))]
83 pub persistent_path: Option<String>,
84 #[serde(skip_serializing_if = "Option::is_none")]
86 #[builder(default, setter(into, strip_option))]
87 pub ephemeral_path: Option<String>,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
92pub struct CredentialsBootstrap {
93 #[builder(setter(into))]
95 pub username: String,
96 #[builder(setter(into))]
98 pub password: String,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
103pub struct BootstrapStatus {
104 pub status: String,
106 #[serde(skip_serializing_if = "Option::is_none")]
107 pub progress: Option<f32>,
109 #[serde(skip_serializing_if = "Option::is_none")]
110 pub message: Option<String>,
112}
113
114pub struct BootstrapHandler {
116 client: RestClient,
117}
118
119impl BootstrapHandler {
120 pub fn new(client: RestClient) -> Self {
121 BootstrapHandler { client }
122 }
123
124 pub async fn create(&self, config: BootstrapConfig) -> Result<BootstrapStatus> {
126 self.client.post("/v1/bootstrap", &config).await
127 }
128
129 pub async fn status(&self) -> Result<BootstrapStatus> {
131 self.client.get("/v1/bootstrap").await
132 }
133
134 pub async fn join(&self, config: BootstrapConfig) -> Result<BootstrapStatus> {
136 self.client.post("/v1/bootstrap/join", &config).await
137 }
138
139 pub async fn reset(&self) -> Result<()> {
141 self.client.delete("/v1/bootstrap").await
142 }
143
144 pub async fn validate_for(&self, uid: u32, body: Value) -> Result<Value> {
146 self.client
147 .post(&format!("/v1/bootstrap/validate/{}", uid), &body)
148 .await
149 }
150
151 pub async fn post_action(&self, action: &str, body: Value) -> Result<Value> {
153 self.client
154 .post(&format!("/v1/bootstrap/{}", action), &body)
155 .await
156 }
157}