opendal/services/aliyun_drive/
config.rs1use std::fmt::Debug;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23use super::backend::AliyunDriveBuilder;
24
25#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
27#[serde(default)]
28#[non_exhaustive]
29pub struct AliyunDriveConfig {
30 pub root: Option<String>,
36 pub access_token: Option<String>,
42 pub client_id: Option<String>,
46 pub client_secret: Option<String>,
50 pub refresh_token: Option<String>,
54 pub drive_type: String,
62}
63
64impl Debug for AliyunDriveConfig {
65 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66 f.debug_struct("AliyunDriveConfig")
67 .field("root", &self.root)
68 .field("drive_type", &self.drive_type)
69 .finish_non_exhaustive()
70 }
71}
72
73impl crate::Configurator for AliyunDriveConfig {
74 type Builder = AliyunDriveBuilder;
75
76 fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
77 let mut map = uri.options().clone();
78
79 if let Some(drive_type) = uri.name() {
80 if !drive_type.is_empty() {
81 map.insert("drive_type".to_string(), drive_type.to_string());
82 }
83 }
84
85 if let Some(root) = uri.root() {
86 if !root.is_empty() {
87 map.insert("root".to_string(), root.to_string());
88 }
89 }
90
91 Self::from_iter(map)
92 }
93
94 #[allow(deprecated)]
95 fn into_builder(self) -> Self::Builder {
96 AliyunDriveBuilder {
97 config: self,
98 http_client: None,
99 }
100 }
101}
102
103#[cfg(test)]
104mod tests {
105 use super::*;
106 use crate::Configurator;
107 use crate::types::OperatorUri;
108
109 #[test]
110 fn from_uri_sets_drive_type_and_root() {
111 let uri = OperatorUri::new(
112 "aliyun-drive://resource/library/photos",
113 Vec::<(String, String)>::new(),
114 )
115 .unwrap();
116
117 let cfg = AliyunDriveConfig::from_uri(&uri).unwrap();
118 assert_eq!(cfg.drive_type, "resource".to_string());
119 assert_eq!(cfg.root.as_deref(), Some("library/photos"));
120 }
121
122 #[test]
123 fn from_uri_allows_missing_drive_type() {
124 let uri =
125 OperatorUri::new("aliyun-drive:///documents", Vec::<(String, String)>::new()).unwrap();
126
127 let cfg = AliyunDriveConfig::from_uri(&uri).unwrap();
128 assert_eq!(cfg.drive_type, String::default());
129 assert_eq!(cfg.root.as_deref(), Some("documents"));
130 }
131}