1use common_base::secrets::ExposeSecret;
16use common_telemetry::info;
17use object_store::services::Gcs;
18use object_store::{util, ObjectStore};
19use snafu::prelude::*;
20
21use crate::config::GcsConfig;
22use crate::error::{self, Result};
23use crate::store::build_http_client;
24
25pub(crate) async fn new_gcs_object_store(gcs_config: &GcsConfig) -> Result<ObjectStore> {
26 let root = util::normalize_dir(&gcs_config.root);
27 info!(
28 "The gcs storage bucket is: {}, root is: {}",
29 gcs_config.bucket, &root
30 );
31
32 let client = build_http_client(&gcs_config.http_client);
33
34 let builder = Gcs::default()
35 .root(&root)
36 .bucket(&gcs_config.bucket)
37 .scope(&gcs_config.scope)
38 .credential_path(gcs_config.credential_path.expose_secret())
39 .credential(gcs_config.credential.expose_secret())
40 .endpoint(&gcs_config.endpoint)
41 .http_client(client?);
42
43 Ok(ObjectStore::new(builder)
44 .context(error::InitBackendSnafu)?
45 .finish())
46}