-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
193 additions
and
110 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod barrier_cell; | ||
pub mod conda_environment_file; | ||
pub mod reqwest; | ||
pub mod spanned; | ||
|
||
pub use barrier_cell::BarrierCell; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::path::PathBuf; | ||
use std::{sync::Arc, time::Duration}; | ||
|
||
use rattler_networking::AuthenticationMiddleware; | ||
use rattler_networking::{MirrorMiddleware, OciMiddleware}; | ||
use reqwest::Client; | ||
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; | ||
|
||
use crate::config::Config; | ||
|
||
fn mirror_middleware() -> MirrorMiddleware { | ||
let config = Config::from_path(&PathBuf::from("./config.toml")).expect("Failed to load config"); | ||
let mirror_map = config.mirror_map(); | ||
// let mut mirror_map = HashMap::new(); | ||
// mirror_map.insert( | ||
// "https://conda.anaconda.org/conda-forge".to_string(), | ||
// vec![ | ||
// // "https://repo.prefix.dev/conda-forge".to_string() | ||
// "oci://ghcr.io/channel-mirrors/conda-forge".to_string(), | ||
// ], | ||
// ); | ||
MirrorMiddleware::from_map(mirror_map) | ||
} | ||
|
||
fn oci_middleware() -> OciMiddleware { | ||
OciMiddleware::default() | ||
} | ||
|
||
pub(crate) fn build_reqwest_clients() -> (Client, ClientWithMiddleware) { | ||
static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),); | ||
|
||
let timeout = 5 * 60; | ||
let client = Client::builder() | ||
.pool_max_idle_per_host(20) | ||
.user_agent(APP_USER_AGENT) | ||
.timeout(Duration::from_secs(timeout)) | ||
.build() | ||
.expect("failed to create reqwest Client"); | ||
|
||
let authenticated_client = ClientBuilder::new(client.clone()) | ||
.with_arc(Arc::new(AuthenticationMiddleware::default())) | ||
.with(mirror_middleware()) | ||
.with(oci_middleware()) | ||
.build(); | ||
|
||
(client, authenticated_client) | ||
} |