opendal_service_vercel_artifacts/
config.rs1use std::fmt::Debug;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23use super::backend::VercelArtifactsBuilder;
24
25#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
27#[serde(default)]
28#[non_exhaustive]
29pub struct VercelArtifactsConfig {
30 pub access_token: Option<String>,
32 pub endpoint: Option<String>,
36 pub team_id: Option<String>,
39 pub team_slug: Option<String>,
42}
43
44impl Debug for VercelArtifactsConfig {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 f.debug_struct("VercelArtifactsConfig")
47 .finish_non_exhaustive()
48 }
49}
50
51impl opendal_core::Configurator for VercelArtifactsConfig {
52 type Builder = VercelArtifactsBuilder;
53
54 fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self> {
55 Self::from_iter(uri.options().clone())
56 }
57
58 fn into_builder(self) -> Self::Builder {
59 VercelArtifactsBuilder { config: self }
60 }
61}
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66 use opendal_core::Configurator;
67 use opendal_core::OperatorUri;
68
69 #[test]
70 fn from_uri_loads_access_token() {
71 let uri = OperatorUri::new(
72 "vercel-artifacts://cache",
73 vec![("access_token".to_string(), "token123".to_string())],
74 )
75 .unwrap();
76
77 let cfg = VercelArtifactsConfig::from_uri(&uri).unwrap();
78 assert_eq!(cfg.access_token.as_deref(), Some("token123"));
79 }
80
81 #[test]
82 fn from_uri_loads_all_options() {
83 let uri = OperatorUri::new(
84 "vercel-artifacts://cache",
85 vec![
86 ("access_token".to_string(), "token123".to_string()),
87 (
88 "endpoint".to_string(),
89 "https://custom.api.example.com".to_string(),
90 ),
91 ("team_id".to_string(), "team_abc".to_string()),
92 ("team_slug".to_string(), "my-team".to_string()),
93 ],
94 )
95 .unwrap();
96
97 let cfg = VercelArtifactsConfig::from_uri(&uri).unwrap();
98 assert_eq!(cfg.access_token.as_deref(), Some("token123"));
99 assert_eq!(
100 cfg.endpoint.as_deref(),
101 Some("https://custom.api.example.com")
102 );
103 assert_eq!(cfg.team_id.as_deref(), Some("team_abc"));
104 assert_eq!(cfg.team_slug.as_deref(), Some("my-team"));
105 }
106
107 #[test]
108 fn defaults_are_none() {
109 let cfg = VercelArtifactsConfig::default();
110 assert!(cfg.access_token.is_none());
111 assert!(cfg.endpoint.is_none());
112 assert!(cfg.team_id.is_none());
113 assert!(cfg.team_slug.is_none());
114 }
115}