opendal_service_gcs_grpc/
config.rs1use std::fmt::Debug;
19
20use serde::{Deserialize, Serialize};
21
22use super::backend::GcsGrpcBuilder;
23
24#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
26#[serde(default)]
27#[non_exhaustive]
28pub struct GcsGrpcConfig {
29 pub root: Option<String>,
31 #[serde(
33 alias = "google_bucket",
34 alias = "google_bucket_name",
35 alias = "bucket_name"
36 )]
37 pub bucket: String,
38 pub endpoint: Option<String>,
40 pub scope: Option<String>,
42 #[serde(
44 alias = "google_service_account",
45 alias = "google_service_account_path",
46 alias = "service_account_path"
47 )]
48 pub service_account: Option<String>,
49 #[serde(alias = "google_service_account_key", alias = "service_account_key")]
51 pub credential: Option<String>,
52 #[serde(alias = "google_application_credentials")]
54 pub credential_path: Option<String>,
55 #[serde(alias = "google_skip_signature")]
57 pub skip_signature: bool,
58 pub disable_vm_metadata: bool,
60 pub disable_config_load: bool,
62 pub token: Option<String>,
64}
65
66impl Debug for GcsGrpcConfig {
67 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
68 f.debug_struct("GcsGrpcConfig")
69 .field("root", &self.root)
70 .field("bucket", &self.bucket)
71 .field("endpoint", &self.endpoint)
72 .field("scope", &self.scope)
73 .finish_non_exhaustive()
74 }
75}
76
77impl opendal_core::Configurator for GcsGrpcConfig {
78 type Builder = GcsGrpcBuilder;
79
80 fn from_uri(uri: &opendal_core::OperatorUri) -> opendal_core::Result<Self> {
81 let mut map = uri.options().clone();
82 if let Some(name) = uri.name() {
83 map.insert("bucket".to_string(), name.to_string());
84 }
85 if let Some(root) = uri.root() {
86 map.insert("root".to_string(), root.to_string());
87 }
88 Self::from_iter(map)
89 }
90
91 fn into_builder(self) -> Self::Builder {
92 GcsGrpcBuilder {
93 config: self,
94 credential_provider_chain: None,
95 }
96 }
97}
98
99#[cfg(test)]
100mod tests {
101 use opendal_core::{Configurator, OperatorUri};
102
103 use super::*;
104
105 #[test]
106 fn from_uri_extracts_bucket_and_root() {
107 let uri = OperatorUri::new(
108 "gcs-grpc://example-bucket/path/to/root",
109 Vec::<(String, String)>::new(),
110 )
111 .unwrap();
112 let cfg = GcsGrpcConfig::from_uri(&uri).unwrap();
113 assert_eq!(cfg.bucket, "example-bucket");
114 assert_eq!(cfg.root.as_deref(), Some("path/to/root"));
115 }
116}