Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
pub(crate) struct Client {
client: reqwest::blocking::Client,
key: Option<PrivateKey>,
server: Url,
server: ServerUrl,
}

impl Client {
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Client {
)
}

pub(crate) fn new(options: &Options, server: Url, auth: Option<&KeyName>) -> Result<Self> {
pub(crate) fn new(options: &Options, server: ServerUrl, auth: Option<&KeyName>) -> Result<Self> {
install_default_crypto_provider()?;

let client = reqwest::blocking::Client::builder()
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ use {
rotation::Rotation,
server::Server,
server_error::ServerError,
server_url::ServerUrl,
sign_options::SignOptions,
signature_error::SignatureError,
sort::Sort,
Expand Down Expand Up @@ -413,6 +414,7 @@ mod resource_type;
mod rotation;
mod server;
mod server_error;
mod server_url;
mod sign_options;
mod signature;
mod signature_error;
Expand Down
64 changes: 64 additions & 0 deletions src/server_url.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use super::*;

#[derive(Clone, Debug, PartialEq)]
pub(crate) struct ServerUrl(Url);

impl Deref for ServerUrl {
type Target = Url;

fn deref(&self) -> &Url {
&self.0
}
}

impl FromStr for ServerUrl {
type Err = UrlError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut url = CheckedUrl::check(s)?;

url.path_segments_mut().unwrap().pop_if_empty().push("");

Ok(Self(url))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn scheme() {
assert_eq!(
"ftp://foo".parse::<ServerUrl>().unwrap_err(),
UrlError::Scheme {
scheme: "ftp".into()
},
);
}

#[test]
fn trailing_slash() {
assert_eq!(
"https://foo/bar".parse::<ServerUrl>().unwrap().as_str(),
"https://foo/bar/",
);
assert_eq!(
"https://foo/bar/".parse::<ServerUrl>().unwrap().as_str(),
"https://foo/bar/",
);
assert_eq!(
"https://foo".parse::<ServerUrl>().unwrap().as_str(),
"https://foo/",
);
assert_eq!(
"https://foo/bar"
.parse::<ServerUrl>()
.unwrap()
.join("api/missing")
.unwrap()
.as_str(),
"https://foo/bar/api/missing",
);
}
}
4 changes: 2 additions & 2 deletions src/subcommand/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub(crate) struct Delete {
value_name = "FINGERPRINT"
)]
fingerprint: Option<Fingerprint>,
#[arg(help = "Delete from server at <URL>", long, value_name = "URL", value_parser = CheckedUrl::check)]
server: Url,
#[arg(help = "Delete from server at <URL>", long, value_name = "URL")]
server: ServerUrl,
}

impl Delete {
Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub(crate) struct Download {
value_name = "FINGERPRINT"
)]
package: Option<Fingerprint>,
#[arg(help = "Download from server at <URL>", long, value_name = "URL", value_parser = CheckedUrl::check)]
server: Url,
#[arg(help = "Download from server at <URL>", long, value_name = "URL")]
server: ServerUrl,
}

impl Download {
Expand Down
8 changes: 6 additions & 2 deletions src/subcommand/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ use super::*;
pub(crate) struct Gc {
#[arg(help = "Authenticate with key <KEY>", long, value_name = "KEY")]
auth: Option<KeyName>,
#[arg(help = "Delete unreferenced data on server at <URL>", long, value_name = "URL", value_parser = CheckedUrl::check)]
server: Url,
#[arg(
help = "Delete unreferenced data on server at <URL>",
long,
value_name = "URL"
)]
server: ServerUrl,
}

impl Gc {
Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub(crate) struct Upload {
value_name = "PATH"
)]
input: Option<Utf8PathBuf>,
#[arg(help = "Upload to server at <URL>", long, value_name = "URL", value_parser = CheckedUrl::check)]
server: Url,
#[arg(help = "Upload to server at <URL>", long, value_name = "URL")]
server: ServerUrl,
}

impl Upload {
Expand Down