From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 9A30F71E38
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:08:31 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 8D64A1B3D8
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:08:01 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS id 269E21B3C6
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:08:00 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id F29CE4681C
 for <pve-devel@lists.proxmox.com>; Wed, 30 Jun 2021 17:07:59 +0200 (CEST)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 30 Jun 2021 17:07:53 +0200
Message-Id: <20210630150754.9921-2-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20210630150754.9921-1-f.ebner@proxmox.com>
References: <20210630150754.9921-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.621 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [mod.rs, repositories.rs, standard.rs]
Subject: [pve-devel] [PATCH proxmox-apt 1/1] standard repos: allow
 conversion from handle and improve information
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 30 Jun 2021 15:08:31 -0000

Add a description for the handle, which can be useful to display
alongside the name. The descriptions are essentially the first
sentence from PVE's "Package Repositories" docs, but without the
product name.

Also drop the " Repository" suffix from the names, as it's not useful,
but can be ugly: e.g. for the UI when the label already is
'Repository:'.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
 src/repositories/mod.rs      | 42 ++++-------------------
 src/repositories/standard.rs | 64 +++++++++++++++++++++++++++++++-----
 tests/repositories.rs        | 42 ++++-------------------
 3 files changed, 69 insertions(+), 79 deletions(-)

diff --git a/src/repositories/mod.rs b/src/repositories/mod.rs
index e2b0b6b..7bac333 100644
--- a/src/repositories/mod.rs
+++ b/src/repositories/mod.rs
@@ -80,45 +80,17 @@ pub fn standard_repositories(
     files: &[APTRepositoryFile],
 ) -> Vec<APTStandardRepository> {
     let mut result = vec![
-        APTStandardRepository {
-            handle: APTRepositoryHandle::Enterprise,
-            status: None,
-            name: APTRepositoryHandle::Enterprise.name(),
-        },
-        APTStandardRepository {
-            handle: APTRepositoryHandle::NoSubscription,
-            status: None,
-            name: APTRepositoryHandle::NoSubscription.name(),
-        },
-        APTStandardRepository {
-            handle: APTRepositoryHandle::Test,
-            status: None,
-            name: APTRepositoryHandle::Test.name(),
-        },
+        APTStandardRepository::from(APTRepositoryHandle::Enterprise),
+        APTStandardRepository::from(APTRepositoryHandle::NoSubscription),
+        APTStandardRepository::from(APTRepositoryHandle::Test),
     ];
 
     if product == "pve" {
         result.append(&mut vec![
-            APTStandardRepository {
-                handle: APTRepositoryHandle::CephPacific,
-                status: None,
-                name: APTRepositoryHandle::CephPacific.name(),
-            },
-            APTStandardRepository {
-                handle: APTRepositoryHandle::CephPacificTest,
-                status: None,
-                name: APTRepositoryHandle::CephPacificTest.name(),
-            },
-            APTStandardRepository {
-                handle: APTRepositoryHandle::CephOctopus,
-                status: None,
-                name: APTRepositoryHandle::CephOctopus.name(),
-            },
-            APTStandardRepository {
-                handle: APTRepositoryHandle::CephOctopusTest,
-                status: None,
-                name: APTRepositoryHandle::CephOctopusTest.name(),
-            },
+            APTStandardRepository::from(APTRepositoryHandle::CephPacific),
+            APTStandardRepository::from(APTRepositoryHandle::CephPacificTest),
+            APTStandardRepository::from(APTRepositoryHandle::CephOctopus),
+            APTStandardRepository::from(APTRepositoryHandle::CephOctopusTest),
         ]);
     }
 
diff --git a/src/repositories/standard.rs b/src/repositories/standard.rs
index dcfe85b..0d2cc14 100644
--- a/src/repositories/standard.rs
+++ b/src/repositories/standard.rs
@@ -29,8 +29,11 @@ pub struct APTStandardRepository {
     #[serde(skip_serializing_if = "Option::is_none")]
     pub status: Option<bool>,
 
-    /// Full name of the repository.
+    /// Display name of the repository.
     pub name: String,
+
+    /// Description of the repository.
+    pub description: String,
 }
 
 #[api]
@@ -54,6 +57,17 @@ pub enum APTRepositoryHandle {
     CephOctopusTest,
 }
 
+impl From<APTRepositoryHandle> for APTStandardRepository {
+    fn from(handle: APTRepositoryHandle) -> Self {
+        APTStandardRepository {
+            handle,
+            status: None,
+            name: handle.name(),
+            description: handle.description(),
+        }
+    }
+}
+
 impl TryFrom<&str> for APTRepositoryHandle {
     type Error = Error;
 
@@ -86,16 +100,48 @@ impl Display for APTRepositoryHandle {
 }
 
 impl APTRepositoryHandle {
-    /// Get the full name of the repository.
+    /// Get the description for the repository.
+    pub fn description(self) -> String {
+        match self {
+            APTRepositoryHandle::Enterprise => {
+                "This is the default, stable, and recommended repository, available for all \
+                Proxmox subscription users."
+            }
+            APTRepositoryHandle::NoSubscription => {
+                "This is the recommended repository for testing and non-production use."
+            }
+            APTRepositoryHandle::Test => {
+                "This repository contains the latest packages and is primarily used by developers \
+                to test new features."
+            }
+            APTRepositoryHandle::CephPacific => {
+                "This repository holds the main Proxmox Ceph Pacific packages."
+            }
+            APTRepositoryHandle::CephPacificTest => {
+                "This repository contains the Ceph Pacific packages before they are moved to the \
+                main repository."
+            }
+            APTRepositoryHandle::CephOctopus => {
+                "This repository holds the main Proxmox Ceph Octopus packages."
+            }
+            APTRepositoryHandle::CephOctopusTest => {
+                "This repository contains the Ceph Octopus packages before they are moved to the \
+                main repository."
+            }
+        }
+        .to_string()
+    }
+
+    /// Get the display name of the repository.
     pub fn name(self) -> String {
         match self {
-            APTRepositoryHandle::Enterprise => "Enterprise Repository",
-            APTRepositoryHandle::NoSubscription => "No-Subscription Repository",
-            APTRepositoryHandle::Test => "Test Repository",
-            APTRepositoryHandle::CephPacific => "Ceph Pacific Repository",
-            APTRepositoryHandle::CephPacificTest => "Ceph Pacific Test Repository",
-            APTRepositoryHandle::CephOctopus => "Ceph Octopus Repository",
-            APTRepositoryHandle::CephOctopusTest => "Ceph Octopus Test Repository",
+            APTRepositoryHandle::Enterprise => "Enterprise",
+            APTRepositoryHandle::NoSubscription => "No-Subscription",
+            APTRepositoryHandle::Test => "Test",
+            APTRepositoryHandle::CephPacific => "Ceph Pacific",
+            APTRepositoryHandle::CephPacificTest => "Ceph Pacific Test",
+            APTRepositoryHandle::CephOctopus => "Ceph Octopus",
+            APTRepositoryHandle::CephOctopusTest => "Ceph Octopus Test",
         }
         .to_string()
     }
diff --git a/tests/repositories.rs b/tests/repositories.rs
index fefc608..289bbe4 100644
--- a/tests/repositories.rs
+++ b/tests/repositories.rs
@@ -317,41 +317,13 @@ fn test_standard_repositories() -> Result<(), Error> {
     let read_dir = test_dir.join("sources.list.d");
 
     let mut expected = vec![
-        APTStandardRepository {
-            handle: APTRepositoryHandle::Enterprise,
-            status: None,
-            name: APTRepositoryHandle::Enterprise.name(),
-        },
-        APTStandardRepository {
-            handle: APTRepositoryHandle::NoSubscription,
-            status: None,
-            name: APTRepositoryHandle::NoSubscription.name(),
-        },
-        APTStandardRepository {
-            handle: APTRepositoryHandle::Test,
-            status: None,
-            name: APTRepositoryHandle::Test.name(),
-        },
-        APTStandardRepository {
-            handle: APTRepositoryHandle::CephPacific,
-            status: None,
-            name: APTRepositoryHandle::CephPacific.name(),
-        },
-        APTStandardRepository {
-            handle: APTRepositoryHandle::CephPacificTest,
-            status: None,
-            name: APTRepositoryHandle::CephPacificTest.name(),
-        },
-        APTStandardRepository {
-            handle: APTRepositoryHandle::CephOctopus,
-            status: None,
-            name: APTRepositoryHandle::CephOctopus.name(),
-        },
-        APTStandardRepository {
-            handle: APTRepositoryHandle::CephOctopusTest,
-            status: None,
-            name: APTRepositoryHandle::CephOctopusTest.name(),
-        },
+        APTStandardRepository::from(APTRepositoryHandle::Enterprise),
+        APTStandardRepository::from(APTRepositoryHandle::NoSubscription),
+        APTStandardRepository::from(APTRepositoryHandle::Test),
+        APTStandardRepository::from(APTRepositoryHandle::CephPacific),
+        APTStandardRepository::from(APTRepositoryHandle::CephPacificTest),
+        APTStandardRepository::from(APTRepositoryHandle::CephOctopus),
+        APTStandardRepository::from(APTRepositoryHandle::CephOctopusTest),
     ];
 
     let absolute_suite_list = read_dir.join("absolute_suite.list");
-- 
2.30.2