opendal/services/yandex_disk/
config.rs1use std::fmt::Debug;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23use super::backend::YandexDiskBuilder;
24
25#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
27#[serde(default)]
28#[non_exhaustive]
29pub struct YandexDiskConfig {
30 pub root: Option<String>,
34 pub access_token: String,
36}
37
38impl Debug for YandexDiskConfig {
39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 f.debug_struct("YandexDiskConfig")
41 .field("root", &self.root)
42 .finish_non_exhaustive()
43 }
44}
45
46impl crate::Configurator for YandexDiskConfig {
47 type Builder = YandexDiskBuilder;
48
49 fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
50 let mut map = uri.options().clone();
51
52 if let Some(root) = uri.root() {
53 if !root.is_empty() {
54 map.insert("root".to_string(), root.to_string());
55 }
56 }
57
58 Self::from_iter(map)
59 }
60
61 #[allow(deprecated)]
62 fn into_builder(self) -> Self::Builder {
63 YandexDiskBuilder {
64 config: self,
65 http_client: None,
66 }
67 }
68}
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73 use crate::Configurator;
74 use crate::types::OperatorUri;
75
76 #[test]
77 fn from_uri_sets_root_and_preserves_token() {
78 let uri = OperatorUri::new(
79 "yandex-disk://disk/root/path",
80 vec![("access_token".to_string(), "secret".to_string())],
81 )
82 .unwrap();
83
84 let cfg = YandexDiskConfig::from_uri(&uri).unwrap();
85 assert_eq!(cfg.root.as_deref(), Some("root/path"));
86 assert_eq!(cfg.access_token, "secret".to_string());
87 }
88}