opendal_service_alluxio/
config.rs1use std::fmt::Debug;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23use super::backend::AlluxioBuilder;
24
25#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
27#[serde(default)]
28#[non_exhaustive]
29pub struct AlluxioConfig {
30 pub root: Option<String>,
36 pub endpoint: Option<String>,
40}
41
42impl Debug for AlluxioConfig {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 f.debug_struct("AlluxioConfig")
45 .field("root", &self.root)
46 .field("endpoint", &self.endpoint)
47 .finish_non_exhaustive()
48 }
49}
50
51impl opendal_core::Configurator for AlluxioConfig {
52 type Builder = AlluxioBuilder;
53
54 fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self> {
55 let mut map = uri.options().clone();
56 if let Some(authority) = uri.authority() {
57 map.insert("endpoint".to_string(), format!("http://{authority}"));
58 }
59
60 if let Some(root) = uri.root()
61 && !root.is_empty()
62 {
63 map.insert("root".to_string(), root.to_string());
64 }
65
66 Self::from_iter(map)
67 }
68
69 fn into_builder(self) -> Self::Builder {
70 AlluxioBuilder { config: self }
71 }
72}
73
74#[cfg(test)]
75mod tests {
76 use super::*;
77 use opendal_core::Configurator;
78 use opendal_core::OperatorUri;
79
80 #[test]
81 fn from_uri_sets_endpoint_and_root() {
82 let uri = OperatorUri::new(
83 "alluxio://127.0.0.1:39999/data/raw",
84 Vec::<(String, String)>::new(),
85 )
86 .unwrap();
87
88 let cfg = AlluxioConfig::from_uri(&uri).unwrap();
89 assert_eq!(cfg.endpoint.as_deref(), Some("http://127.0.0.1:39999"));
90 assert_eq!(cfg.root.as_deref(), Some("data/raw"));
91 }
92}