Skip to content
Merged
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
29 changes: 29 additions & 0 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,19 @@ pub trait Registry {
) -> Result<AuditLogResponse>;
}

const LEGACY_PUBLIC_REGISTRY_URL: &str = "https://registry.zpkg.net";
const CANONICAL_PUBLIC_REGISTRY_URL: &str = "https://zpkg.net";

fn canonical_registry_url(url: &str) -> &str {
if url.trim_end_matches('/') == LEGACY_PUBLIC_REGISTRY_URL {
CANONICAL_PUBLIC_REGISTRY_URL
} else {
url
}
}

pub fn registry_for(url: &str) -> Result<Box<dyn Registry>> {
let url = canonical_registry_url(url);
if url.starts_with("file://") {
Ok(Box::new(FileRegistry::new(file_registry_path(url)?)))
} else if url.starts_with("http://") || url.starts_with("https://") {
Expand All @@ -169,6 +181,23 @@ pub fn registry_for(url: &str) -> Result<Box<dyn Registry>> {
}
}

#[cfg(test)]
#[test]
fn legacy_public_registry_alias_uses_the_canonical_zpkg_edge() {
assert_eq!(
canonical_registry_url("https://registry.zpkg.net"),
"https://zpkg.net"
);
assert_eq!(
canonical_registry_url("https://registry.zpkg.net/"),
"https://zpkg.net"
);
assert_eq!(
canonical_registry_url("https://registry.example.test"),
"https://registry.example.test"
);
}

/// Pick the highest stable version satisfying `req`.
pub fn resolve_version(req: &VersionReq, versions: &[String]) -> Option<Version> {
versions
Expand Down
Loading