datanode/store/
gcs.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use 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}