risingwave_object_store/object/opendal_engine/
oss.rs1use std::sync::Arc;
16
17use opendal::Operator;
18use opendal::layers::LoggingLayer;
19use opendal::services::Oss;
20use risingwave_common::config::ObjectStoreConfig;
21
22use super::{MediaType, OpendalObjectStore};
23use crate::object::ObjectResult;
24use crate::object::object_metrics::ObjectStoreMetrics;
25
26impl OpendalObjectStore {
27 pub fn new_oss_engine(
29 bucket: String,
30 root: String,
31 config: Arc<ObjectStoreConfig>,
32 metrics: Arc<ObjectStoreMetrics>,
33 ) -> ObjectResult<Self> {
34 let mut builder = Oss::default().bucket(&bucket).root(&root);
36
37 let endpoint = std::env::var("OSS_ENDPOINT")
38 .unwrap_or_else(|_| panic!("OSS_ENDPOINT not found from environment variables"));
39 let access_key_id = std::env::var("OSS_ACCESS_KEY_ID")
40 .unwrap_or_else(|_| panic!("OSS_ACCESS_KEY_ID not found from environment variables"));
41 let access_key_secret = std::env::var("OSS_ACCESS_KEY_SECRET").unwrap_or_else(|_| {
42 panic!("OSS_ACCESS_KEY_SECRET not found from environment variables")
43 });
44
45 builder = builder
46 .endpoint(&endpoint)
47 .access_key_id(&access_key_id)
48 .access_key_secret(&access_key_secret);
49
50 let op: Operator = Operator::new(builder)?
51 .layer(LoggingLayer::default())
52 .finish();
53 Ok(Self {
54 op,
55 media_type: MediaType::Oss,
56 config,
57 metrics,
58 })
59 }
60}