datanode/store/
oss.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::Oss;
18use object_store::{util, ObjectStore};
19use snafu::prelude::*;
20
21use crate::config::OssConfig;
22use crate::error::{self, Result};
23use crate::store::build_http_client;
24
25pub(crate) async fn new_oss_object_store(oss_config: &OssConfig) -> Result<ObjectStore> {
26    let root = util::normalize_dir(&oss_config.root);
27    info!(
28        "The oss storage bucket is: {}, root is: {}",
29        oss_config.bucket, &root
30    );
31
32    let client = build_http_client(&oss_config.http_client)?;
33
34    let builder = Oss::default()
35        .root(&root)
36        .bucket(&oss_config.bucket)
37        .endpoint(&oss_config.endpoint)
38        .access_key_id(oss_config.access_key_id.expose_secret())
39        .access_key_secret(oss_config.access_key_secret.expose_secret())
40        .http_client(client);
41
42    Ok(ObjectStore::new(builder)
43        .context(error::InitBackendSnafu)?
44        .finish())
45}