use crate::{Error, GetObjectResponse, ObjectInfo, PutObjectRequest, PutObjectResponse, Result};
#[derive(Debug, Clone)]
pub struct StorageClient {
endpoint: String,
}
impl StorageClient {
pub async fn connect(endpoint: &str) -> Result<Self> {
Ok(Self {
endpoint: endpoint.to_string(),
})
}
pub async fn create_bucket(&self, bucket: &str) -> Result<()> {
Ok(())
}
pub async fn list_buckets(&self) -> Result<Vec<String>> {
Ok(vec![])
}
pub async fn delete_bucket(&self, bucket: &str) -> Result<()> {
Ok(())
}
pub async fn put_object(&self, req: PutObjectRequest) -> Result<PutObjectResponse> {
Ok(PutObjectResponse {
etag: "dummy-etag".to_string(),
version_id: None,
})
}
pub async fn get_object(&self, bucket: &str, key: &str) -> Result<GetObjectResponse> {
Err(Error::ObjectNotFound {
bucket: bucket.to_string(),
key: key.to_string(),
})
}
pub async fn list_objects(
&self,
bucket: &str,
prefix: Option<&str>,
) -> Result<Vec<ObjectInfo>> {
Ok(vec![])
}
pub async fn delete_object(&self, bucket: &str, key: &str) -> Result<()> {
Ok(())
}
pub async fn copy_object(
&self,
source_bucket: &str,
source_key: &str,
dest_bucket: &str,
dest_key: &str,
) -> Result<()> {
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_client_connect() {
let client = StorageClient::connect("https://storage.avila.cloud").await;
assert!(client.is_ok());
}
}