opendal/services/upyun/
config.rs1use std::fmt::Debug;
19use std::fmt::Formatter;
20
21use super::backend::UpyunBuilder;
22use serde::Deserialize;
23use serde::Serialize;
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 Formatter<'_>) -> std::fmt::Result {
44 let mut ds = f.debug_struct("Config");
45
46 ds.field("root", &self.root);
47 ds.field("bucket", &self.bucket);
48 ds.field("operator", &self.operator);
49
50 ds.finish()
51 }
52}
53
54impl crate::Configurator for UpyunConfig {
55 type Builder = UpyunBuilder;
56
57 fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
58 let mut map = uri.options().clone();
59
60 if let Some(name) = uri.name() {
61 map.insert("bucket".to_string(), name.to_string());
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 UpyunBuilder {
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_extracts_bucket_and_root() {
88 let uri = OperatorUri::new(
89 "upyun://example-bucket/path/to/root",
90 Vec::<(String, String)>::new(),
91 )
92 .unwrap();
93 let cfg = UpyunConfig::from_uri(&uri).unwrap();
94 assert_eq!(cfg.bucket, "example-bucket");
95 assert_eq!(cfg.root.as_deref(), Some("path/to/root"));
96 }
97}