datanode/store/
azblob.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::Azblob;
18use object_store::{util, ObjectStore};
19use snafu::prelude::*;
20
21use crate::config::AzblobConfig;
22use crate::error::{self, Result};
23use crate::store::build_http_client;
24
25pub(crate) async fn new_azblob_object_store(azblob_config: &AzblobConfig) -> Result<ObjectStore> {
26    let root = util::normalize_dir(&azblob_config.root);
27
28    info!(
29        "The azure storage container is: {}, root is: {}",
30        azblob_config.container, &root
31    );
32
33    let client = build_http_client(&azblob_config.http_client)?;
34
35    let mut builder = Azblob::default()
36        .root(&root)
37        .container(&azblob_config.container)
38        .endpoint(&azblob_config.endpoint)
39        .account_name(azblob_config.account_name.expose_secret())
40        .account_key(azblob_config.account_key.expose_secret())
41        .http_client(client);
42
43    if let Some(token) = &azblob_config.sas_token {
44        builder = builder.sas_token(token);
45    };
46
47    Ok(ObjectStore::new(builder)
48        .context(error::InitBackendSnafu)?
49        .finish())
50}