Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add S3ServiceBuilder #32

Merged
merged 3 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion codegen/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;",
"",
]);

Expand Down Expand Up @@ -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<http::Response> {");
g.ln("async fn call(&self, s3: &Arc<dyn S3>, req: &mut http::Request) -> S3Result<http::Response> {");

let method = op.name.to_snake_case();

Expand Down
4 changes: 2 additions & 2 deletions crates/s3s-aws/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
6 changes: 3 additions & 3 deletions crates/s3s-fs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"] }
33 changes: 19 additions & 14 deletions crates/s3s-fs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))?;
Expand Down
28 changes: 17 additions & 11 deletions crates/s3s-fs/tests/it_aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,21 +51,25 @@ fn config() -> &'static SdkConfig {
static CONFIG: Lazy<SdkConfig> = 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)
Expand Down
4 changes: 2 additions & 2 deletions crates/s3s-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
35 changes: 20 additions & 15 deletions crates/s3s-proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,22 +42,27 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
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))?;
Expand Down
2 changes: 1 addition & 1 deletion crates/s3s/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
Loading