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 BA9611FF2C6 for ; Tue, 9 Jul 2024 08:20:14 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B424318954; Tue, 9 Jul 2024 08:20:31 +0200 (CEST) From: Wolfgang Bumiller To: pve-devel@lists.proxmox.com Date: Tue, 9 Jul 2024 08:20:23 +0200 Message-Id: <20240709062026.53271-2-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240709062026.53271-1-w.bumiller@proxmox.com> References: <20240709062026.53271-1-w.bumiller@proxmox.com> 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] [PATCH perl-rs 2/5] perl-rs: use api functions from proxmox-apt 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 | 117 +++------------------------------ pmg-rs/src/apt/repositories.rs | 11 +++- pve-rs/src/apt/repositories.rs | 13 ++-- 3 files changed, 26 insertions(+), 115 deletions(-) diff --git a/common/src/apt/repositories.rs b/common/src/apt/repositories.rs index 3b05449..61824d7 100644 --- a/common/src/apt/repositories.rs +++ b/common/src/apt/repositories.rs @@ -1,39 +1,17 @@ #[perlmod::package(name = "Proxmox::RS::APT::Repositories")] pub mod export { - use anyhow::{bail, Error}; - use serde::{Deserialize, Serialize}; + use anyhow::Error; - use proxmox_apt::repositories::{APTRepositoryFileImpl, APTRepositoryImpl}; - use proxmox_apt_api_types::{APTRepositoriesResult, APTRepositoryFile, APTRepositoryHandle}; + use proxmox_apt_api_types::{ + APTChangeRepositoryOptions, APTRepositoriesResult, APTRepositoryHandle, + }; use proxmox_config_digest::ConfigDigest; - #[derive(Deserialize, Serialize)] - #[serde(rename_all = "kebab-case")] - /// For changing an existing repository. - pub struct ChangeProperties { - /// Whether the repository should be enabled or not. - pub enabled: Option, - } - /// Get information about configured repositories and standard repositories for `product`. #[export] pub fn repositories(product: &str) -> Result { - let (files, errors, digest) = proxmox_apt::repositories::repositories()?; - - let suite = proxmox_apt::repositories::get_current_release_codename()?; - - let infos = proxmox_apt::repositories::check_repositories(&files, suite); - let standard_repos = - proxmox_apt::repositories::standard_repositories(&files, product, suite); - - Ok(APTRepositoriesResult { - files, - errors, - digest, - infos, - standard_repos, - }) + proxmox_apt::list_repositories(product) } /// Add the repository identified by the `handle` and `product`. @@ -42,63 +20,11 @@ pub mod export { /// The `digest` parameter asserts that the configuration has not been modified. #[export] pub fn add_repository( - handle: &str, + handle: APTRepositoryHandle, product: &str, digest: Option, ) -> Result<(), Error> { - let (mut files, errors, current_digest) = proxmox_apt::repositories::repositories()?; - - let handle: APTRepositoryHandle = handle.parse()?; - let suite = proxmox_apt::repositories::get_current_release_codename()?; - - current_digest.detect_modification(digest.as_ref())?; - - // check if it's already configured first - for file in files.iter_mut() { - for repo in file.repositories.iter_mut() { - if repo.is_referenced_repository(handle, product, &suite.to_string()) { - if repo.enabled { - return Ok(()); - } - - repo.set_enabled(true); - file.write()?; - - return Ok(()); - } - } - } - - let (repo, path) = - proxmox_apt::repositories::get_standard_repository(handle, product, suite); - - if let Some(error) = errors.iter().find(|error| error.path == path) { - bail!( - "unable to parse existing file {} - {}", - error.path, - error.error, - ); - } - - if let Some(file) = files - .iter_mut() - .find(|file| file.path.as_ref() == Some(&path)) - { - file.repositories.push(repo); - - file.write()?; - } else { - let mut file = match APTRepositoryFile::new(&path)? { - Some(file) => file, - None => bail!("invalid path - {}", path), - }; - - file.repositories.push(repo); - - file.write()?; - } - - Ok(()) + proxmox_apt::add_repository_handle(product, handle, digest) } /// Change the properties of the specified repository. @@ -108,34 +34,9 @@ pub mod export { pub fn change_repository( path: &str, index: usize, - options: ChangeProperties, + options: APTChangeRepositoryOptions, digest: Option, ) -> Result<(), Error> { - let (mut files, errors, current_digest) = proxmox_apt::repositories::repositories()?; - - 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); - } - - if let Some(file) = files - .iter_mut() - .find(|file| file.path.as_ref() == Some(&path.to_string())) - { - if let Some(repo) = file.repositories.get_mut(index) { - if let Some(enabled) = options.enabled { - repo.set_enabled(enabled); - } - - file.write()?; - } else { - bail!("invalid index - {}", index); - } - } else { - bail!("invalid path - {}", path); - } - - Ok(()) + proxmox_apt::change_repository(path, index, &options, digest) } } diff --git a/pmg-rs/src/apt/repositories.rs b/pmg-rs/src/apt/repositories.rs index 3680d5c..d8e89c2 100644 --- a/pmg-rs/src/apt/repositories.rs +++ b/pmg-rs/src/apt/repositories.rs @@ -1,7 +1,9 @@ #[perlmod::package(name = "PMG::RS::APT::Repositories")] mod export { use anyhow::Error; - use proxmox_apt_api_types::APTRepositoriesResult; + use proxmox_apt_api_types::{ + APTChangeRepositoryOptions, APTRepositoriesResult, APTRepositoryHandle, + }; use proxmox_config_digest::ConfigDigest; use crate::common::apt::repositories::export as common; @@ -17,7 +19,10 @@ mod export { /// /// The `digest` parameter asserts that the configuration has not been modified. #[export] - pub fn add_repository(handle: &str, digest: Option) -> Result<(), Error> { + pub fn add_repository( + handle: APTRepositoryHandle, + digest: Option, + ) -> Result<(), Error> { common::add_repository(handle, "pmg", digest) } @@ -28,7 +33,7 @@ mod export { pub fn change_repository( path: &str, index: usize, - options: common::ChangeProperties, + options: APTChangeRepositoryOptions, digest: Option, ) -> Result<(), Error> { common::change_repository(path, index, options, digest) diff --git a/pve-rs/src/apt/repositories.rs b/pve-rs/src/apt/repositories.rs index c1867a1..7fbf97c 100644 --- a/pve-rs/src/apt/repositories.rs +++ b/pve-rs/src/apt/repositories.rs @@ -2,7 +2,9 @@ mod export { use anyhow::Error; - use proxmox_apt_api_types::APTRepositoriesResult; + use proxmox_apt_api_types::{ + APTChangeRepositoryOptions, APTRepositoriesResult, APTRepositoryHandle, + }; use proxmox_config_digest::ConfigDigest; use crate::common::apt::repositories::export as common; @@ -10,7 +12,7 @@ mod export { /// Get information about configured and standard repositories. #[export] pub fn repositories() -> Result { - common::repositories("pve") + proxmox_apt::list_repositories("pve") } /// Add the repository identified by the `handle`. @@ -18,7 +20,10 @@ mod export { /// /// The `digest` parameter asserts that the configuration has not been modified. #[export] - pub fn add_repository(handle: &str, digest: Option) -> Result<(), Error> { + pub fn add_repository( + handle: APTRepositoryHandle, + digest: Option, + ) -> Result<(), Error> { common::add_repository(handle, "pve", digest) } @@ -29,7 +34,7 @@ mod export { pub fn change_repository( path: &str, index: usize, - options: common::ChangeProperties, + options: APTChangeRepositoryOptions, 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