redis_enterprise/
bootstrap.rs1use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct BootstrapConfig {
16    pub action: String,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub cluster: Option<ClusterBootstrap>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub node: Option<NodeBootstrap>,
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub credentials: Option<CredentialsBootstrap>,
27
28    #[serde(flatten)]
29    pub extra: Value,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct ClusterBootstrap {
35    pub name: String,
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub dns_suffixes: Option<Vec<String>>,
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub rack_aware: Option<bool>,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct NodeBootstrap {
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub paths: Option<NodePaths>,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct NodePaths {
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub persistent_path: Option<String>,
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub ephemeral_path: Option<String>,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct CredentialsBootstrap {
67    pub username: String,
69    pub password: String,
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct BootstrapStatus {
76    pub status: String,
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub progress: Option<f32>,
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub message: Option<String>,
84
85    #[serde(flatten)]
86    pub extra: Value,
87}
88
89pub struct BootstrapHandler {
91    client: RestClient,
92}
93
94impl BootstrapHandler {
95    pub fn new(client: RestClient) -> Self {
96        BootstrapHandler { client }
97    }
98
99    pub async fn create(&self, config: BootstrapConfig) -> Result<BootstrapStatus> {
101        self.client.post("/v1/bootstrap", &config).await
102    }
103
104    pub async fn status(&self) -> Result<BootstrapStatus> {
106        self.client.get("/v1/bootstrap").await
107    }
108
109    pub async fn join(&self, config: BootstrapConfig) -> Result<BootstrapStatus> {
111        self.client.post("/v1/bootstrap/join", &config).await
112    }
113
114    pub async fn reset(&self) -> Result<()> {
116        self.client.delete("/v1/bootstrap").await
117    }
118
119    pub async fn validate_for(&self, uid: u32, body: Value) -> Result<Value> {
121        self.client
122            .post(&format!("/v1/bootstrap/validate/{}", uid), &body)
123            .await
124    }
125
126    pub async fn post_action(&self, action: &str, body: Value) -> Result<Value> {
128        self.client
129            .post(&format!("/v1/bootstrap/{}", action), &body)
130            .await
131    }
132}