public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] applied-series: [PATCH perl-rs 1/5] perl-rs: use proxmox-apt-api-types
@ 2024-07-09  6:20 Wolfgang Bumiller
  2024-07-09  6:20 ` [pve-devel] [PATCH perl-rs 2/5] perl-rs: use api functions from proxmox-apt Wolfgang Bumiller
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Wolfgang Bumiller @ 2024-07-09  6:20 UTC (permalink / raw)
  To: pve-devel

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pve-devel] [PATCH perl-rs 2/5] perl-rs: use api functions from proxmox-apt
  2024-07-09  6:20 [pve-devel] applied-series: [PATCH perl-rs 1/5] perl-rs: use proxmox-apt-api-types Wolfgang Bumiller
@ 2024-07-09  6:20 ` Wolfgang Bumiller
  2024-07-09  6:20 ` [pve-devel] [PATCH perl-rs 3/5] perl-rs: add further apt api calls Wolfgang Bumiller
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Bumiller @ 2024-07-09  6:20 UTC (permalink / raw)
  To: pve-devel

From: Dietmar Maurer <dietmar@proxmox.com>

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
---
 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<bool>,
-    }
-
     /// Get information about configured repositories and standard repositories for `product`.
     #[export]
     pub fn repositories(product: &str) -> Result<APTRepositoriesResult, Error> {
-        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<ConfigDigest>,
     ) -> 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<ConfigDigest>,
     ) -> 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<ConfigDigest>) -> Result<(), Error> {
+    pub fn add_repository(
+        handle: APTRepositoryHandle,
+        digest: Option<ConfigDigest>,
+    ) -> 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<ConfigDigest>,
     ) -> 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<APTRepositoriesResult, Error> {
-        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<ConfigDigest>) -> Result<(), Error> {
+    pub fn add_repository(
+        handle: APTRepositoryHandle,
+        digest: Option<ConfigDigest>,
+    ) -> 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<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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pve-devel] [PATCH perl-rs 3/5] perl-rs: add further apt api calls
  2024-07-09  6:20 [pve-devel] applied-series: [PATCH perl-rs 1/5] perl-rs: use proxmox-apt-api-types Wolfgang Bumiller
  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 ` 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
  3 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Bumiller @ 2024-07-09  6:20 UTC (permalink / raw)
  To: pve-devel

From: Dietmar Maurer <dietmar@proxmox.com>

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
---
 common/src/apt/repositories.rs | 49 +++++++++++++++++++++++++++++++++-
 pmg-rs/Cargo.toml              |  2 +-
 pve-rs/Cargo.toml              |  2 +-
 pve-rs/src/lib.rs              |  2 +-
 4 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/common/src/apt/repositories.rs b/common/src/apt/repositories.rs
index 61824d7..ccf4f33 100644
--- a/common/src/apt/repositories.rs
+++ b/common/src/apt/repositories.rs
@@ -4,7 +4,8 @@ pub mod export {
     use anyhow::Error;
 
     use proxmox_apt_api_types::{
-        APTChangeRepositoryOptions, APTRepositoriesResult, APTRepositoryHandle,
+        APTChangeRepositoryOptions, APTGetChangelogOptions, APTRepositoriesResult,
+        APTRepositoryHandle, APTUpdateInfo, APTUpdateOptions,
     };
     use proxmox_config_digest::ConfigDigest;
 
@@ -39,4 +40,50 @@ pub mod export {
     ) -> Result<(), Error> {
         proxmox_apt::change_repository(path, index, &options, digest)
     }
+
+    /// Retrieve the changelog of the specified package.
+    #[export]
+    pub fn get_changelog(options: APTGetChangelogOptions) -> Result<String, Error> {
+        proxmox_apt::get_changelog(&options)
+    }
+
+    /// List available APT updates
+    ///
+    /// Automatically updates an expired package cache.
+    #[export]
+    pub fn list_available_apt_update(apt_state_file: &str) -> Result<Vec<APTUpdateInfo>, Error> {
+        proxmox_apt::list_available_apt_update(apt_state_file)
+    }
+
+    /// Update the APT database
+    ///
+    /// You should update the APT proxy configuration before running this.
+    #[export]
+    pub fn update_database(apt_state_file: &str, options: APTUpdateOptions) -> Result<(), Error> {
+        proxmox_apt::update_database(
+            apt_state_file,
+            &options,
+            |_updates: &[&APTUpdateInfo]| -> Result<(), Error> {
+                // fixme: howto send notifgications?
+                Ok(())
+            },
+        )
+    }
+
+    /// Get package information for a list of important product packages.
+    #[export]
+    pub fn get_package_versions(
+        product_virtual_package: &str,
+        api_server_package: &str,
+        running_api_server_version: &str,
+        package_list: Vec<String>,
+    ) -> Result<Vec<APTUpdateInfo>, Error> {
+        let package_list: Vec<&str> = package_list.iter().map(|s| s.as_ref()).collect();
+        proxmox_apt::get_package_versions(
+            product_virtual_package,
+            api_server_package,
+            running_api_server_version,
+            &package_list,
+        )
+    }
 }
diff --git a/pmg-rs/Cargo.toml b/pmg-rs/Cargo.toml
index ad3a107..2706fcb 100644
--- a/pmg-rs/Cargo.toml
+++ b/pmg-rs/Cargo.toml
@@ -29,7 +29,7 @@ url = "2"
 perlmod = { version = "0.13.4", features = ["exporter"] }
 
 proxmox-acme = { version = "0.5", features = ["client", "api-types"] }
-proxmox-apt = "0.11"
+proxmox-apt = { version = "0.11", features = ["cache"] }
 proxmox-apt-api-types = "1.0"
 proxmox-config-digest = "0.1"
 proxmox-http = { version = "0.9", features = ["client-sync", "client-trait"] }
diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml
index ce7059d..3ba649e 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -31,7 +31,7 @@ url = "2"
 
 perlmod = { version = "0.13", features = ["exporter"] }
 
-proxmox-apt = "0.11"
+proxmox-apt = { version = "0.11", features = ["cache"] }
 proxmox-apt-api-types = "1.0"
 proxmox-config-digest = "0.1"
 proxmox-http = { version = "0.9", features = ["client-sync", "client-trait"] }
diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs
index 42be39e..73780f8 100644
--- a/pve-rs/src/lib.rs
+++ b/pve-rs/src/lib.rs
@@ -17,6 +17,6 @@ mod export {
     #[export]
     pub fn init() {
         common::logger::init("PVE_LOG", "info");
-        proxmox_notify::context::set_context(&PVE_CONTEXT)
+        proxmox_notify::context::set_context(&PVE_CONTEXT);
     }
 }
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pve-devel] [PATCH perl-rs 4/5] pve-rs: common: send apt update notification via proxmox-notify
  2024-07-09  6:20 [pve-devel] applied-series: [PATCH perl-rs 1/5] perl-rs: use proxmox-apt-api-types Wolfgang Bumiller
  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 ` Wolfgang Bumiller
  2024-07-09  6:20 ` [pve-devel] [PATCH perl-rs 5/5] apt: minor parameter cleanup Wolfgang Bumiller
  3 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Bumiller @ 2024-07-09  6:20 UTC (permalink / raw)
  To: pve-devel; +Cc: Lukas Wagner

From: Lukas Wagner <l.wagner@proxmox.com>

For PMG we for now only provide an empty stub and warn to syslog -
we need basic notification system integration there first.
On PMG, we still use a pure Perl implementation at the moment,
so this should not be an issue unless we change that.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 common/src/apt/repositories.rs |  3 +-
 pmg-rs/Cargo.toml              |  1 +
 pmg-rs/src/lib.rs              | 10 ++++++
 pve-rs/src/lib.rs              | 64 ++++++++++++++++++++++++++++++++++
 4 files changed, 77 insertions(+), 1 deletion(-)

diff --git a/common/src/apt/repositories.rs b/common/src/apt/repositories.rs
index ccf4f33..8ad29cc 100644
--- a/common/src/apt/repositories.rs
+++ b/common/src/apt/repositories.rs
@@ -63,8 +63,9 @@ pub mod export {
         proxmox_apt::update_database(
             apt_state_file,
             &options,
-            |_updates: &[&APTUpdateInfo]| -> Result<(), Error> {
+            |updates: &[&APTUpdateInfo]| -> Result<(), Error> {
                 // fixme: howto send notifgications?
+                crate::send_updates_available(updates)?;
                 Ok(())
             },
         )
diff --git a/pmg-rs/Cargo.toml b/pmg-rs/Cargo.toml
index 2706fcb..8a6d113 100644
--- a/pmg-rs/Cargo.toml
+++ b/pmg-rs/Cargo.toml
@@ -19,6 +19,7 @@ env_logger = "0.10"
 hex = "0.4"
 http = "0.2.7"
 libc = "0.2"
+log = "0.4.17"
 nix = "0.26"
 openssl = "0.10.40"
 serde = "1.0"
diff --git a/pmg-rs/src/lib.rs b/pmg-rs/src/lib.rs
index 4a91632..8bac823 100644
--- a/pmg-rs/src/lib.rs
+++ b/pmg-rs/src/lib.rs
@@ -6,6 +6,10 @@ pub mod apt;
 pub mod csr;
 pub mod tfa;
 
+use anyhow::Error;
+
+use proxmox_apt_api_types::APTUpdateInfo;
+
 #[perlmod::package(name = "Proxmox::Lib::PMG", lib = "pmg_rs")]
 mod export {
     use crate::common;
@@ -23,3 +27,9 @@ mod export {
         perlmod::ffi::use_safe_putenv(true);
     }
 }
+
+pub fn send_updates_available(_updates: &[&APTUpdateInfo]) -> Result<(), Error> {
+    log::warn!("update notifications are not implemented for PMG yet");
+
+    Ok(())
+}
diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs
index 73780f8..0fad753 100644
--- a/pve-rs/src/lib.rs
+++ b/pve-rs/src/lib.rs
@@ -8,6 +8,14 @@ pub mod openid;
 pub mod resource_scheduling;
 pub mod tfa;
 
+use std::collections::HashMap;
+
+use anyhow::Error;
+
+use proxmox_apt_api_types::APTUpdateInfo;
+use proxmox_notify::{Config, Notification, Severity};
+use serde_json::json;
+
 #[perlmod::package(name = "Proxmox::Lib::PVE", lib = "pve_rs")]
 mod export {
     use proxmox_notify::context::pve::PVE_CONTEXT;
@@ -20,3 +28,59 @@ mod export {
         proxmox_notify::context::set_context(&PVE_CONTEXT);
     }
 }
+
+fn send_notification(notification: &Notification) -> Result<(), Error> {
+    let config = proxmox_sys::fs::file_read_optional_string("/etc/pve/notifications.cfg")?
+        .unwrap_or_default();
+    let private_config =
+        proxmox_sys::fs::file_read_optional_string("/etc/pve/priv/notifications.cfg")?
+            .unwrap_or_default();
+
+    let config = Config::new(&config, &private_config)?;
+
+    proxmox_notify::api::common::send(&config, notification)?;
+
+    Ok(())
+}
+
+pub fn send_updates_available(updates: &[&APTUpdateInfo]) -> Result<(), Error> {
+    let hostname = proxmox_sys::nodename().to_string();
+
+    let metadata = HashMap::from([
+        ("hostname".into(), hostname.clone()),
+        ("type".into(), "package-updates".into()),
+    ]);
+
+    // The template uses the `table` handlebars helper, so
+    // we need to form the approriate data structure first.
+    let update_table = json!({
+        "schema": {
+            "columns": [
+                {
+                    "label": "Package",
+                    "id": "Package",
+                },
+                {
+                    "label": "Old Version",
+                    "id": "OldVersion",
+                },
+                {
+                    "label": "New Version",
+                    "id": "Version",
+                }
+            ],
+        },
+        "data": updates,
+    });
+
+    let template_data = json!({
+        "hostname": hostname,
+        "updates": update_table,
+    });
+
+    let notification =
+        Notification::from_template(Severity::Info, "package-updates", template_data, metadata);
+
+    send_notification(&notification)?;
+    Ok(())
+}
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pve-devel] [PATCH perl-rs 5/5] apt: minor parameter cleanup
  2024-07-09  6:20 [pve-devel] applied-series: [PATCH perl-rs 1/5] perl-rs: use proxmox-apt-api-types Wolfgang Bumiller
                   ` (2 preceding siblings ...)
  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 ` Wolfgang Bumiller
  3 siblings, 0 replies; 5+ messages in thread
From: Wolfgang Bumiller @ 2024-07-09  6:20 UTC (permalink / raw)
  To: pve-devel

We cannot use &[&str] - since this would be a poitner to a `[&str]`
data structure, that's not how perl stores strings.
But we *can* use Vec<&str> - here, the Vec will be allocated, but the
contents will borrow. We don't need to transform this afterwards.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
 common/src/apt/repositories.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/common/src/apt/repositories.rs b/common/src/apt/repositories.rs
index 8ad29cc..aff3522 100644
--- a/common/src/apt/repositories.rs
+++ b/common/src/apt/repositories.rs
@@ -77,9 +77,8 @@ pub mod export {
         product_virtual_package: &str,
         api_server_package: &str,
         running_api_server_version: &str,
-        package_list: Vec<String>,
+        package_list: Vec<&str>,
     ) -> Result<Vec<APTUpdateInfo>, Error> {
-        let package_list: Vec<&str> = package_list.iter().map(|s| s.as_ref()).collect();
         proxmox_apt::get_package_versions(
             product_virtual_package,
             api_server_package,
-- 
2.39.2



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-07-09  6:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-09  6:20 [pve-devel] applied-series: [PATCH perl-rs 1/5] perl-rs: use proxmox-apt-api-types Wolfgang Bumiller
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal