use std::sync::Arc;
use ailake_core::{AilakeError, AilakeResult};
use object_store::gcp::GoogleCloudStorageBuilder;
use crate::ObjectStoreBackend;
pub enum GcsCredentials {
ServiceAccountFile(String),
ServiceAccountJson(String),
ApplicationDefault,
}
pub struct GcsConfig {
pub bucket: String,
pub credentials: GcsCredentials,
}
#[cfg(feature = "store-gcs")]
pub fn gcs_store(config: GcsConfig, prefix: impl Into<String>) -> AilakeResult<ObjectStoreBackend> {
let mut b = GoogleCloudStorageBuilder::new().with_bucket_name(&config.bucket);
match config.credentials {
GcsCredentials::ServiceAccountFile(path) => {
b = b.with_service_account_path(path);
}
GcsCredentials::ServiceAccountJson(json) => {
b = b.with_service_account_key(json);
}
GcsCredentials::ApplicationDefault => {
}
}
let store = b.build().map_err(|e| AilakeError::Store(e.to_string()))?;
Ok(ObjectStoreBackend::new(Arc::new(store), prefix))
}