Skip to content

Commit

Permalink
Upgrade hyper to 1.x and related crates
Browse files Browse the repository at this point in the history
  • Loading branch information
robklg committed Jan 19, 2025
1 parent 29c5a62 commit 66865c3
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 85 deletions.
8 changes: 5 additions & 3 deletions crates/unftp-sbe-gcs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ base64 = "0.22.1"
bytes = "1.9.0"
chrono = { version = "0.4.39", default-features = false, features = ["std", "serde"] }
futures = { version = "0.3.31", default-features = false, features = ["std"] }
hyper = { version = "0.14.32", features = ["client", "runtime", "stream", "http1"] }
hyper-rustls = "0.24.2"
http-body-util = "0.1.2"
hyper = { version = "1.5.2", features = ["client", "http1"] }
hyper-rustls = "0.27.5"
hyper-util = "0.1.10"
libunftp = { version = "0.20.3", path = "../../" }
mime = "0.3.17"
percent-encoding = "2.3.1"
Expand All @@ -36,7 +38,7 @@ tokio-stream = "0.1.17"
tokio-util = { version = "0.7.13", features = ["codec", "compat"] }
tracing = { version = "0.1.41", default-features = false }
tracing-attributes = "0.1.28"
yup-oauth2 = "8.3.2"
yup-oauth2 = { version = "11.0.0", default-features = false, features = ["hyper-rustls", "service-account", "aws-lc-rs"]}

[dev-dependencies]
async_ftp = "6.0.0"
Expand Down
40 changes: 20 additions & 20 deletions crates/unftp-sbe-gcs/examples/gcs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use clap::{Arg, Command};
use libunftp::ServerBuilder;
use std::{error::Error, path::PathBuf};
use tracing::Level;
use unftp_sbe_gcs::options::AuthMethod;

// To run this example with the local fake GCS (see tests/resources/gcs_test.sh) instead of Google GCS,
// after starting fake-gcs-server, run this example with
Expand Down Expand Up @@ -38,7 +40,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
.value_name("SERVICE_ACCOUNT_KEY")
.env("LIBUNFTP_SERVICE_ACCOUNT_KEY")
.help("The service account key JSON file of the Google Cloud Storage bucket to be used")
.required(true),
.required(false),
)
.arg(
Arg::new(FAKE_GCS_BASE_URL)
Expand Down Expand Up @@ -69,34 +71,32 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
)
.get_matches();

let service_account_key_path = matches.get_one::<String>(SERVICE_ACCOUNT_KEY).unwrap();
let service_account_key_path = matches.get_one::<String>(SERVICE_ACCOUNT_KEY);
let bucket_name = matches.get_one::<String>(BUCKET_NAME).unwrap().to_owned();
let gcs_base_url = if let Some(base_url) = matches.get_one::<String>(FAKE_GCS_BASE_URL) {
String::from(base_url)
} else {
String::from("https://www.googleapis.com")
};

let service_account_key: Vec<u8> = tokio::fs::read(service_account_key_path).await?;
if let Some(ftps_certs_file) = matches.get_one::<String>(FTPS_CERTS_FILE) {
let service_account_key: Option<Vec<u8>> = match service_account_key_path {
Some(key_path) => Some(tokio::fs::read(key_path).await?),
None => None,
};

let mut builder = ServerBuilder::new(Box::new(move || match &service_account_key {
Some(key) => unftp_sbe_gcs::CloudStorage::with_api_base(&gcs_base_url, &bucket_name, PathBuf::new(), key.clone()),
None => unftp_sbe_gcs::CloudStorage::with_api_base(&gcs_base_url, &bucket_name, PathBuf::new(), AuthMethod::None),
}));

builder = if let Some(ftps_certs_file) = matches.get_one::<String>(FTPS_CERTS_FILE) {
let ftps_key_file = matches.get_one::<String>(FTPS_KEY_FILE).unwrap();
libunftp::ServerBuilder::new(Box::new(move || {
unftp_sbe_gcs::CloudStorage::with_api_base(&gcs_base_url, &bucket_name, PathBuf::new(), service_account_key.clone())
}))
.ftps(ftps_certs_file, ftps_key_file)
.build()
.unwrap()
.listen(BIND_ADDRESS)
.await?;
builder.ftps(ftps_certs_file, ftps_key_file)
} else {
libunftp::ServerBuilder::new(Box::new(move || {
unftp_sbe_gcs::CloudStorage::with_api_base(&gcs_base_url, &bucket_name, PathBuf::new(), service_account_key.clone())
}))
.build()
.unwrap()
.listen(BIND_ADDRESS)
.await?;
}
builder
};

builder.build().unwrap().listen(BIND_ADDRESS).await?;

Ok(())
}
Loading

0 comments on commit 66865c3

Please sign in to comment.