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