opendal/services/etcd/config.rs
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use std::fmt::Debug;
19use std::fmt::Formatter;
20
21use serde::Deserialize;
22use serde::Serialize;
23
24/// Config for Etcd services support.
25#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
26#[serde(default)]
27#[non_exhaustive]
28pub struct EtcdConfig {
29 /// network address of the Etcd services.
30 /// If use https, must set TLS options: `ca_path`, `cert_path`, `key_path`.
31 /// e.g. "127.0.0.1:23790,127.0.0.1:23791,127.0.0.1:23792" or "http://127.0.0.1:23790,http://127.0.0.1:23791,http://127.0.0.1:23792" or "https://127.0.0.1:23790,https://127.0.0.1:23791,https://127.0.0.1:23792"
32 ///
33 /// default is "http://127.0.0.1:2379"
34 pub endpoints: Option<String>,
35 /// the username to connect etcd service.
36 ///
37 /// default is None
38 pub username: Option<String>,
39 /// the password for authentication
40 ///
41 /// default is None
42 pub password: Option<String>,
43 /// the working directory of the etcd service. Can be "/path/to/dir"
44 ///
45 /// default is "/"
46 pub root: Option<String>,
47 /// certificate authority file path
48 ///
49 /// default is None
50 pub ca_path: Option<String>,
51 /// cert path
52 ///
53 /// default is None
54 pub cert_path: Option<String>,
55 /// key path
56 ///
57 /// default is None
58 pub key_path: Option<String>,
59}
60
61impl Debug for EtcdConfig {
62 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
63 let mut ds = f.debug_struct("EtcdConfig");
64
65 ds.field("root", &self.root);
66 if let Some(endpoints) = self.endpoints.clone() {
67 ds.field("endpoints", &endpoints);
68 }
69 if let Some(username) = self.username.clone() {
70 ds.field("username", &username);
71 }
72 if self.password.is_some() {
73 ds.field("password", &"<redacted>");
74 }
75 if let Some(ca_path) = self.ca_path.clone() {
76 ds.field("ca_path", &ca_path);
77 }
78 if let Some(cert_path) = self.cert_path.clone() {
79 ds.field("cert_path", &cert_path);
80 }
81 if let Some(key_path) = self.key_path.clone() {
82 ds.field("key_path", &key_path);
83 }
84 ds.finish()
85 }
86}