use opendal::OperationContext;
use opendal::Operator;
use opendal::services::Oss;
use opendal_layer_logging::LoggingLayer;
use crate::errors::*;
use super::http_client::set_user_agent;
pub struct OSSCache;
impl OSSCache {
pub fn build(
bucket: &str,
key_prefix: &str,
endpoint: Option<&str>,
no_credentials: bool,
) -> Result<Operator> {
let mut builder = Oss::default().bucket(bucket).root(key_prefix);
if let Some(endpoint) = endpoint {
builder = builder.endpoint(endpoint);
}
if no_credentials {
builder = builder.skip_signature();
}
let op = Operator::new(builder)?
.with_context(OperationContext::new().with_http_transport(set_user_agent()))
.layer(LoggingLayer::default());
Ok(op)
}
}