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