From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 1E5501FF2C6 for ; Tue, 9 Jul 2024 08:20:19 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 2C7A218A02; Tue, 9 Jul 2024 08:20:32 +0200 (CEST) From: Wolfgang Bumiller To: pve-devel@lists.proxmox.com Date: Tue, 9 Jul 2024 08:20:22 +0200 Message-Id: <20240709062026.53271-1-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.086 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 Subject: [pve-devel] applied-series: [PATCH perl-rs 1/5] perl-rs: use proxmox-apt-api-types X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" From: Dietmar Maurer Signed-off-by: Dietmar Maurer --- common/src/apt/repositories.rs | 57 +++++++++------------------------- pmg-rs/Cargo.toml | 14 ++++----- pmg-rs/src/apt/repositories.rs | 8 +++-- pve-rs/Cargo.toml | 12 +++---- pve-rs/src/apt/repositories.rs | 9 ++++-- 5 files changed, 37 insertions(+), 63 deletions(-) diff --git a/common/src/apt/repositories.rs b/common/src/apt/repositories.rs index e710819..3b05449 100644 --- a/common/src/apt/repositories.rs +++ b/common/src/apt/repositories.rs @@ -1,34 +1,12 @@ #[perlmod::package(name = "Proxmox::RS::APT::Repositories")] pub mod export { - use std::convert::TryInto; use anyhow::{bail, Error}; use serde::{Deserialize, Serialize}; - use proxmox_apt::repositories::{ - APTRepositoryFile, APTRepositoryFileError, APTRepositoryHandle, APTRepositoryInfo, - APTStandardRepository, - }; - - #[derive(Deserialize, Serialize)] - #[serde(rename_all = "kebab-case")] - /// Result for the repositories() function - pub struct RepositoriesResult { - /// Successfully parsed files. - pub files: Vec, - - /// Errors for files that could not be parsed or read. - pub errors: Vec, - - /// Common digest for successfully parsed files. - pub digest: String, - - /// Additional information/warnings about repositories. - pub infos: Vec, - - /// Standard repositories and their configuration status. - pub standard_repos: Vec, - } + use proxmox_apt::repositories::{APTRepositoryFileImpl, APTRepositoryImpl}; + use proxmox_apt_api_types::{APTRepositoriesResult, APTRepositoryFile, APTRepositoryHandle}; + use proxmox_config_digest::ConfigDigest; #[derive(Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] @@ -40,9 +18,8 @@ pub mod export { /// Get information about configured repositories and standard repositories for `product`. #[export] - pub fn repositories(product: &str) -> Result { + pub fn repositories(product: &str) -> Result { let (files, errors, digest) = proxmox_apt::repositories::repositories()?; - let digest = hex::encode(&digest); let suite = proxmox_apt::repositories::get_current_release_codename()?; @@ -50,7 +27,7 @@ pub mod export { let standard_repos = proxmox_apt::repositories::standard_repositories(&files, product, suite); - Ok(RepositoriesResult { + Ok(APTRepositoriesResult { files, errors, digest, @@ -64,18 +41,17 @@ pub mod export { /// /// The `digest` parameter asserts that the configuration has not been modified. #[export] - pub fn add_repository(handle: &str, product: &str, digest: Option<&str>) -> Result<(), Error> { + pub fn add_repository( + handle: &str, + product: &str, + digest: Option, + ) -> Result<(), Error> { let (mut files, errors, current_digest) = proxmox_apt::repositories::repositories()?; - let handle: APTRepositoryHandle = handle.try_into()?; + let handle: APTRepositoryHandle = handle.parse()?; let suite = proxmox_apt::repositories::get_current_release_codename()?; - if let Some(digest) = digest { - let expected_digest = hex::decode(digest)?; - if expected_digest != current_digest { - bail!("detected modified configuration - file changed by other user? Try again."); - } - } + current_digest.detect_modification(digest.as_ref())?; // check if it's already configured first for file in files.iter_mut() { @@ -133,16 +109,11 @@ pub mod export { path: &str, index: usize, options: ChangeProperties, - digest: Option<&str>, + digest: Option, ) -> Result<(), Error> { let (mut files, errors, current_digest) = proxmox_apt::repositories::repositories()?; - if let Some(digest) = digest { - let expected_digest = hex::decode(digest)?; - if expected_digest != current_digest { - bail!("detected modified configuration - file changed by other user? Try again."); - } - } + current_digest.detect_modification(digest.as_ref())?; if let Some(error) = errors.iter().find(|error| error.path == path) { bail!("unable to parse file {} - {}", error.path, error.error); diff --git a/pmg-rs/Cargo.toml b/pmg-rs/Cargo.toml index 559033b..ad3a107 100644 --- a/pmg-rs/Cargo.toml +++ b/pmg-rs/Cargo.toml @@ -8,14 +8,10 @@ edition = "2021" license = "AGPL-3" repository = "https://git.proxmox.com/?p=proxmox.git" -exclude = [ - "build", - "debian", - "PMG", -] +exclude = ["build", "debian", "PMG"] [lib] -crate-type = [ "cdylib" ] +crate-type = ["cdylib"] [dependencies] anyhow = "1.0" @@ -30,10 +26,12 @@ serde_bytes = "0.11" serde_json = "1.0" url = "2" -perlmod = { version = "0.13.4", features = [ "exporter" ] } +perlmod = { version = "0.13.4", features = ["exporter"] } proxmox-acme = { version = "0.5", features = ["client", "api-types"] } -proxmox-apt = "0.10" +proxmox-apt = "0.11" +proxmox-apt-api-types = "1.0" +proxmox-config-digest = "0.1" proxmox-http = { version = "0.9", features = ["client-sync", "client-trait"] } proxmox-http-error = "0.1.0" proxmox-notify = "0.4" diff --git a/pmg-rs/src/apt/repositories.rs b/pmg-rs/src/apt/repositories.rs index f6ddb37..3680d5c 100644 --- a/pmg-rs/src/apt/repositories.rs +++ b/pmg-rs/src/apt/repositories.rs @@ -1,12 +1,14 @@ #[perlmod::package(name = "PMG::RS::APT::Repositories")] mod export { use anyhow::Error; + use proxmox_apt_api_types::APTRepositoriesResult; + use proxmox_config_digest::ConfigDigest; use crate::common::apt::repositories::export as common; /// Get information about configured and standard repositories. #[export] - pub fn repositories() -> Result { + pub fn repositories() -> Result { common::repositories("pmg") } @@ -15,7 +17,7 @@ mod export { /// /// The `digest` parameter asserts that the configuration has not been modified. #[export] - pub fn add_repository(handle: &str, digest: Option<&str>) -> Result<(), Error> { + pub fn add_repository(handle: &str, digest: Option) -> Result<(), Error> { common::add_repository(handle, "pmg", digest) } @@ -27,7 +29,7 @@ mod export { path: &str, index: usize, options: common::ChangeProperties, - digest: Option<&str>, + digest: Option, ) -> Result<(), Error> { common::change_repository(path, index, options, digest) } diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml index 33e698a..ce7059d 100644 --- a/pve-rs/Cargo.toml +++ b/pve-rs/Cargo.toml @@ -8,12 +8,10 @@ edition = "2021" license = "AGPL-3" repository = "https://git.proxmox.com/?p=proxmox.git" -exclude = [ - "debian", -] +exclude = ["debian"] [lib] -crate-type = [ "cdylib" ] +crate-type = ["cdylib"] [dependencies] anyhow = "1.0" @@ -31,9 +29,11 @@ serde_bytes = "0.11" serde_json = "1.0" url = "2" -perlmod = { version = "0.13", features = [ "exporter" ] } +perlmod = { version = "0.13", features = ["exporter"] } -proxmox-apt = "0.10.6" +proxmox-apt = "0.11" +proxmox-apt-api-types = "1.0" +proxmox-config-digest = "0.1" proxmox-http = { version = "0.9", features = ["client-sync", "client-trait"] } proxmox-http-error = "0.1.0" proxmox-notify = { version = "0.4", features = ["pve-context"] } diff --git a/pve-rs/src/apt/repositories.rs b/pve-rs/src/apt/repositories.rs index d5c2f56..c1867a1 100644 --- a/pve-rs/src/apt/repositories.rs +++ b/pve-rs/src/apt/repositories.rs @@ -2,11 +2,14 @@ mod export { use anyhow::Error; + use proxmox_apt_api_types::APTRepositoriesResult; + use proxmox_config_digest::ConfigDigest; + use crate::common::apt::repositories::export as common; /// Get information about configured and standard repositories. #[export] - pub fn repositories() -> Result { + pub fn repositories() -> Result { common::repositories("pve") } @@ -15,7 +18,7 @@ mod export { /// /// The `digest` parameter asserts that the configuration has not been modified. #[export] - pub fn add_repository(handle: &str, digest: Option<&str>) -> Result<(), Error> { + pub fn add_repository(handle: &str, digest: Option) -> Result<(), Error> { common::add_repository(handle, "pve", digest) } @@ -27,7 +30,7 @@ mod export { path: &str, index: usize, options: common::ChangeProperties, - digest: Option<&str>, + digest: Option, ) -> Result<(), Error> { common::change_repository(path, index, options, digest) } -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel