opendal_core/services/webdav/
config.rs1use std::fmt::Debug;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23use super::backend::WebdavBuilder;
24
25#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
27#[serde(default)]
28#[non_exhaustive]
29pub struct WebdavConfig {
30 pub endpoint: Option<String>,
32 pub username: Option<String>,
34 pub password: Option<String>,
36 pub token: Option<String>,
38 pub root: Option<String>,
40 pub disable_copy: bool,
42}
43
44impl Debug for WebdavConfig {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 f.debug_struct("WebdavConfig")
47 .field("endpoint", &self.endpoint)
48 .field("username", &self.username)
49 .field("root", &self.root)
50 .field("disable_copy", &self.disable_copy)
51 .finish_non_exhaustive()
52 }
53}
54
55impl crate::Configurator for WebdavConfig {
56 type Builder = WebdavBuilder;
57
58 fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
59 let mut map = uri.options().clone();
60 if let Some(authority) = uri.authority() {
61 map.insert("endpoint".to_string(), format!("https://{authority}"));
62 }
63
64 if let Some(root) = uri.root() {
65 map.insert("root".to_string(), root.to_string());
66 }
67
68 Self::from_iter(map)
69 }
70
71 #[allow(deprecated)]
72 fn into_builder(self) -> Self::Builder {
73 WebdavBuilder {
74 config: self,
75 http_client: None,
76 }
77 }
78}
79
80#[cfg(test)]
81mod tests {
82 use super::*;
83 use crate::Configurator;
84 use crate::types::OperatorUri;
85
86 #[test]
87 fn from_uri_sets_endpoint_and_root() {
88 let uri = OperatorUri::new(
89 "webdav://webdav.example.com/remote.php/webdav",
90 Vec::<(String, String)>::new(),
91 )
92 .unwrap();
93
94 let cfg = WebdavConfig::from_uri(&uri).unwrap();
95 assert_eq!(cfg.endpoint.as_deref(), Some("https://webdav.example.com"));
96 assert_eq!(cfg.root.as_deref(), Some("remote.php/webdav"));
97 }
98
99 #[test]
100 fn from_uri_ignores_endpoint_override() {
101 let uri = OperatorUri::new(
102 "webdav://dav.internal/data",
103 vec![(
104 "endpoint".to_string(),
105 "http://dav.internal:8080".to_string(),
106 )],
107 )
108 .unwrap();
109
110 let cfg = WebdavConfig::from_uri(&uri).unwrap();
111 assert_eq!(cfg.endpoint.as_deref(), Some("https://dav.internal"));
112 }
113
114 #[test]
115 fn from_uri_propagates_disable_copy() {
116 let uri = OperatorUri::new(
117 "webdav://dav.example.com",
118 vec![("disable_copy".to_string(), "true".to_string())],
119 )
120 .unwrap();
121
122 let cfg = WebdavConfig::from_uri(&uri).unwrap();
123 assert!(cfg.disable_copy);
124 }
125}