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