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) }