Skip to content

Commit

Permalink
feat: bump rust-s3
Browse files Browse the repository at this point in the history
  • Loading branch information
RWDai committed Jun 18, 2024
1 parent 8957194 commit ed22ba5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tardis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ lettre = { version = "0.11", features = [

# Object Storage
# rust-s3 = { version = "0.33", optional = true }
rust-s3 = { git = "https://github.com/tuist/rust-s3.git", rev = "b80b231" , optional = true }
rust-s3 = { git = "https://github.com/tuist/rust-s3.git", rev = "3ee40ba", optional = true }
# rust-s3 = { path = "../../rust-s3/s3", optional = true }
anyhow = { version = "1.0", optional = true }

# K8s
Expand Down
37 changes: 36 additions & 1 deletion tardis/src/os/os_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::Deref;

use async_trait::async_trait;
use s3::creds::Credentials;
use s3::serde_types::Part;
use s3::serde_types::{BucketLifecycleConfiguration, Part};
use s3::{Bucket, BucketConfiguration, Region};
use tracing::{error, info, trace};

Expand Down Expand Up @@ -147,6 +147,18 @@ impl TardisOSClient {
trace!("[Tardis.OSClient] Deleting object url {}", path);
self.get_client().object_delete_url(path, expire_sec, bucket_name).await
}

pub async fn get_lifecycle(&self, bucket_name: &str) -> TardisResult<BucketLifecycleConfiguration> {
self.get_client().get_lifecycle(bucket_name).await
}

pub async fn put_lifecycle(&self, bucket_name: &str, config: BucketLifecycleConfiguration) -> TardisResult<()> {
self.get_client().put_lifecycle(bucket_name, config).await
}

pub async fn delete_lifecycle(&self, bucket_name: &str) -> TardisResult<()> {
self.get_client().delete_lifecycle(bucket_name).await
}
}

#[async_trait]
Expand Down Expand Up @@ -178,6 +190,12 @@ trait TardisOSOperations {
async fn object_get_url(&self, path: &str, expire_sec: u32, bucket_name: Option<&str>) -> TardisResult<String>;

async fn object_delete_url(&self, path: &str, expire_sec: u32, bucket_name: Option<&str>) -> TardisResult<String>;

async fn get_lifecycle(&self, bucket_name: &str) -> TardisResult<BucketLifecycleConfiguration>;

async fn put_lifecycle(&self, bucket_name: &str, config: BucketLifecycleConfiguration) -> TardisResult<()>;

async fn delete_lifecycle(&self, bucket_name: &str) -> TardisResult<()>;
}

#[async_trait]
Expand Down Expand Up @@ -397,6 +415,23 @@ impl TardisOSOperations for TardisOSS3Client {
async fn object_delete_url(&self, path: &str, expire_sec: u32, bucket_name: Option<&str>) -> TardisResult<String> {
Ok(self.get_bucket(bucket_name)?.presign_delete(path, expire_sec).await?)
}

async fn get_lifecycle(&self, bucket_name: &str) -> TardisResult<BucketLifecycleConfiguration> {
let bucket = self.get_bucket(Some(bucket_name))?;
Ok(bucket.get_bucket_lifecycle().await?)
}

async fn put_lifecycle(&self, bucket_name: &str, config: BucketLifecycleConfiguration) -> TardisResult<()> {
let bucket = self.get_bucket(Some(bucket_name))?;
bucket.put_bucket_lifecycle(config).await?;
Ok(())
}

async fn delete_lifecycle(&self, bucket_name: &str) -> TardisResult<()> {
let bucket = self.get_bucket(Some(bucket_name))?;
bucket.delete_bucket_lifecycle().await?;
Ok(())
}
}

impl TardisOSS3Client {
Expand Down
10 changes: 10 additions & 0 deletions tardis/tests/test_os_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ async fn test_os_client() -> TardisResult<()> {

info!("object_create_url = {:?}", TardisFuns::os().object_exist("test/test1.txt", Some(bucket_name)).await?);

let put_config = s3::serde_types::BucketLifecycleConfiguration::new(vec![s3::serde_types::LifecycleRule::builder("Enabled".to_string())
.expiration(s3::serde_types::Expiration::new(None, Some(30), Some(true)))
.build()]);
TardisFuns::os().put_lifecycle(bucket_name, put_config.clone()).await?;

let get_config = TardisFuns::os().get_lifecycle(bucket_name).await?;
info!("get_lifecycle_rule = {:?}", get_config);
assert_eq!(serde_json::to_string(&put_config).unwrap(), serde_json::to_string(&get_config).unwrap());

TardisFuns::os().delete_lifecycle(bucket_name).await?;
//info!("object_create_url = {}", TardisFuns::os().object_create_url("test/test2.txt", 1, Some(bucket_name.clone()))?);
//
//info!("object_delete_url = {}", TardisFuns::os().object_delete_url("test/test.txt", 60, Some(bucket_name.clone()))?);
Expand Down

0 comments on commit ed22ba5

Please sign in to comment.