mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-17 18:57:30 +00:00
Accept either strings or structs for hosts (#6763)
## Summary Technically a struct did work in the last release, so let's not break it.
This commit is contained in:
parent
71f5998752
commit
af323888ee
2 changed files with 25 additions and 3 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
/// A trusted host, which could be a host or a host-port pair.
|
/// A trusted host, which could be a host or a host-port pair.
|
||||||
|
|
@ -31,13 +33,28 @@ impl TrustedHost {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
enum TrustHostWire {
|
||||||
|
String(String),
|
||||||
|
Struct {
|
||||||
|
scheme: Option<String>,
|
||||||
|
host: String,
|
||||||
|
port: Option<u16>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
impl<'de> serde::de::Deserialize<'de> for TrustedHost {
|
impl<'de> serde::de::Deserialize<'de> for TrustedHost {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<TrustedHost, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<TrustedHost, D::Error>
|
||||||
where
|
where
|
||||||
D: serde::de::Deserializer<'de>,
|
D: serde::de::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
let s = String::deserialize(deserializer)?;
|
let helper = TrustHostWire::deserialize(deserializer)?;
|
||||||
s.parse().map_err(serde::de::Error::custom)
|
|
||||||
|
match helper {
|
||||||
|
TrustHostWire::String(s) => TrustedHost::from_str(&s).map_err(serde::de::Error::custom),
|
||||||
|
TrustHostWire::Struct { scheme, host, port } => Ok(TrustedHost { scheme, host, port }),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3419,7 +3419,7 @@ fn allow_insecure_host() -> anyhow::Result<()> {
|
||||||
|
|
||||||
let config = context.temp_dir.child("uv.toml");
|
let config = context.temp_dir.child("uv.toml");
|
||||||
config.write_str(indoc::indoc! {r#"
|
config.write_str(indoc::indoc! {r#"
|
||||||
allow-insecure-host = ["google.com"]
|
allow-insecure-host = ["google.com", { host = "example.com" }]
|
||||||
"#})?;
|
"#})?;
|
||||||
|
|
||||||
let requirements_in = context.temp_dir.child("requirements.in");
|
let requirements_in = context.temp_dir.child("requirements.in");
|
||||||
|
|
@ -3495,6 +3495,11 @@ fn allow_insecure_host() -> anyhow::Result<()> {
|
||||||
host: "google.com",
|
host: "google.com",
|
||||||
port: None,
|
port: None,
|
||||||
},
|
},
|
||||||
|
TrustedHost {
|
||||||
|
scheme: None,
|
||||||
|
host: "example.com",
|
||||||
|
port: None,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
no_build_isolation: false,
|
no_build_isolation: false,
|
||||||
no_build_isolation_package: [],
|
no_build_isolation_package: [],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue