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