opendal/services/foundationdb/
config.rs1use serde::Deserialize;
19use serde::Serialize;
20
21use super::backend::FoundationdbBuilder;
22
23#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
26#[serde(default)]
27#[non_exhaustive]
28pub struct FoundationdbConfig {
29 pub root: Option<String>,
31 pub config_path: Option<String>,
33}
34
35impl crate::Configurator for FoundationdbConfig {
36 type Builder = FoundationdbBuilder;
37
38 fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
39 let mut map = uri.options().clone();
40
41 if let Some(path) = uri.root() {
42 if !path.is_empty() {
43 map.entry("config_path".to_string())
44 .or_insert_with(|| format!("/{path}"));
45 }
46 }
47
48 Self::from_iter(map)
49 }
50
51 fn into_builder(self) -> Self::Builder {
52 FoundationdbBuilder { config: self }
53 }
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59 use crate::Configurator;
60 use crate::types::OperatorUri;
61
62 #[test]
63 fn from_uri_sets_config_path_and_root() {
64 let uri = OperatorUri::new(
65 "foundationdb:///etc/foundationdb/fdb.cluster?root=data",
66 Vec::<(String, String)>::new(),
67 )
68 .unwrap();
69
70 let cfg = FoundationdbConfig::from_uri(&uri).unwrap();
71 assert_eq!(
72 cfg.config_path.as_deref(),
73 Some("/etc/foundationdb/fdb.cluster")
74 );
75 assert_eq!(cfg.root.as_deref(), Some("data"));
76 }
77}