From ed22ba5a46e501bd9f1d74bc263928a5a6acf8dd Mon Sep 17 00:00:00 2001 From: RWDai <27391645+RWDai@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:16:28 +0800 Subject: [PATCH 1/3] feat: bump rust-s3 --- tardis/Cargo.toml | 3 ++- tardis/src/os/os_client.rs | 37 +++++++++++++++++++++++++++++++++- tardis/tests/test_os_client.rs | 10 +++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/tardis/Cargo.toml b/tardis/Cargo.toml index 8d65948..652b63b 100644 --- a/tardis/Cargo.toml +++ b/tardis/Cargo.toml @@ -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 diff --git a/tardis/src/os/os_client.rs b/tardis/src/os/os_client.rs index a7db57f..2af9cbf 100644 --- a/tardis/src/os/os_client.rs +++ b/tardis/src/os/os_client.rs @@ -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}; @@ -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 { + 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] @@ -178,6 +190,12 @@ trait TardisOSOperations { async fn object_get_url(&self, path: &str, expire_sec: u32, bucket_name: Option<&str>) -> TardisResult; async fn object_delete_url(&self, path: &str, expire_sec: u32, bucket_name: Option<&str>) -> TardisResult; + + async fn get_lifecycle(&self, bucket_name: &str) -> TardisResult; + + async fn put_lifecycle(&self, bucket_name: &str, config: BucketLifecycleConfiguration) -> TardisResult<()>; + + async fn delete_lifecycle(&self, bucket_name: &str) -> TardisResult<()>; } #[async_trait] @@ -397,6 +415,23 @@ impl TardisOSOperations for TardisOSS3Client { async fn object_delete_url(&self, path: &str, expire_sec: u32, bucket_name: Option<&str>) -> TardisResult { Ok(self.get_bucket(bucket_name)?.presign_delete(path, expire_sec).await?) } + + async fn get_lifecycle(&self, bucket_name: &str) -> TardisResult { + 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 { diff --git a/tardis/tests/test_os_client.rs b/tardis/tests/test_os_client.rs index 13883ed..91427b9 100644 --- a/tardis/tests/test_os_client.rs +++ b/tardis/tests/test_os_client.rs @@ -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()))?); From 4c495925670c04ecf731f2e348110f4fa55a1da6 Mon Sep 17 00:00:00 2001 From: RWDai <27391645+RWDai@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:39:56 +0800 Subject: [PATCH 2/3] update --- tardis/Cargo.toml | 2 +- tardis/src/os.rs | 1 + tardis/src/os/os_client.rs | 24 ++++++++++++------------ tardis/tests/test_os_client.rs | 7 ++++--- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tardis/Cargo.toml b/tardis/Cargo.toml index 652b63b..62bef9c 100644 --- a/tardis/Cargo.toml +++ b/tardis/Cargo.toml @@ -218,7 +218,7 @@ 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 = "3ee40ba", optional = true } +rust-s3 = { git = "https://github.com/tuist/rust-s3.git", rev = "55f2947", optional = true } # rust-s3 = { path = "../../rust-s3/s3", optional = true } anyhow = { version = "1.0", optional = true } diff --git a/tardis/src/os.rs b/tardis/src/os.rs index 0230a85..5851df9 100644 --- a/tardis/src/os.rs +++ b/tardis/src/os.rs @@ -1 +1,2 @@ +pub use s3::serde_types; pub mod os_client; diff --git a/tardis/src/os/os_client.rs b/tardis/src/os/os_client.rs index 2af9cbf..6a20a3d 100644 --- a/tardis/src/os/os_client.rs +++ b/tardis/src/os/os_client.rs @@ -148,15 +148,15 @@ impl TardisOSClient { self.get_client().object_delete_url(path, expire_sec, bucket_name).await } - pub async fn get_lifecycle(&self, bucket_name: &str) -> TardisResult { + pub async fn get_lifecycle(&self, bucket_name: Option<&str>) -> TardisResult { self.get_client().get_lifecycle(bucket_name).await } - pub async fn put_lifecycle(&self, bucket_name: &str, config: BucketLifecycleConfiguration) -> TardisResult<()> { + pub async fn put_lifecycle(&self, bucket_name: Option<&str>, config: BucketLifecycleConfiguration) -> TardisResult<()> { self.get_client().put_lifecycle(bucket_name, config).await } - pub async fn delete_lifecycle(&self, bucket_name: &str) -> TardisResult<()> { + pub async fn delete_lifecycle(&self, bucket_name: Option<&str>) -> TardisResult<()> { self.get_client().delete_lifecycle(bucket_name).await } } @@ -191,11 +191,11 @@ trait TardisOSOperations { async fn object_delete_url(&self, path: &str, expire_sec: u32, bucket_name: Option<&str>) -> TardisResult; - async fn get_lifecycle(&self, bucket_name: &str) -> TardisResult; + async fn get_lifecycle(&self, bucket_name: Option<&str>) -> TardisResult; - async fn put_lifecycle(&self, bucket_name: &str, config: BucketLifecycleConfiguration) -> TardisResult<()>; + async fn put_lifecycle(&self, bucket_name: Option<&str>, config: BucketLifecycleConfiguration) -> TardisResult<()>; - async fn delete_lifecycle(&self, bucket_name: &str) -> TardisResult<()>; + async fn delete_lifecycle(&self, bucket_name: Option<&str>) -> TardisResult<()>; } #[async_trait] @@ -416,19 +416,19 @@ impl TardisOSOperations for TardisOSS3Client { Ok(self.get_bucket(bucket_name)?.presign_delete(path, expire_sec).await?) } - async fn get_lifecycle(&self, bucket_name: &str) -> TardisResult { - let bucket = self.get_bucket(Some(bucket_name))?; + async fn get_lifecycle(&self, bucket_name: Option<&str>) -> TardisResult { + let bucket = self.get_bucket(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))?; + async fn put_lifecycle(&self, bucket_name: Option<&str>, config: BucketLifecycleConfiguration) -> TardisResult<()> { + let bucket = self.get_bucket(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))?; + async fn delete_lifecycle(&self, bucket_name: Option<&str>) -> TardisResult<()> { + let bucket = self.get_bucket(bucket_name)?; bucket.delete_bucket_lifecycle().await?; Ok(()) } diff --git a/tardis/tests/test_os_client.rs b/tardis/tests/test_os_client.rs index 91427b9..5e4efa0 100644 --- a/tardis/tests/test_os_client.rs +++ b/tardis/tests/test_os_client.rs @@ -1,5 +1,6 @@ use std::env; +use s3::serde_types::LifecycleFilter; use tracing::info; use tardis::basic::result::TardisResult; @@ -33,8 +34,9 @@ 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))) + let put_config = s3::serde_types::BucketLifecycleConfiguration::new(vec![s3::serde_types::LifecycleRule::builder("Enabled") + .expiration(s3::serde_types::Expiration::new(None, Some(30), None)) + .filter(LifecycleFilter::new(None, None, None, Some("test".to_string()), None)) .build()]); TardisFuns::os().put_lifecycle(bucket_name, put_config.clone()).await?; @@ -42,7 +44,6 @@ async fn test_os_client() -> TardisResult<()> { 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()))?); From 04358c7569c2ef7a075397ced4125ab1f075a8b1 Mon Sep 17 00:00:00 2001 From: RWDai <27391645+RWDai@users.noreply.github.com> Date: Wed, 19 Jun 2024 12:52:34 +0800 Subject: [PATCH 3/3] fix test --- tardis/tests/test_os_client.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tardis/tests/test_os_client.rs b/tardis/tests/test_os_client.rs index 5e4efa0..7c09a9a 100644 --- a/tardis/tests/test_os_client.rs +++ b/tardis/tests/test_os_client.rs @@ -38,9 +38,9 @@ async fn test_os_client() -> TardisResult<()> { .expiration(s3::serde_types::Expiration::new(None, Some(30), None)) .filter(LifecycleFilter::new(None, None, None, Some("test".to_string()), None)) .build()]); - TardisFuns::os().put_lifecycle(bucket_name, put_config.clone()).await?; + TardisFuns::os().put_lifecycle(Some(bucket_name), put_config.clone()).await?; - let get_config = TardisFuns::os().get_lifecycle(bucket_name).await?; + let get_config = TardisFuns::os().get_lifecycle(Some(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());