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

Allow nested mounted paths in UnionFilesystem #5008

Merged
merged 15 commits into from
Aug 21, 2024
Merged
22 changes: 22 additions & 0 deletions lib/backend-api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ impl WasmerClient {
})
}

pub fn new_with_proxy(
graphql_endpoint: Url,
user_agent: &str,
proxy: reqwest::Proxy,
) -> Result<Self, anyhow::Error> {
let builder = {
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
let mut builder = reqwest::ClientBuilder::new();

#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
let builder = reqwest::ClientBuilder::new()
.connect_timeout(Duration::from_secs(10))
.timeout(Duration::from_secs(90));

builder.proxy(proxy)
};

let client = builder.build().context("failed to create reqwest client")?;

Self::new_with_client(client, graphql_endpoint, user_agent)
}

pub fn new(graphql_endpoint: Url, user_agent: &str) -> Result<Self, anyhow::Error> {
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
let client = reqwest::Client::builder()
Expand Down
13 changes: 12 additions & 1 deletion lib/cli/src/commands/package/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ pub struct PackageDownload {
#[clap(long)]
pub quiet: bool,

/// proxy to use for downloading
#[clap(long)]
pub proxy: Option<String>,

/// The package to download.
package: PackageSource,
}
Expand Down Expand Up @@ -97,7 +101,13 @@ impl PackageDownload {
// caveat: client_unauthennticated will use a token if provided, it
// just won't fail if none is present. So, _unauthenticated() can actually
// produce an authenticated client.
let client = self.env.client_unauthennticated()?;
let client = if let Some(proxy) = &self.proxy {
let proxy = reqwest::Proxy::all(proxy)?;

self.env.client_unauthennticated_with_proxy(proxy)?
} else {
self.env.client_unauthennticated()?
};

let version = id.version_or_default().to_string();
let version = if version == "*" {
Expand Down Expand Up @@ -299,6 +309,7 @@ mod tests {
out_path: Some(out_path.clone()),
package: "wasmer/[email protected]".parse().unwrap(),
quiet: true,
proxy: None,
};

cmd.execute().unwrap();
Expand Down
20 changes: 20 additions & 0 deletions lib/cli/src/config/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,26 @@ impl WasmerEnv {
Ok(client)
}

pub fn client_unauthennticated_with_proxy(
&self,
proxy: reqwest::Proxy,
) -> Result<WasmerClient, anyhow::Error> {
let registry_url = self.registry_endpoint()?;
let client = wasmer_api::WasmerClient::new_with_proxy(
registry_url,
&DEFAULT_WASMER_CLI_USER_AGENT,
proxy,
)?;

let client = if let Some(token) = self.token() {
client.with_auth_token(token)
} else {
client
};

Ok(client)
}

pub fn client(&self) -> Result<WasmerClient, anyhow::Error> {
let client = self.client_unauthennticated()?;
if client.auth_token().is_none() {
Expand Down
2 changes: 1 addition & 1 deletion lib/virtual-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ impl From<FsError> for io::Error {
#[derive(Debug)]
pub struct ReadDir {
// TODO: to do this properly we need some kind of callback to the core FS abstraction
data: Vec<DirEntry>,
pub(crate) data: Vec<DirEntry>,
index: usize,
}

Expand Down
Loading
Loading