opendal_service_obs/
config.rs1use std::fmt::Debug;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23use super::backend::ObsBuilder;
24
25#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
27#[serde(default)]
28#[non_exhaustive]
29pub struct ObsConfig {
30 pub root: Option<String>,
32 pub endpoint: Option<String>,
34 pub access_key_id: Option<String>,
36 pub secret_access_key: Option<String>,
38 pub security_token: Option<String>,
48 pub bucket: Option<String>,
50 pub disable_config_load: bool,
57 pub skip_signature: bool,
59 #[deprecated(
61 since = "0.57.0",
62 note = "OBS versioning capability is not controlled by this option and this option is no longer needed."
63 )]
64 pub enable_versioning: bool,
65}
66
67impl Debug for ObsConfig {
68 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69 f.debug_struct("ObsConfig")
70 .field("root", &self.root)
71 .field("endpoint", &self.endpoint)
72 .field("bucket", &self.bucket)
73 .field(
74 "security_token",
75 &self.security_token.as_ref().map(|_| "<redacted>"),
76 )
77 .field("disable_config_load", &self.disable_config_load)
78 .finish_non_exhaustive()
79 }
80}
81
82impl opendal_core::Configurator for ObsConfig {
83 type Builder = ObsBuilder;
84
85 fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self> {
86 let mut map = uri.options().clone();
87
88 if let Some(name) = uri.name() {
89 map.insert("bucket".to_string(), name.to_string());
90 }
91
92 if let Some(root) = uri.root() {
93 map.insert("root".to_string(), root.to_string());
94 }
95
96 Self::from_iter(map)
97 }
98
99 fn into_builder(self) -> Self::Builder {
100 ObsBuilder { config: self }
101 }
102}
103
104#[cfg(test)]
105mod tests {
106 use super::*;
107 use opendal_core::Configurator;
108 use opendal_core::OperatorUri;
109
110 #[test]
111 fn debug_redacts_security_token() {
112 let cfg = ObsConfig {
113 security_token: Some("super-secret-token".to_string()),
114 ..Default::default()
115 };
116
117 let debug = format!("{cfg:?}");
118 assert!(!debug.contains("super-secret-token"), "{debug}");
119 assert!(debug.contains("<redacted>"), "{debug}");
120 }
121
122 #[test]
123 fn from_uri_extracts_bucket_and_root() {
124 let uri = OperatorUri::new(
125 "obs://example-bucket/path/to/root",
126 Vec::<(String, String)>::new(),
127 )
128 .unwrap();
129 let cfg = ObsConfig::from_uri(&uri).unwrap();
130 assert_eq!(cfg.bucket.as_deref(), Some("example-bucket"));
131 assert_eq!(cfg.root.as_deref(), Some("path/to/root"));
132 }
133}