Skip to content

Commit

Permalink
update google-cloud-auth and rename feature to gcs
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Nov 1, 2024
1 parent b049858 commit addb3c4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ fxhash = "0.2.1"
generic-array = "0.14.7"
getrandom = { version = "0.2.15", default-features = false }
glob = "0.3.1"
google-cloud-auth = { version = "0.13.2", default-features = false }
google-cloud-auth = { version = "0.17.1", default-features = false }
google-cloud-token = "0.1.2"
hex = "0.4.3"
hex-literal = "0.4.1"
http = "1.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ indicatif = { workspace = true }
once_cell = { workspace = true }
rattler = { path="../rattler", version = "0.27.16", default-features = false, features = ["indicatif"] }
rattler_conda_types = { path="../rattler_conda_types", version = "0.28.3", default-features = false }
rattler_networking = { path="../rattler_networking", version = "0.21.4", default-features = false, features = ["google-cloud-auth"] }
rattler_networking = { path="../rattler_networking", version = "0.21.4", default-features = false, features = ["gcs"] }
rattler_repodata_gateway = { path="../rattler_repodata_gateway", version = "0.21.18", default-features = false, features = ["gateway"] }
rattler_solve = { path="../rattler_solve", version = "1.1.0", default-features = false, features = ["resolvo", "libsolv_c"] }
rattler_virtual_packages = { path="../rattler_virtual_packages", version = "1.1.7", default-features = false }
Expand Down
6 changes: 4 additions & 2 deletions crates/rattler_networking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ readme.workspace = true

[features]
default = ["native-tls"]
native-tls = ['reqwest/native-tls', "google-cloud-auth?/default-tls"]
rustls-tls = ['reqwest/rustls-tls', "google-cloud-auth?/rustls-tls"]
native-tls = ["reqwest/native-tls", "google-cloud-auth?/default-tls"]
rustls-tls = ["reqwest/rustls-tls", "google-cloud-auth?/rustls-tls"]
gcs = ["google-cloud-auth", "google-cloud-token"]

[dependencies]
anyhow = { workspace = true }
Expand All @@ -23,6 +24,7 @@ chrono = { workspace = true }
dirs = { workspace = true }
fslock = { workspace = true }
google-cloud-auth = { workspace = true, optional = true }
google-cloud-token = { workspace = true, optional = true }
http = { workspace = true }
itertools = { workspace = true }
keyring = { workspace = true, features = ["apple-native", "windows-native", "async-secret-service", "async-io", "crypto-rust"] }
Expand Down
24 changes: 13 additions & 11 deletions crates/rattler_networking/src/gcs_middleware.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Middleware to handle `gcs://` URLs to pull artifacts from an GCS
use async_trait::async_trait;
use google_cloud_auth::project::{create_token_source, Config};
use google_cloud_auth::{project::Config, token::DefaultTokenSourceProvider};
use google_cloud_token::TokenSourceProvider;
use reqwest::{Request, Response};
use reqwest_middleware::{Middleware, Next, Result as MiddlewareResult};
use url::Url;
Expand Down Expand Up @@ -40,23 +41,24 @@ async fn authenticate_with_google_cloud(mut req: Request) -> MiddlewareResult<Re
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/devstorage.read_only",
];
match create_token_source(Config {
audience: Some(audience),
scopes: Some(&scopes),
sub: None,
})
.await
{
Ok(ts) => match ts.token().await {
let config = Config::default()
.with_audience(audience)
.with_scopes(&scopes);

match DefaultTokenSourceProvider::new(config).await {
Ok(provider) => match provider.token_source().token().await {
Ok(token) => {
let bearer_auth = format!("Bearer {}", token.access_token);
let bearer_auth = format!("Bearer {}", token);
let header_value = reqwest::header::HeaderValue::from_str(&bearer_auth)
.map_err(reqwest_middleware::Error::middleware)?;
req.headers_mut()
.insert(reqwest::header::AUTHORIZATION, header_value);
Ok(req)
}
Err(e) => Err(reqwest_middleware::Error::Middleware(anyhow::Error::new(e))),
Err(e) => Err(reqwest_middleware::Error::Middleware(anyhow::anyhow!(
"Failed to get GCS token: {:?}",
e
))),
},
Err(e) => Err(reqwest_middleware::Error::Middleware(anyhow::Error::new(e))),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rattler_networking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pub use authentication_storage::{authentication::Authentication, storage::Authen
pub use mirror_middleware::MirrorMiddleware;
pub use oci_middleware::OciMiddleware;

#[cfg(feature = "google-cloud-auth")]
#[cfg(feature = "gcs")]
pub mod gcs_middleware;
#[cfg(feature = "google-cloud-auth")]
#[cfg(feature = "gcs")]
pub use gcs_middleware::GCSMiddleware;

pub mod authentication_middleware;
Expand Down

0 comments on commit addb3c4

Please sign in to comment.