forked from Proxmox/proxmox
check: return 'origin' property instead of 'badge' for official host
which is obtained from the cached InRelease file and also works for mirrors, host aliases, direct IPs. The has_official_uri function was replaced by origin_from_uris. Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
parent
bb0ff2ac73
commit
87ea23ec83
@ -373,13 +373,22 @@ impl APTRepositoryFile {
|
||||
let mut infos = vec![];
|
||||
|
||||
for (n, repo) in self.repositories.iter().enumerate() {
|
||||
if repo.has_official_uri() {
|
||||
let mut origin = match repo.get_cached_origin() {
|
||||
Ok(option) => option,
|
||||
Err(_) => None,
|
||||
};
|
||||
|
||||
if origin.is_none() {
|
||||
origin = repo.origin_from_uris();
|
||||
}
|
||||
|
||||
if let Some(origin) = origin {
|
||||
infos.push(APTRepositoryInfo {
|
||||
path: self.path.clone(),
|
||||
index: n,
|
||||
kind: "badge".to_string(),
|
||||
property: Some("URIs".to_string()),
|
||||
message: "official host name".to_string(),
|
||||
kind: "origin".to_string(),
|
||||
property: None,
|
||||
message: origin,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -288,21 +288,23 @@ impl APTRepository {
|
||||
.any(|suite| suite_variant(suite).0 == base_suite)
|
||||
}
|
||||
|
||||
/// Checks if an official host is configured in the repository.
|
||||
pub fn has_official_uri(&self) -> bool {
|
||||
/// Guess the origin from the repository's URIs.
|
||||
///
|
||||
/// Intended to be used as a fallback for get_cached_origin.
|
||||
pub fn origin_from_uris(&self) -> Option<String> {
|
||||
for uri in self.uris.iter() {
|
||||
if let Some(host) = host_from_uri(uri) {
|
||||
if host == "proxmox.com"
|
||||
|| host.ends_with(".proxmox.com")
|
||||
|| host == "debian.org"
|
||||
|| host.ends_with(".debian.org")
|
||||
{
|
||||
return true;
|
||||
if host == "proxmox.com" || host.ends_with(".proxmox.com") {
|
||||
return Some("Proxmox".to_string());
|
||||
}
|
||||
|
||||
if host == "debian.org" || host.ends_with(".debian.org") {
|
||||
return Some("Debian".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
None
|
||||
}
|
||||
|
||||
/// Get the `Origin:` value from a cached InRelease file.
|
||||
|
@ -171,6 +171,11 @@ fn test_check_repositories() -> Result<(), Error> {
|
||||
let test_dir = std::env::current_dir()?.join("tests");
|
||||
let read_dir = test_dir.join("sources.list.d");
|
||||
|
||||
proxmox_apt::config::init(APTConfig::new(
|
||||
Some(&test_dir.into_os_string().into_string().unwrap()),
|
||||
None,
|
||||
));
|
||||
|
||||
let absolute_suite_list = read_dir.join("absolute_suite.list");
|
||||
let mut file = APTRepositoryFile::new(&absolute_suite_list)?.unwrap();
|
||||
file.parse()?;
|
||||
@ -184,14 +189,18 @@ fn test_check_repositories() -> Result<(), Error> {
|
||||
|
||||
let path_string = pve_list.into_os_string().into_string().unwrap();
|
||||
|
||||
let origins = [
|
||||
"Debian", "Debian", "Proxmox", "Proxmox", "Proxmox", "Debian",
|
||||
];
|
||||
|
||||
let mut expected_infos = vec![];
|
||||
for n in 0..=5 {
|
||||
expected_infos.push(APTRepositoryInfo {
|
||||
path: path_string.clone(),
|
||||
index: n,
|
||||
property: Some("URIs".to_string()),
|
||||
kind: "badge".to_string(),
|
||||
message: "official host name".to_string(),
|
||||
property: None,
|
||||
kind: "origin".to_string(),
|
||||
message: origins[n].to_string(),
|
||||
});
|
||||
}
|
||||
expected_infos.sort();
|
||||
@ -255,9 +264,9 @@ fn test_check_repositories() -> Result<(), Error> {
|
||||
expected_infos.push(APTRepositoryInfo {
|
||||
path: path_string.clone(),
|
||||
index: n,
|
||||
property: Some("URIs".to_string()),
|
||||
kind: "badge".to_string(),
|
||||
message: "official host name".to_string(),
|
||||
property: None,
|
||||
kind: "origin".to_string(),
|
||||
message: "Debian".to_string(),
|
||||
});
|
||||
}
|
||||
expected_infos.sort();
|
||||
|
Loading…
Reference in New Issue
Block a user