Skip to content

Commit

Permalink
Implement combine
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Oct 25, 2024
1 parent 91a493a commit 8f400da
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 91 deletions.
1 change: 0 additions & 1 deletion crates/uv-cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ impl From<ResolverInstallerArgs> for PipOptions {
reinstall_package: Some(reinstall_package),
index_strategy,
keyring_provider,
allow_insecure_host: None,
resolution,
prerelease: if pre {
Some(PrereleaseMode::Allow)
Expand Down
16 changes: 0 additions & 16 deletions crates/uv-settings/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,22 +823,6 @@ pub struct PipOptions {
"#
)]
pub keyring_provider: Option<KeyringProviderType>,
/// Allow insecure connections to host.
///
/// Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
/// `localhost:8080`), or a URL (e.g., `https://localhost`).
///
/// WARNING: Hosts included in this list will not be verified against the system's certificate
/// store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
/// bypasses SSL verification and could expose you to MITM attacks.
#[option(
default = "[]",
value_type = "list[str]",
example = r#"
allow-insecure-host = ["localhost:8080"]
"#
)]
pub allow_insecure_host: Option<Vec<TrustedHost>>,
/// Don't build source distributions.
///
/// When enabled, resolving will not run arbitrary Python code. The cached wheels of
Expand Down
10 changes: 5 additions & 5 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.index_strategy,
args.settings.dependency_metadata,
args.settings.keyring_provider,
&args.settings.allow_insecure_host,
&globals.allow_insecure_host,
args.settings.config_setting,
globals.connectivity,
args.settings.no_build_isolation,
Expand Down Expand Up @@ -439,7 +439,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.sources,
globals.concurrency,
globals.native_tls,
&args.settings.allow_insecure_host,
&globals.allow_insecure_host,
cache,
args.dry_run,
printer,
Expand Down Expand Up @@ -527,7 +527,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.prefix,
globals.concurrency,
globals.native_tls,
&args.settings.allow_insecure_host,
&globals.allow_insecure_host,
cache,
args.dry_run,
printer,
Expand Down Expand Up @@ -565,7 +565,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
globals.connectivity,
globals.native_tls,
args.settings.keyring_provider,
&args.settings.allow_insecure_host,
&globals.allow_insecure_host,
printer,
)
.await
Expand Down Expand Up @@ -772,7 +772,7 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
args.settings.index_strategy,
args.settings.dependency_metadata,
args.settings.keyring_provider,
&args.settings.allow_insecure_host,
&globals.allow_insecure_host,
uv_virtualenv::Prompt::from_args(prompt),
args.system_site_packages,
globals.connectivity,
Expand Down
48 changes: 22 additions & 26 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,6 @@ pub(crate) struct GlobalSettings {
impl GlobalSettings {
/// Resolve the [`GlobalSettings`] from the CLI and filesystem configuration.
pub(crate) fn resolve(args: &GlobalArgs, workspace: Option<&FilesystemOptions>) -> Self {
let preview = PreviewMode::from(
flag(args.preview, args.no_preview)
.combine(workspace.and_then(|workspace| workspace.globals.preview))
.unwrap_or(false),
);

let allow_insecure_host = if let Some(allow_insecure_host) = &args.allow_insecure_host {
allow_insecure_host
.iter()
.filter_map(|value| value.clone().into_option())
.collect()
} else {
workspace
.and_then(|workspace| workspace.globals.allow_insecure_host.clone())
.unwrap_or_default()
};
Self {
quiet: args.quiet,
verbose: args.verbose,
Expand Down Expand Up @@ -127,9 +111,29 @@ impl GlobalSettings {
} else {
Connectivity::Online
},
allow_insecure_host,
allow_insecure_host: args
.allow_insecure_host
.as_ref()
.map(|allow_insecure_host| {
allow_insecure_host
.iter()
.filter_map(|value| value.clone().into_option())
})
.into_iter()
.flatten()
.chain(
workspace
.and_then(|workspace| workspace.globals.allow_insecure_host.clone())
.into_iter()
.flatten(),
)
.collect(),
show_settings: args.show_settings,
preview,
preview: PreviewMode::from(
flag(args.preview, args.no_preview)
.combine(workspace.and_then(|workspace| workspace.globals.preview))
.unwrap_or(false),
),
python_preference: args
.python_preference
.combine(workspace.and_then(|workspace| workspace.globals.python_preference))
Expand Down Expand Up @@ -2173,7 +2177,6 @@ pub(crate) struct PipSettings {
pub(crate) prefix: Option<Prefix>,
pub(crate) index_strategy: IndexStrategy,
pub(crate) keyring_provider: KeyringProviderType,
pub(crate) allow_insecure_host: Vec<TrustedHost>,
pub(crate) no_build_isolation: bool,
pub(crate) no_build_isolation_package: Vec<PackageName>,
pub(crate) build_options: BuildOptions,
Expand Down Expand Up @@ -2230,7 +2233,6 @@ impl PipSettings {
find_links,
index_strategy,
keyring_provider,
allow_insecure_host,
no_build,
no_binary,
only_binary,
Expand Down Expand Up @@ -2282,7 +2284,6 @@ impl PipSettings {
find_links: top_level_find_links,
index_strategy: top_level_index_strategy,
keyring_provider: top_level_keyring_provider,
allow_insecure_host: top_level_allow_insecure_host,
resolution: top_level_resolution,
prerelease: top_level_prerelease,
dependency_metadata: top_level_dependency_metadata,
Expand Down Expand Up @@ -2314,7 +2315,6 @@ impl PipSettings {
let find_links = find_links.combine(top_level_find_links);
let index_strategy = index_strategy.combine(top_level_index_strategy);
let keyring_provider = keyring_provider.combine(top_level_keyring_provider);
let allow_insecure_host = allow_insecure_host.combine(top_level_allow_insecure_host);
let resolution = resolution.combine(top_level_resolution);
let prerelease = prerelease.combine(top_level_prerelease);
let dependency_metadata = dependency_metadata.combine(top_level_dependency_metadata);
Expand Down Expand Up @@ -2390,10 +2390,6 @@ impl PipSettings {
.keyring_provider
.combine(keyring_provider)
.unwrap_or_default(),
allow_insecure_host: args
.allow_insecure_host
.combine(allow_insecure_host)
.unwrap_or_default(),
generate_hashes: args
.generate_hashes
.combine(generate_hashes)
Expand Down
33 changes: 0 additions & 33 deletions docs/reference/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1481,39 +1481,6 @@ packages.

---

#### [`allow-insecure-host`](#pip_allow-insecure-host) {: #pip_allow-insecure-host }
<span id="allow-insecure-host"></span>

Allow insecure connections to host.

Expects to receive either a hostname (e.g., `localhost`), a host-port pair (e.g.,
`localhost:8080`), or a URL (e.g., `https://localhost`).

WARNING: Hosts included in this list will not be verified against the system's certificate
store. Only use `--allow-insecure-host` in a secure network with verified sources, as it
bypasses SSL verification and could expose you to MITM attacks.

**Default value**: `[]`

**Type**: `list[str]`

**Example usage**:

=== "pyproject.toml"

```toml
[tool.uv.pip]
allow-insecure-host = ["localhost:8080"]
```
=== "uv.toml"

```toml
[pip]
allow-insecure-host = ["localhost:8080"]
```

---

#### [`annotation-style`](#pip_annotation-style) {: #pip_annotation-style }
<span id="annotation-style"></span>

Expand Down
10 changes: 0 additions & 10 deletions uv.schema.json

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

0 comments on commit 8f400da

Please sign in to comment.