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

feat: allow configuring pypi insecure host #2521

Merged
merged 21 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/pixi_config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serde_json = { workspace = true }
toml_edit = { workspace = true, features = ["serde"] }
tracing = { workspace = true }
url = { workspace = true }
uv-configuration = { workspace = true }
zen-xu marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
insta = { workspace = true, features = ["yaml"] }
Expand Down
33 changes: 33 additions & 0 deletions crates/pixi_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use rattler_repodata_gateway::{Gateway, SourceConfig};
use reqwest_middleware::ClientWithMiddleware;
use serde::{de::IntoDeserializer, Deserialize, Serialize};
use url::Url;
use uv_configuration::TrustedHost;

pub fn default_channel_config() -> ChannelConfig {
ChannelConfig::default_with_root_dir(
Expand Down Expand Up @@ -241,6 +242,10 @@ pub struct PyPIConfig {
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub keyring_provider: Option<KeyringProvider>,
/// Allow insecure connections to a host
#[serde(default)]
#[serde(skip_serializing_if = "Vec::is_empty")]
pub allow_insecure_host: Vec<TrustedHost>,
}

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
Expand Down Expand Up @@ -286,6 +291,11 @@ impl PyPIConfig {
index_url: other.index_url.or(self.index_url),
extra_index_urls,
keyring_provider: other.keyring_provider.or(self.keyring_provider),
allow_insecure_host: self
.allow_insecure_host
.into_iter()
.chain(other.allow_insecure_host)
.collect(),
}
}

Expand Down Expand Up @@ -1113,6 +1123,29 @@ UNUSED = "unused"
);
}

#[test]
fn test_pypi_config_allow_insecure_host() {
let toml = r#"
[pypi-config]
index-url = "https://pypi.org/simple"
extra-index-urls = ["https://pypi.org/simple2"]
keyring-provider = "subprocess"
allow-insecure-host = ["https://localhost:1234", "*"]
"#;
let (config, _) = Config::from_toml(toml).unwrap();
assert_eq!(
config.pypi_config().allow_insecure_host,
vec![
TrustedHost::Host {
scheme: Some("https".into()),
host: "localhost".into(),
port: Some(1234),
},
TrustedHost::Wildcard,
]
);
}

#[test]
fn test_config_merge() {
let mut config = Config::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Config {
index_url: None,
extra_index_urls: [],
keyring_provider: None,
allow_insecure_host: [],
},
detached_environments: Some(
Boolean(
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/pixi_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ To setup a certain number of defaults for the usage of PyPI registries. You can
- `index-url`: The default index URL to use for PyPI packages. This will be added to a manifest file on a `pixi init`.
- `extra-index-urls`: A list of additional URLs to use for PyPI packages. This will be added to a manifest file on a `pixi init`.
- `keyring-provider`: Allows the use of the [keyring](https://pypi.org/project/keyring/) python package to store and retrieve credentials.
- `allow-insecure-host`: Allow insecure connections to host.

```toml title="config.toml"
[pypi-config]
Expand All @@ -216,6 +217,8 @@ index-url = "https://pypi.org/simple"
extra-index-urls = ["https://pypi.org/simple2"]
# can be "subprocess" or "disabled"
keyring-provider = "subprocess"
# allow insecure connections to host
allow-insecure-host = ["localhost:8080"]
```

!!! Note "`index-url` and `extra-index-urls` are *not* globals"
Expand Down
1 change: 1 addition & 0 deletions src/install_pypi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ pub async fn update_python_distributions(
let registry_client = Arc::new(
RegistryClientBuilder::new(uv_context.cache.clone())
.client(uv_context.client.clone())
.allow_insecure_host(uv_context.allow_insecure_host.clone())
.index_urls(index_locations.index_urls())
.keyring(uv_context.keyring_provider)
.connectivity(Connectivity::Online)
Expand Down
4 changes: 3 additions & 1 deletion src/lock_file/resolve/uv_resolution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use miette::{Context, IntoDiagnostic};
use uv_cache::Cache;
use uv_configuration::{BuildOptions, Concurrency, SourceStrategy};
use uv_configuration::{BuildOptions, Concurrency, SourceStrategy, TrustedHost};
use uv_distribution_types::IndexCapabilities;
use uv_types::{HashStrategy, InFlight};

Expand All @@ -22,6 +22,7 @@ pub struct UvResolutionContext {
pub concurrency: Concurrency,
pub source_strategy: SourceStrategy,
pub capabilities: IndexCapabilities,
pub allow_insecure_host: Vec<TrustedHost>,
}

impl UvResolutionContext {
Expand Down Expand Up @@ -57,6 +58,7 @@ impl UvResolutionContext {
concurrency: Concurrency::default(),
source_strategy: SourceStrategy::Disabled,
capabilities: IndexCapabilities::default(),
allow_insecure_host: project.config().pypi_config.allow_insecure_host.clone(),
})
}
}
Loading