From 3e1a60d36f4d413222dd4b00fc367c878b516976 Mon Sep 17 00:00:00 2001 From: Nugine Date: Tue, 11 Apr 2023 19:08:42 +0800 Subject: [PATCH 1/3] s3s: add S3ServiceBuilder --- codegen/src/ops.rs | 3 +- crates/s3s-fs/src/main.rs | 33 +++--- crates/s3s-fs/tests/it_aws.rs | 28 +++-- crates/s3s-proxy/src/main.rs | 35 +++--- crates/s3s/src/ops/generated.rs | 187 ++++++++++++++++---------------- crates/s3s/src/ops/mod.rs | 12 +- crates/s3s/src/service.rs | 35 ++++-- 7 files changed, 187 insertions(+), 146 deletions(-) diff --git a/codegen/src/ops.rs b/codegen/src/ops.rs index 471d34a7..2e072cd7 100644 --- a/codegen/src/ops.rs +++ b/codegen/src/ops.rs @@ -110,6 +110,7 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes, g: &mut Codegen) { "use crate::s3_trait::S3;", "", "use std::borrow::Cow;", + "use std::sync::Arc;", "", ]); @@ -596,7 +597,7 @@ fn codegen_op_http_call(op: &Operation, g: &mut Codegen) { g.ln("}"); g.lf(); - g.ln("async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result {"); + g.ln("async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result {"); let method = op.name.to_snake_case(); diff --git a/crates/s3s-fs/src/main.rs b/crates/s3s-fs/src/main.rs index 3224ad05..12eeeef8 100644 --- a/crates/s3s-fs/src/main.rs +++ b/crates/s3s-fs/src/main.rs @@ -5,7 +5,7 @@ use s3s_fs::FileSystem; use s3s_fs::Result; use s3s::auth::SimpleAuth; -use s3s::service::S3Service; +use s3s::service::S3ServiceBuilder; use std::net::TcpListener; use std::path::PathBuf; @@ -48,20 +48,25 @@ async fn main() -> Result { setup_tracing(); let opt = Opt::parse(); - // Setup S3 service + // Setup S3 provider let fs = FileSystem::new(opt.root)?; - let mut service = S3Service::new(Box::new(fs)); - - // Enable authentication - if let (Some(ak), Some(sk)) = (opt.access_key, opt.secret_key) { - let auth = SimpleAuth::from_single(ak, sk); - service.set_auth(Box::new(auth)); - } - - // Enable parsing virtual-hosted-style requests - if let Some(domain_name) = opt.domain_name { - service.set_base_domain(domain_name); - } + + // Setup S3 service + let service = { + let mut b = S3ServiceBuilder::new(fs); + + // Enable authentication + if let (Some(ak), Some(sk)) = (opt.access_key, opt.secret_key) { + b.set_auth(SimpleAuth::from_single(ak, sk)); + } + + // Enable parsing virtual-hosted-style requests + if let Some(domain_name) = opt.domain_name { + b.set_base_domain(domain_name); + } + + b.build() + }; // Run server let listener = TcpListener::bind((opt.host.as_str(), opt.port))?; diff --git a/crates/s3s-fs/tests/it_aws.rs b/crates/s3s-fs/tests/it_aws.rs index d3ac84ae..72f748f3 100644 --- a/crates/s3s-fs/tests/it_aws.rs +++ b/crates/s3s-fs/tests/it_aws.rs @@ -4,7 +4,9 @@ clippy::must_use_candidate, // )] -use s3s::service::S3Service; +use s3s::auth::SimpleAuth; +use s3s::service::S3ServiceBuilder; +use s3s_fs::FileSystem; use std::env; use std::fs; @@ -49,21 +51,25 @@ fn config() -> &'static SdkConfig { static CONFIG: Lazy = Lazy::new(|| { setup_tracing(); + // Fake credentials let cred = Credentials::for_tests(); - let conn = { - fs::create_dir_all(FS_ROOT).unwrap(); - let fs = s3s_fs::FileSystem::new(FS_ROOT).unwrap(); + // Setup S3 provider + fs::create_dir_all(FS_ROOT).unwrap(); + let fs = FileSystem::new(FS_ROOT).unwrap(); - let auth = s3s::auth::SimpleAuth::from_single(cred.access_key_id(), cred.secret_access_key()); - - let mut service = S3Service::new(Box::new(fs)); - service.set_auth(Box::new(auth)); - service.set_base_domain(DOMAIN_NAME); - - s3s_aws::Connector::from(service.into_shared()) + // Setup S3 service + let service = { + let mut b = S3ServiceBuilder::new(fs); + b.set_auth(SimpleAuth::from_single(cred.access_key_id(), cred.secret_access_key())); + b.set_base_domain(DOMAIN_NAME); + b.build() }; + // Convert to aws http connector + let conn = s3s_aws::Connector::from(service.into_shared()); + + // Setup aws sdk config SdkConfig::builder() .credentials_provider(SharedCredentialsProvider::new(cred)) .http_connector(conn) diff --git a/crates/s3s-proxy/src/main.rs b/crates/s3s-proxy/src/main.rs index b5974185..f2e82835 100644 --- a/crates/s3s-proxy/src/main.rs +++ b/crates/s3s-proxy/src/main.rs @@ -2,7 +2,7 @@ #![deny(clippy::all)] use s3s::auth::SimpleAuth; -use s3s::service::S3Service; +use s3s::service::S3ServiceBuilder; use std::error::Error; use std::net::TcpListener; @@ -42,22 +42,27 @@ async fn main() -> Result<(), Box> { setup_tracing(); let opt = Opt::parse(); - // Setup S3 service + // Setup S3 provider let conf = aws_config::from_env().endpoint_url(&opt.endpoint_url).load().await; let proxy = s3s_aws::Proxy::from(aws_sdk_s3::Client::new(&conf)); - let mut service = S3Service::new(Box::new(proxy)); - - // Enable authentication - if let Some(cred_provider) = conf.credentials_provider() { - let cred = cred_provider.provide_credentials().await?; - let auth = SimpleAuth::from_single(cred.access_key_id(), cred.secret_access_key()); - service.set_auth(Box::new(auth)); - } - - // Enable parsing virtual-hosted-style requests - if let Some(domain_name) = opt.domain_name { - service.set_base_domain(domain_name); - } + + // Setup S3 service + let service = { + let mut b = S3ServiceBuilder::new(proxy); + + // Enable authentication + if let Some(cred_provider) = conf.credentials_provider() { + let cred = cred_provider.provide_credentials().await?; + b.set_auth(SimpleAuth::from_single(cred.access_key_id(), cred.secret_access_key())); + } + + // Enable parsing virtual-hosted-style requests + if let Some(domain_name) = opt.domain_name { + b.set_base_domain(domain_name); + } + + b.build() + }; // Run server let listener = TcpListener::bind((opt.host.as_str(), opt.port))?; diff --git a/crates/s3s/src/ops/generated.rs b/crates/s3s/src/ops/generated.rs index c0da017c..e6d048cd 100644 --- a/crates/s3s/src/ops/generated.rs +++ b/crates/s3s/src/ops/generated.rs @@ -11,6 +11,7 @@ use crate::path::S3Path; use crate::s3_trait::S3; use std::borrow::Cow; +use std::sync::Arc; impl http::TryIntoHeaderValue for ArchiveStatus { type Error = http::InvalidHeaderValue; @@ -334,7 +335,7 @@ impl super::Operation for AbortMultipartUpload { "AbortMultipartUpload" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.abort_multipart_upload(req).await; @@ -412,7 +413,7 @@ impl super::Operation for CompleteMultipartUpload { "CompleteMultipartUpload" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.complete_multipart_upload(req).await; @@ -591,7 +592,7 @@ impl super::Operation for CopyObject { "CopyObject" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.copy_object(req).await; @@ -655,7 +656,7 @@ impl super::Operation for CreateBucket { "CreateBucket" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.create_bucket(req).await; @@ -793,7 +794,7 @@ impl super::Operation for CreateMultipartUpload { "CreateMultipartUpload" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.create_multipart_upload(req).await; @@ -830,7 +831,7 @@ impl super::Operation for DeleteBucket { "DeleteBucket" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket(req).await; @@ -870,7 +871,7 @@ impl super::Operation for DeleteBucketAnalyticsConfiguration { "DeleteBucketAnalyticsConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_analytics_configuration(req).await; @@ -907,7 +908,7 @@ impl super::Operation for DeleteBucketCors { "DeleteBucketCors" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_cors(req).await; @@ -944,7 +945,7 @@ impl super::Operation for DeleteBucketEncryption { "DeleteBucketEncryption" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_encryption(req).await; @@ -978,7 +979,7 @@ impl super::Operation for DeleteBucketIntelligentTieringConfiguration { "DeleteBucketIntelligentTieringConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_intelligent_tiering_configuration(req).await; @@ -1018,7 +1019,7 @@ impl super::Operation for DeleteBucketInventoryConfiguration { "DeleteBucketInventoryConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_inventory_configuration(req).await; @@ -1055,7 +1056,7 @@ impl super::Operation for DeleteBucketLifecycle { "DeleteBucketLifecycle" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_lifecycle(req).await; @@ -1095,7 +1096,7 @@ impl super::Operation for DeleteBucketMetricsConfiguration { "DeleteBucketMetricsConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_metrics_configuration(req).await; @@ -1132,7 +1133,7 @@ impl super::Operation for DeleteBucketOwnershipControls { "DeleteBucketOwnershipControls" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_ownership_controls(req).await; @@ -1169,7 +1170,7 @@ impl super::Operation for DeleteBucketPolicy { "DeleteBucketPolicy" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_policy(req).await; @@ -1206,7 +1207,7 @@ impl super::Operation for DeleteBucketReplication { "DeleteBucketReplication" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_replication(req).await; @@ -1243,7 +1244,7 @@ impl super::Operation for DeleteBucketTagging { "DeleteBucketTagging" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_tagging(req).await; @@ -1280,7 +1281,7 @@ impl super::Operation for DeleteBucketWebsite { "DeleteBucketWebsite" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_bucket_website(req).await; @@ -1335,7 +1336,7 @@ impl super::Operation for DeleteObject { "DeleteObject" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_object(req).await; @@ -1378,7 +1379,7 @@ impl super::Operation for DeleteObjectTagging { "DeleteObjectTagging" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_object_tagging(req).await; @@ -1434,7 +1435,7 @@ impl super::Operation for DeleteObjects { "DeleteObjects" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_objects(req).await; @@ -1471,7 +1472,7 @@ impl super::Operation for DeletePublicAccessBlock { "DeletePublicAccessBlock" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.delete_public_access_block(req).await; @@ -1510,7 +1511,7 @@ impl super::Operation for GetBucketAccelerateConfiguration { "GetBucketAccelerateConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_accelerate_configuration(req).await; @@ -1549,7 +1550,7 @@ impl super::Operation for GetBucketAcl { "GetBucketAcl" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_acl(req).await; @@ -1593,7 +1594,7 @@ impl super::Operation for GetBucketAnalyticsConfiguration { "GetBucketAnalyticsConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_analytics_configuration(req).await; @@ -1632,7 +1633,7 @@ impl super::Operation for GetBucketCors { "GetBucketCors" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_cors(req).await; @@ -1673,7 +1674,7 @@ impl super::Operation for GetBucketEncryption { "GetBucketEncryption" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_encryption(req).await; @@ -1711,7 +1712,7 @@ impl super::Operation for GetBucketIntelligentTieringConfiguration { "GetBucketIntelligentTieringConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_intelligent_tiering_configuration(req).await; @@ -1755,7 +1756,7 @@ impl super::Operation for GetBucketInventoryConfiguration { "GetBucketInventoryConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_inventory_configuration(req).await; @@ -1794,7 +1795,7 @@ impl super::Operation for GetBucketLifecycleConfiguration { "GetBucketLifecycleConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_lifecycle_configuration(req).await; @@ -1833,7 +1834,7 @@ impl super::Operation for GetBucketLocation { "GetBucketLocation" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_location(req).await; @@ -1872,7 +1873,7 @@ impl super::Operation for GetBucketLogging { "GetBucketLogging" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_logging(req).await; @@ -1916,7 +1917,7 @@ impl super::Operation for GetBucketMetricsConfiguration { "GetBucketMetricsConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_metrics_configuration(req).await; @@ -1955,7 +1956,7 @@ impl super::Operation for GetBucketNotificationConfiguration { "GetBucketNotificationConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_notification_configuration(req).await; @@ -1996,7 +1997,7 @@ impl super::Operation for GetBucketOwnershipControls { "GetBucketOwnershipControls" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_ownership_controls(req).await; @@ -2037,7 +2038,7 @@ impl super::Operation for GetBucketPolicy { "GetBucketPolicy" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_policy(req).await; @@ -2078,7 +2079,7 @@ impl super::Operation for GetBucketPolicyStatus { "GetBucketPolicyStatus" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_policy_status(req).await; @@ -2119,7 +2120,7 @@ impl super::Operation for GetBucketReplication { "GetBucketReplication" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_replication(req).await; @@ -2158,7 +2159,7 @@ impl super::Operation for GetBucketRequestPayment { "GetBucketRequestPayment" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_request_payment(req).await; @@ -2197,7 +2198,7 @@ impl super::Operation for GetBucketTagging { "GetBucketTagging" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_tagging(req).await; @@ -2236,7 +2237,7 @@ impl super::Operation for GetBucketVersioning { "GetBucketVersioning" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_versioning(req).await; @@ -2275,7 +2276,7 @@ impl super::Operation for GetBucketWebsite { "GetBucketWebsite" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_bucket_website(req).await; @@ -2417,7 +2418,7 @@ impl super::Operation for GetObject { "GetObject" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_object(req).await; @@ -2464,7 +2465,7 @@ impl super::Operation for GetObjectAcl { "GetObjectAcl" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_object_acl(req).await; @@ -2534,7 +2535,7 @@ impl super::Operation for GetObjectAttributes { "GetObjectAttributes" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_object_attributes(req).await; @@ -2582,7 +2583,7 @@ impl super::Operation for GetObjectLegalHold { "GetObjectLegalHold" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_object_legal_hold(req).await; @@ -2623,7 +2624,7 @@ impl super::Operation for GetObjectLockConfiguration { "GetObjectLockConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_object_lock_configuration(req).await; @@ -2671,7 +2672,7 @@ impl super::Operation for GetObjectRetention { "GetObjectRetention" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_object_retention(req).await; @@ -2718,7 +2719,7 @@ impl super::Operation for GetObjectTagging { "GetObjectTagging" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_object_tagging(req).await; @@ -2764,7 +2765,7 @@ impl super::Operation for GetObjectTorrent { "GetObjectTorrent" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_object_torrent(req).await; @@ -2805,7 +2806,7 @@ impl super::Operation for GetPublicAccessBlock { "GetPublicAccessBlock" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.get_public_access_block(req).await; @@ -2842,7 +2843,7 @@ impl super::Operation for HeadBucket { "HeadBucket" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.head_bucket(req).await; @@ -2960,7 +2961,7 @@ impl super::Operation for HeadObject { "HeadObject" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.head_object(req).await; @@ -3002,7 +3003,7 @@ impl super::Operation for ListBucketAnalyticsConfigurations { "ListBucketAnalyticsConfigurations" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.list_bucket_analytics_configurations(req).await; @@ -3041,7 +3042,7 @@ impl super::Operation for ListBucketIntelligentTieringConfigurations { "ListBucketIntelligentTieringConfigurations" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.list_bucket_intelligent_tiering_configurations(req).await; @@ -3083,7 +3084,7 @@ impl super::Operation for ListBucketInventoryConfigurations { "ListBucketInventoryConfigurations" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.list_bucket_inventory_configurations(req).await; @@ -3125,7 +3126,7 @@ impl super::Operation for ListBucketMetricsConfigurations { "ListBucketMetricsConfigurations" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.list_bucket_metrics_configurations(req).await; @@ -3157,7 +3158,7 @@ impl super::Operation for ListBuckets { "ListBuckets" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.list_buckets(req).await; @@ -3214,7 +3215,7 @@ impl super::Operation for ListMultipartUploads { "ListMultipartUploads" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.list_multipart_uploads(req).await; @@ -3271,7 +3272,7 @@ impl super::Operation for ListObjectVersions { "ListObjectVersions" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.list_object_versions(req).await; @@ -3328,7 +3329,7 @@ impl super::Operation for ListObjects { "ListObjects" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.list_objects(req).await; @@ -3391,7 +3392,7 @@ impl super::Operation for ListObjectsV2 { "ListObjectsV2" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.list_objects_v2(req).await; @@ -3457,7 +3458,7 @@ impl super::Operation for ListParts { "ListParts" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.list_parts(req).await; @@ -3500,7 +3501,7 @@ impl super::Operation for PutBucketAccelerateConfiguration { "PutBucketAccelerateConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_accelerate_configuration(req).await; @@ -3564,7 +3565,7 @@ impl super::Operation for PutBucketAcl { "PutBucketAcl" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_acl(req).await; @@ -3607,7 +3608,7 @@ impl super::Operation for PutBucketAnalyticsConfiguration { "PutBucketAnalyticsConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_analytics_configuration(req).await; @@ -3653,7 +3654,7 @@ impl super::Operation for PutBucketCors { "PutBucketCors" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_cors(req).await; @@ -3699,7 +3700,7 @@ impl super::Operation for PutBucketEncryption { "PutBucketEncryption" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_encryption(req).await; @@ -3739,7 +3740,7 @@ impl super::Operation for PutBucketIntelligentTieringConfiguration { "PutBucketIntelligentTieringConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_intelligent_tiering_configuration(req).await; @@ -3782,7 +3783,7 @@ impl super::Operation for PutBucketInventoryConfiguration { "PutBucketInventoryConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_inventory_configuration(req).await; @@ -3825,7 +3826,7 @@ impl super::Operation for PutBucketLifecycleConfiguration { "PutBucketLifecycleConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_lifecycle_configuration(req).await; @@ -3871,7 +3872,7 @@ impl super::Operation for PutBucketLogging { "PutBucketLogging" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_logging(req).await; @@ -3914,7 +3915,7 @@ impl super::Operation for PutBucketMetricsConfiguration { "PutBucketMetricsConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_metrics_configuration(req).await; @@ -3958,7 +3959,7 @@ impl super::Operation for PutBucketNotificationConfiguration { "PutBucketNotificationConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_notification_configuration(req).await; @@ -4001,7 +4002,7 @@ impl super::Operation for PutBucketOwnershipControls { "PutBucketOwnershipControls" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_ownership_controls(req).await; @@ -4051,7 +4052,7 @@ impl super::Operation for PutBucketPolicy { "PutBucketPolicy" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_policy(req).await; @@ -4100,7 +4101,7 @@ impl super::Operation for PutBucketReplication { "PutBucketReplication" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_replication(req).await; @@ -4146,7 +4147,7 @@ impl super::Operation for PutBucketRequestPayment { "PutBucketRequestPayment" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_request_payment(req).await; @@ -4192,7 +4193,7 @@ impl super::Operation for PutBucketTagging { "PutBucketTagging" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_tagging(req).await; @@ -4241,7 +4242,7 @@ impl super::Operation for PutBucketVersioning { "PutBucketVersioning" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_versioning(req).await; @@ -4287,7 +4288,7 @@ impl super::Operation for PutBucketWebsite { "PutBucketWebsite" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_bucket_website(req).await; @@ -4594,7 +4595,7 @@ impl super::Operation for PutObject { "PutObject" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_object(req).await; @@ -4667,7 +4668,7 @@ impl super::Operation for PutObjectAcl { "PutObjectAcl" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_object_acl(req).await; @@ -4722,7 +4723,7 @@ impl super::Operation for PutObjectLegalHold { "PutObjectLegalHold" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_object_legal_hold(req).await; @@ -4776,7 +4777,7 @@ impl super::Operation for PutObjectLockConfiguration { "PutObjectLockConfiguration" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_object_lock_configuration(req).await; @@ -4835,7 +4836,7 @@ impl super::Operation for PutObjectRetention { "PutObjectRetention" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_object_retention(req).await; @@ -4890,7 +4891,7 @@ impl super::Operation for PutObjectTagging { "PutObjectTagging" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_object_tagging(req).await; @@ -4936,7 +4937,7 @@ impl super::Operation for PutPublicAccessBlock { "PutPublicAccessBlock" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.put_public_access_block(req).await; @@ -4989,7 +4990,7 @@ impl super::Operation for RestoreObject { "RestoreObject" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.restore_object(req).await; @@ -5045,7 +5046,7 @@ impl super::Operation for SelectObjectContent { "SelectObjectContent" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.select_object_content(req).await; @@ -5139,7 +5140,7 @@ impl super::Operation for UploadPart { "UploadPart" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.upload_part(req).await; @@ -5244,7 +5245,7 @@ impl super::Operation for UploadPartCopy { "UploadPartCopy" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.upload_part_copy(req).await; @@ -5408,7 +5409,7 @@ impl super::Operation for WriteGetObjectResponse { "WriteGetObjectResponse" } - async fn call(&self, s3: &dyn S3, req: &mut http::Request) -> S3Result { + async fn call(&self, s3: &Arc, req: &mut http::Request) -> S3Result { let input = Self::deserialize_http(req)?; let req = super::build_s3_request(input, req); let result = s3.write_get_object_response(req).await; diff --git a/crates/s3s/src/ops/mod.rs b/crates/s3s/src/ops/mod.rs index 7923a842..c6c1f75f 100644 --- a/crates/s3s/src/ops/mod.rs +++ b/crates/s3s/src/ops/mod.rs @@ -26,6 +26,7 @@ use crate::utils::is_base64_encoded; use std::mem; use std::ops::Not; +use std::sync::Arc; use bytes::Bytes; use bytestring::ByteString; @@ -41,7 +42,7 @@ use tracing::debug; pub trait Operation: Send + Sync + 'static { fn name(&self) -> &'static str; - async fn call(&self, s3: &dyn S3, req: &mut Request) -> S3Result; + async fn call(&self, s3: &Arc, req: &mut Request) -> S3Result; } fn build_s3_request(input: T, req: &mut Request) -> S3Request { @@ -196,7 +197,12 @@ fn fmt_content_length(len: usize) -> http::HeaderValue { } } -pub async fn call(req: &mut Request, s3: &dyn S3, auth: Option<&dyn S3Auth>, base_domain: Option<&str>) -> S3Result { +pub async fn call( + req: &mut Request, + s3: &Arc, + auth: Option<&dyn S3Auth>, + base_domain: Option<&str>, +) -> S3Result { let op = match prepare(req, auth, base_domain).await { Ok(op) => op, Err(err) => { @@ -692,7 +698,7 @@ mod tests { #[test] fn track_future_size() { let sizes = [ - (output_size(&S3Service::call), 2632), + (output_size(&S3Service::call), 2616), (output_size(&call), 1448), (output_size(&prepare), 1360), (output_size(&SignatureContext::check), 752), diff --git a/crates/s3s/src/service.rs b/crates/s3s/src/service.rs index 9ff2a759..2cacde15 100644 --- a/crates/s3s/src/service.rs +++ b/crates/s3s/src/service.rs @@ -12,30 +12,47 @@ use futures::future::BoxFuture; use hyper::service::Service; use tracing::{debug, error}; -pub struct S3Service { - s3: Box, +pub struct S3ServiceBuilder { + s3: Arc, auth: Option>, base_domain: Option, } -impl S3Service { +impl S3ServiceBuilder { #[must_use] - pub fn new(s3: Box) -> Self { + pub fn new(s3: impl S3) -> Self { Self { - s3, + s3: Arc::new(s3), auth: None, base_domain: None, } } - pub fn set_auth(&mut self, auth: Box) { - self.auth = Some(auth); + pub fn set_auth(&mut self, auth: impl S3Auth) { + self.auth = Some(Box::new(auth)); } pub fn set_base_domain(&mut self, base_domain: impl Into) { self.base_domain = Some(base_domain.into()); } + #[must_use] + pub fn build(self) -> S3Service { + S3Service { + s3: self.s3, + auth: self.auth, + base_domain: self.base_domain, + } + } +} + +pub struct S3Service { + s3: Arc, + auth: Option>, + base_domain: Option, +} + +impl S3Service { #[tracing::instrument( level = "debug", skip(self, req), @@ -46,7 +63,7 @@ impl S3Service { let mut req = Request::from(req); - let s3 = &*self.s3; + let s3 = &self.s3; let auth = self.auth.as_deref(); let base_domain = self.base_domain.as_deref(); let result = crate::ops::call(&mut req, s3, auth, base_domain).await.map(Into::into); @@ -95,7 +112,7 @@ impl Service> for SharedS3Service { type Future = BoxFuture<'static, Result>; fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll> { - Poll::Ready(Ok(())) // ASK: back pressure? + Poll::Ready(Ok(())) // TODO: back pressure? } fn call(&mut self, req: hyper::Request) -> Self::Future { From c0ad2fd483878ecf43512ce196a0e0a37d8e872a Mon Sep 17 00:00:00 2001 From: Nugine Date: Tue, 11 Apr 2023 19:15:03 +0800 Subject: [PATCH 2/3] track future size --- crates/s3s/src/ops/mod.rs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/crates/s3s/src/ops/mod.rs b/crates/s3s/src/ops/mod.rs index c6c1f75f..7fd17bc6 100644 --- a/crates/s3s/src/ops/mod.rs +++ b/crates/s3s/src/ops/mod.rs @@ -697,22 +697,30 @@ mod tests { #[test] fn track_future_size() { + macro_rules! future_size { + ($f:path, $v:expr) => { + (stringify!($f), output_size(&$f), $v) + }; + } + + #[rustfmt::skip] let sizes = [ - (output_size(&S3Service::call), 2616), - (output_size(&call), 1448), - (output_size(&prepare), 1360), - (output_size(&SignatureContext::check), 752), - (output_size(&SignatureContext::v2_check), 280), - (output_size(&SignatureContext::v2_check_presigned_url), 184), - (output_size(&SignatureContext::v2_check_header_auth), 184), - (output_size(&SignatureContext::v4_check), 728), - (output_size(&SignatureContext::v4_check_post_signature), 368), - (output_size(&SignatureContext::v4_check_presigned_url), 456), - (output_size(&SignatureContext::v4_check_header_auth), 632), + future_size!(S3Service::call, 2616), + future_size!(call, 1432), + future_size!(prepare, 1360), + future_size!(SignatureContext::check, 752), + future_size!(SignatureContext::v2_check, 280), + future_size!(SignatureContext::v2_check_presigned_url, 184), + future_size!(SignatureContext::v2_check_header_auth, 184), + future_size!(SignatureContext::v4_check, 728), + future_size!(SignatureContext::v4_check_post_signature, 368), + future_size!(SignatureContext::v4_check_presigned_url, 456), + future_size!(SignatureContext::v4_check_header_auth, 632), ]; - println!("{:?}", sizes); - for (size, expected) in sizes { - assert_eq!(size, expected); + + println!("{:#?}", sizes); + for (name, size, expected) in sizes { + assert_eq!(size, expected, "{name:?} size changed: prev {expected}, now {size}"); } } } From 4afbad4d6d54a3da835608795a4208530e9e588c Mon Sep 17 00:00:00 2001 From: Nugine Date: Tue, 11 Apr 2023 19:29:34 +0800 Subject: [PATCH 3/3] bump version --- crates/s3s-aws/Cargo.toml | 4 ++-- crates/s3s-fs/Cargo.toml | 6 +++--- crates/s3s-proxy/Cargo.toml | 4 ++-- crates/s3s/Cargo.toml | 2 +- justfile | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/s3s-aws/Cargo.toml b/crates/s3s-aws/Cargo.toml index e7d2c5a2..f68b125b 100644 --- a/crates/s3s-aws/Cargo.toml +++ b/crates/s3s-aws/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "s3s-aws" -version = "0.4.1-dev" +version = "0.5.0-dev" edition = "2021" description = "S3 service adapter integrated with aws-sdk-s3" license = "Apache-2.0" @@ -18,7 +18,7 @@ aws-smithy-types-convert = { version = "0.55.0", features = ["convert-time"] } bytes = "1.4.0" futures = { version = "0.3.28", default-features = false, features = ["std"] } hyper = "0.14.25" -s3s = { version = "0.4.1-dev", path = "../s3s" } +s3s = { version = "0.5.0-dev", path = "../s3s" } sync_wrapper = "0.1.2" tracing = "0.1.37" transform-stream = "0.3.0" diff --git a/crates/s3s-fs/Cargo.toml b/crates/s3s-fs/Cargo.toml index 9531dae6..001361b7 100644 --- a/crates/s3s-fs/Cargo.toml +++ b/crates/s3s-fs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "s3s-fs" -version = "0.4.1-dev" +version = "0.5.0-dev" edition = "2021" description = "An experimental S3 server based on file system" license = "Apache-2.0" @@ -29,7 +29,7 @@ md-5 = "0.10.5" mime = "0.3.17" numeric_cast = "0.2.1" path-absolutize = "3.0.14" -s3s = { version = "0.4.1-dev", path = "../s3s" } +s3s = { version = "0.5.0-dev", path = "../s3s" } serde_json = "1.0.95" thiserror = "1.0.40" time = "0.3.20" @@ -47,6 +47,6 @@ aws-config = "0.55.0" aws-credential-types = { version = "0.55.0", features = ["test-util"] } aws-sdk-s3 = "0.25.1" once_cell = "1.17.1" -s3s-aws = { version = "0.4.1-dev", path = "../s3s-aws" } +s3s-aws = { version = "0.5.0-dev", path = "../s3s-aws" } tokio = { version = "1.27.0", features = ["full"] } tracing-subscriber = { version = "0.3.16", features = ["env-filter", "time"] } diff --git a/crates/s3s-proxy/Cargo.toml b/crates/s3s-proxy/Cargo.toml index 717bef93..104dd748 100644 --- a/crates/s3s-proxy/Cargo.toml +++ b/crates/s3s-proxy/Cargo.toml @@ -10,8 +10,8 @@ aws-credential-types = "0.55.0" aws-sdk-s3 = "0.25.1" clap = { version = "4.2.1", features = ["derive"] } hyper = { version = "0.14.25", features = ["full"] } -s3s = { version = "0.4.1-dev", path = "../s3s" } -s3s-aws = { version = "0.4.1-dev", path = "../s3s-aws" } +s3s = { version = "0.5.0-dev", path = "../s3s" } +s3s-aws = { version = "0.5.0-dev", path = "../s3s-aws" } tokio = { version = "1.27.0", features = ["full"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3.16", features = ["env-filter", "time"] } diff --git a/crates/s3s/Cargo.toml b/crates/s3s/Cargo.toml index 5a5089c7..8b85e468 100644 --- a/crates/s3s/Cargo.toml +++ b/crates/s3s/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "s3s" -version = "0.4.1-dev" +version = "0.5.0-dev" edition = "2021" description = "S3 Service Adapter" license = "Apache-2.0" diff --git a/justfile b/justfile index c5a8707b..fe5d67d4 100644 --- a/justfile +++ b/justfile @@ -27,9 +27,9 @@ install: sync-version: cargo set-version -p s3s-codegen 0.0.0 - cargo set-version -p s3s 0.4.1-dev - cargo set-version -p s3s-aws 0.4.1-dev - cargo set-version -p s3s-fs 0.4.1-dev + cargo set-version -p s3s 0.5.0-dev + cargo set-version -p s3s-aws 0.5.0-dev + cargo set-version -p s3s-fs 0.5.0-dev cargo set-version -p s3s-proxy 0.0.0 publish: