-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use UrlWithTrailingSlash for upload, use bearer auth for Artifac…
…tory upload
- Loading branch information
Showing
6 changed files
with
155 additions
and
39 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// copied from rattler-conda-types::utils::url_with_trailing_slash | ||
// TODO: move to separate crate | ||
|
||
use std::{ | ||
fmt::{Display, Formatter}, | ||
ops::Deref, | ||
str::FromStr, | ||
}; | ||
|
||
use rattler_redaction::Redact; | ||
use serde::{Deserialize, Deserializer, Serialize}; | ||
use url::Url; | ||
|
||
/// A URL that always has a trailing slash. A trailing slash in a URL has | ||
/// significance but users often forget to add it. This type is used to | ||
/// normalize the use of the URL. | ||
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize)] | ||
#[serde(transparent)] | ||
pub struct UrlWithTrailingSlash(Url); | ||
|
||
impl Deref for UrlWithTrailingSlash { | ||
type Target = Url; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl AsRef<Url> for UrlWithTrailingSlash { | ||
fn as_ref(&self) -> &Url { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl From<Url> for UrlWithTrailingSlash { | ||
fn from(url: Url) -> Self { | ||
let path = url.path(); | ||
if path.ends_with('/') { | ||
Self(url) | ||
} else { | ||
let mut url = url.clone(); | ||
url.set_path(&format!("{path}/")); | ||
Self(url) | ||
} | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for UrlWithTrailingSlash { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let url = Url::deserialize(deserializer)?; | ||
Ok(url.into()) | ||
} | ||
} | ||
|
||
impl FromStr for UrlWithTrailingSlash { | ||
type Err = url::ParseError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
Ok(Url::parse(s)?.into()) | ||
} | ||
} | ||
|
||
impl From<UrlWithTrailingSlash> for Url { | ||
fn from(value: UrlWithTrailingSlash) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl Display for UrlWithTrailingSlash { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", &self.0) | ||
} | ||
} | ||
|
||
impl Redact for UrlWithTrailingSlash { | ||
fn redact(self) -> Self { | ||
UrlWithTrailingSlash(self.0.redact()) | ||
} | ||
} |