all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-apt 2/3] check: return 'origin' property instead of 'badge' for official host
Date: Wed, 30 Jun 2021 12:20:17 +0200	[thread overview]
Message-ID: <20210630102019.39057-3-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210630102019.39057-1-f.ebner@proxmox.com>

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>
---
 src/repositories/file.rs       | 17 +++++++++++++----
 src/repositories/repository.rs | 20 +++++++++++---------
 tests/repositories.rs          | 21 +++++++++++++++------
 3 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/src/repositories/file.rs b/src/repositories/file.rs
index 6225f1c..447fd0a 100644
--- a/src/repositories/file.rs
+++ b/src/repositories/file.rs
@@ -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,
                 });
             }
         }
diff --git a/src/repositories/repository.rs b/src/repositories/repository.rs
index 5eba068..cf17380 100644
--- a/src/repositories/repository.rs
+++ b/src/repositories/repository.rs
@@ -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.
diff --git a/tests/repositories.rs b/tests/repositories.rs
index 4067e60..3265bce 100644
--- a/tests/repositories.rs
+++ b/tests/repositories.rs
@@ -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();
-- 
2.30.2





  parent reply	other threads:[~2021-06-30 10:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30 10:20 [pve-devel] [PATCH-SERIES proxmox-apt/proxmox-widget-toolkit] APT repos: Use Origin property instead of "official host" Fabian Ebner
2021-06-30 10:20 ` [pve-devel] [PATCH proxmox-apt 1/3] add get_cached_origin method and an initial config module Fabian Ebner
2021-06-30 10:20 ` Fabian Ebner [this message]
2021-06-30 10:20 ` [pve-devel] [PATCH proxmox-apt 3/3] standard repos: drop product acronym from repo name Fabian Ebner
2021-06-30 10:20 ` [pve-devel] [PATCH proxmox-widget-toolkit 1/1] apt repositories: replace OfficialHost with Origin Fabian Ebner
2021-06-30 11:42 ` [pve-devel] applied-series: [PATCH-SERIES proxmox-apt/proxmox-widget-toolkit] APT repos: Use Origin property instead of "official host" Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210630102019.39057-3-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal