From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] applied-series: [PATCH perl-rs 1/5] perl-rs: use proxmox-apt-api-types
Date: Tue, 9 Jul 2024 08:20:22 +0200 [thread overview]
Message-ID: <20240709062026.53271-1-w.bumiller@proxmox.com> (raw)
From: Dietmar Maurer <dietmar@proxmox.com>
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
---
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<APTRepositoryFile>,
-
- /// Errors for files that could not be parsed or read.
- pub errors: Vec<APTRepositoryFileError>,
-
- /// Common digest for successfully parsed files.
- pub digest: String,
-
- /// Additional information/warnings about repositories.
- pub infos: Vec<APTRepositoryInfo>,
-
- /// Standard repositories and their configuration status.
- pub standard_repos: Vec<APTStandardRepository>,
- }
+ 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<RepositoriesResult, Error> {
+ pub fn repositories(product: &str) -> Result<APTRepositoriesResult, Error> {
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<ConfigDigest>,
+ ) -> 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<ConfigDigest>,
) -> 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<common::RepositoriesResult, Error> {
+ pub fn repositories() -> Result<APTRepositoriesResult, Error> {
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<ConfigDigest>) -> 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<ConfigDigest>,
) -> 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<common::RepositoriesResult, Error> {
+ pub fn repositories() -> Result<APTRepositoriesResult, Error> {
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<ConfigDigest>) -> 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<ConfigDigest>,
) -> 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
next reply other threads:[~2024-07-09 6:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-09 6:20 Wolfgang Bumiller [this message]
2024-07-09 6:20 ` [pve-devel] [PATCH perl-rs 2/5] perl-rs: use api functions from proxmox-apt Wolfgang Bumiller
2024-07-09 6:20 ` [pve-devel] [PATCH perl-rs 3/5] perl-rs: add further apt api calls Wolfgang Bumiller
2024-07-09 6:20 ` [pve-devel] [PATCH perl-rs 4/5] pve-rs: common: send apt update notification via proxmox-notify Wolfgang Bumiller
2024-07-09 6:20 ` [pve-devel] [PATCH perl-rs 5/5] apt: minor parameter cleanup Wolfgang Bumiller
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=20240709062026.53271-1-w.bumiller@proxmox.com \
--to=w.bumiller@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox