all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v6 pve-rs 1/4] initial commit
Date: Fri, 11 Jun 2021 13:44:10 +0200	[thread overview]
Message-ID: <20210611114418.28772-22-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210611114418.28772-1-f.ebner@proxmox.com>

with a module for wrapping apt repository functions.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v5:
    * Start with a fresh repository.
    * Add comments to exported functions.
    * Make exported functions pub.
    * Use Option<&str> for the digest parameter.

 .cargo/config           |  5 +++
 .gitignore              |  3 ++
 Cargo.toml              | 22 +++++++++++++
 rustfmt.toml            |  1 +
 src/apt/mod.rs          |  1 +
 src/apt/repositories.rs | 69 +++++++++++++++++++++++++++++++++++++++++
 src/lib.rs              |  1 +
 7 files changed, 102 insertions(+)
 create mode 100644 .cargo/config
 create mode 100644 .gitignore
 create mode 100644 Cargo.toml
 create mode 100644 rustfmt.toml
 create mode 100644 src/apt/mod.rs
 create mode 100644 src/apt/repositories.rs
 create mode 100644 src/lib.rs

diff --git a/.cargo/config b/.cargo/config
new file mode 100644
index 0000000..3b5b6e4
--- /dev/null
+++ b/.cargo/config
@@ -0,0 +1,5 @@
+[source]
+[source.debian-packages]
+directory = "/usr/share/cargo/registry"
+[source.crates-io]
+replace-with = "debian-packages"
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..52e46cb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/target
+Cargo.lock
+/PVE
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..d3b9955
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,22 @@
+[package]
+name = "pve-rs"
+version = "0.1.0"
+authors = ["Proxmox Support Team <support@proxmox.com>"]
+edition = "2018"
+license = "AGPL-3"
+description = "PVE parts which have been ported to Rust"
+homepage = "https://www.proxmox.com"
+exclude = [
+    "build",
+    "debian",
+    "PVE",
+]
+
+[lib]
+crate-type = [ "cdylib" ]
+
+[dependencies]
+anyhow = "1.0"
+proxmox = { version = "0.11.5" }
+proxmox-apt = "0.1.1"
+perlmod = { version = "0.4.3", features = [ "exporter" ] }
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..32a9786
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1 @@
+edition = "2018"
diff --git a/src/apt/mod.rs b/src/apt/mod.rs
new file mode 100644
index 0000000..574c1a7
--- /dev/null
+++ b/src/apt/mod.rs
@@ -0,0 +1 @@
+mod repositories;
diff --git a/src/apt/repositories.rs b/src/apt/repositories.rs
new file mode 100644
index 0000000..1643a23
--- /dev/null
+++ b/src/apt/repositories.rs
@@ -0,0 +1,69 @@
+#[perlmod::package(name = "PVE::RS::APT::Repositories", lib = "pve_rs")]
+mod export {
+    use anyhow::{bail, Error};
+
+    use perlmod::{to_value, Value};
+
+    /// Returns all APT repositories configured in `/etc/apt/sources.list` and
+    /// in `/etc/apt/sources.list.d` including disabled repositories.
+    ///
+    /// The first return value is the list of successfully parsed files of type `APTRepositoryFile`.
+    /// The second return value is the list of problems of type `APTRepositoryFileError`.
+    /// The third return value is a common digest of all successfully parsed files as a hexadecimal
+    /// string.
+    #[export(raw_return)]
+    pub fn repositories() -> Result<(Value, Value, Value), Error> {
+        let (files, errors) = proxmox_apt::repositories::repositories()?;
+
+        if files.is_empty() {
+            bail!("no APT repository files could be parsed!");
+        }
+
+        let common_digest = proxmox_apt::repositories::common_digest(&files);
+
+        let hex_digest = proxmox::tools::digest_to_hex(&common_digest);
+
+        Ok((
+            to_value(&files)?,
+            to_value(&errors)?,
+            to_value(&hex_digest)?,
+        ))
+    }
+
+    /// Provides additional information about the repositories.
+    ///
+    /// If `digest` is specified and doesn't match the current one, an error is returned.
+    ///
+    /// The first return value is the list of informations of type `APTRepositoryInfo`.
+    /// The second (resp. third) return values is a boolean indicating whether the enterprise
+    /// (resp. no-subscription) repository is configured.
+    #[export(raw_return)]
+    pub fn check_repositories(digest: Option<&str>) -> Result<(Value, Value, Value), Error> {
+        let (files, _) = proxmox_apt::repositories::repositories()?;
+
+        if files.is_empty() {
+            bail!("no APT repository files could be parsed!");
+        }
+
+        if let Some(digest) = digest {
+            let expected_digest = proxmox::tools::hex_to_digest(digest)?;
+            let current_digest = proxmox_apt::repositories::common_digest(&files);
+            if current_digest != expected_digest {
+                bail!("detected modified configuration - file changed by other user? Try again.");
+            }
+        }
+
+        let infos = proxmox_apt::repositories::check_repositories(&files);
+
+        let enterprise_enabled =
+            proxmox_apt::repositories::enterprise_repository_enabled(&files, "pve");
+        let no_subscription_enabled =
+            proxmox_apt::repositories::no_subscription_repository_enabled(&files, "pve");
+
+        Ok((
+            to_value(&infos)?,
+            to_value(&enterprise_enabled)?,
+            to_value(&no_subscription_enabled)?,
+        ))
+    }
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..10b3376
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1 @@
+pub mod apt;
-- 
2.20.1





WARNING: multiple messages have this Message-ID
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH v6 pve-rs 1/4] initial commit
Date: Fri, 11 Jun 2021 13:44:10 +0200	[thread overview]
Message-ID: <20210611114418.28772-22-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210611114418.28772-1-f.ebner@proxmox.com>

with a module for wrapping apt repository functions.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v5:
    * Start with a fresh repository.
    * Add comments to exported functions.
    * Make exported functions pub.
    * Use Option<&str> for the digest parameter.

 .cargo/config           |  5 +++
 .gitignore              |  3 ++
 Cargo.toml              | 22 +++++++++++++
 rustfmt.toml            |  1 +
 src/apt/mod.rs          |  1 +
 src/apt/repositories.rs | 69 +++++++++++++++++++++++++++++++++++++++++
 src/lib.rs              |  1 +
 7 files changed, 102 insertions(+)
 create mode 100644 .cargo/config
 create mode 100644 .gitignore
 create mode 100644 Cargo.toml
 create mode 100644 rustfmt.toml
 create mode 100644 src/apt/mod.rs
 create mode 100644 src/apt/repositories.rs
 create mode 100644 src/lib.rs

diff --git a/.cargo/config b/.cargo/config
new file mode 100644
index 0000000..3b5b6e4
--- /dev/null
+++ b/.cargo/config
@@ -0,0 +1,5 @@
+[source]
+[source.debian-packages]
+directory = "/usr/share/cargo/registry"
+[source.crates-io]
+replace-with = "debian-packages"
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..52e46cb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/target
+Cargo.lock
+/PVE
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..d3b9955
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,22 @@
+[package]
+name = "pve-rs"
+version = "0.1.0"
+authors = ["Proxmox Support Team <support@proxmox.com>"]
+edition = "2018"
+license = "AGPL-3"
+description = "PVE parts which have been ported to Rust"
+homepage = "https://www.proxmox.com"
+exclude = [
+    "build",
+    "debian",
+    "PVE",
+]
+
+[lib]
+crate-type = [ "cdylib" ]
+
+[dependencies]
+anyhow = "1.0"
+proxmox = { version = "0.11.5" }
+proxmox-apt = "0.1.1"
+perlmod = { version = "0.4.3", features = [ "exporter" ] }
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..32a9786
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1 @@
+edition = "2018"
diff --git a/src/apt/mod.rs b/src/apt/mod.rs
new file mode 100644
index 0000000..574c1a7
--- /dev/null
+++ b/src/apt/mod.rs
@@ -0,0 +1 @@
+mod repositories;
diff --git a/src/apt/repositories.rs b/src/apt/repositories.rs
new file mode 100644
index 0000000..1643a23
--- /dev/null
+++ b/src/apt/repositories.rs
@@ -0,0 +1,69 @@
+#[perlmod::package(name = "PVE::RS::APT::Repositories", lib = "pve_rs")]
+mod export {
+    use anyhow::{bail, Error};
+
+    use perlmod::{to_value, Value};
+
+    /// Returns all APT repositories configured in `/etc/apt/sources.list` and
+    /// in `/etc/apt/sources.list.d` including disabled repositories.
+    ///
+    /// The first return value is the list of successfully parsed files of type `APTRepositoryFile`.
+    /// The second return value is the list of problems of type `APTRepositoryFileError`.
+    /// The third return value is a common digest of all successfully parsed files as a hexadecimal
+    /// string.
+    #[export(raw_return)]
+    pub fn repositories() -> Result<(Value, Value, Value), Error> {
+        let (files, errors) = proxmox_apt::repositories::repositories()?;
+
+        if files.is_empty() {
+            bail!("no APT repository files could be parsed!");
+        }
+
+        let common_digest = proxmox_apt::repositories::common_digest(&files);
+
+        let hex_digest = proxmox::tools::digest_to_hex(&common_digest);
+
+        Ok((
+            to_value(&files)?,
+            to_value(&errors)?,
+            to_value(&hex_digest)?,
+        ))
+    }
+
+    /// Provides additional information about the repositories.
+    ///
+    /// If `digest` is specified and doesn't match the current one, an error is returned.
+    ///
+    /// The first return value is the list of informations of type `APTRepositoryInfo`.
+    /// The second (resp. third) return values is a boolean indicating whether the enterprise
+    /// (resp. no-subscription) repository is configured.
+    #[export(raw_return)]
+    pub fn check_repositories(digest: Option<&str>) -> Result<(Value, Value, Value), Error> {
+        let (files, _) = proxmox_apt::repositories::repositories()?;
+
+        if files.is_empty() {
+            bail!("no APT repository files could be parsed!");
+        }
+
+        if let Some(digest) = digest {
+            let expected_digest = proxmox::tools::hex_to_digest(digest)?;
+            let current_digest = proxmox_apt::repositories::common_digest(&files);
+            if current_digest != expected_digest {
+                bail!("detected modified configuration - file changed by other user? Try again.");
+            }
+        }
+
+        let infos = proxmox_apt::repositories::check_repositories(&files);
+
+        let enterprise_enabled =
+            proxmox_apt::repositories::enterprise_repository_enabled(&files, "pve");
+        let no_subscription_enabled =
+            proxmox_apt::repositories::no_subscription_repository_enabled(&files, "pve");
+
+        Ok((
+            to_value(&infos)?,
+            to_value(&enterprise_enabled)?,
+            to_value(&no_subscription_enabled)?,
+        ))
+    }
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..10b3376
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1 @@
+pub mod apt;
-- 
2.20.1





  parent reply	other threads:[~2021-06-11 11:44 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-11 11:43 [pve-devel] [PATCH-SERIES v6] APT repositories API/UI Fabian Ebner
2021-06-11 11:43 ` [pbs-devel] " Fabian Ebner
2021-06-11 11:43 ` [pve-devel] [PATCH v6 proxmox-apt 01/11] initial commit Fabian Ebner
2021-06-11 11:43   ` [pbs-devel] " Fabian Ebner
2021-06-18  8:14   ` [pve-devel] " Fabian Grünbichler
2021-06-18  8:14     ` [pbs-devel] " Fabian Grünbichler
2021-06-11 11:43 ` [pve-devel] [PATCH v6 proxmox-apt 02/11] add files for Debian packaging Fabian Ebner
2021-06-11 11:43   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:43 ` [pve-devel] [PATCH v6 proxmox-apt 03/11] add functions to check for Proxmox repositories Fabian Ebner
2021-06-11 11:43   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:43 ` [pve-devel] [PATCH v6 proxmox-apt 04/11] add check_repositories function Fabian Ebner
2021-06-11 11:43   ` [pbs-devel] " Fabian Ebner
2021-06-17  8:39   ` [pve-devel] " Wolfgang Bumiller
2021-06-17  8:39     ` [pbs-devel] " Wolfgang Bumiller
2021-06-18  6:42     ` Fabian Ebner
2021-06-18  6:42       ` [pbs-devel] " Fabian Ebner
2021-06-17 14:16   ` Fabian Grünbichler
2021-06-17 14:16     ` [pbs-devel] " Fabian Grünbichler
2021-06-11 11:43 ` [pve-devel] [PATCH v6 proxmox-apt 05/11] add common_digest helper Fabian Ebner
2021-06-11 11:43   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:43 ` [pve-devel] [PATCH v6 proxmox-apt 06/11] add release_upgrade function and constants for the current and upgrade suite Fabian Ebner
2021-06-11 11:43   ` [pbs-devel] " Fabian Ebner
2021-06-17 14:16   ` [pve-devel] " Fabian Grünbichler
2021-06-17 14:16     ` Fabian Grünbichler
2021-06-18  6:50     ` [pve-devel] " Fabian Ebner
2021-06-18  6:50       ` Fabian Ebner
2021-06-11 11:43 ` [pve-devel] [PATCH v6 proxmox-apt 07/11] bump version to 0.1.1-1 Fabian Ebner
2021-06-11 11:43   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:43 ` [pve-devel] [PATCH v6 proxmox-apt 08/11] update for bullseye Fabian Ebner
2021-06-11 11:43   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:43 ` [pve-devel] [PATCH v6 proxmox-apt 09/11] bump version to 1.0.0-1 Fabian Ebner
2021-06-11 11:43   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:43 ` [pve-devel] [PATCH v6 proxmox-apt 10/11] allow upgrade to bullseye Fabian Ebner
2021-06-11 11:43   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 proxmox-apt 11/11] bump version to 0.2.0-1 Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 proxmox-widget-toolkit 1/3] add UI for APT repositories Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 proxmox-widget-toolkit 2/3] APT repositories: add warnings Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 proxmox-widget-toolkit 3/3] add upgrade button Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 proxmox-backup 1/6] depend on new proxmox-apt crate Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 proxmox-backup 2/6] api: apt: add repositories call Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 proxmox-backup 3/6] ui: add APT repositories Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 proxmox-backup 4/6] api: apt: add check_repositories_call Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 proxmox-backup 5/6] add upgrade_repositories call Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-18  8:21   ` [pve-devel] " Fabian Grünbichler
2021-06-18  8:21     ` [pbs-devel] " Fabian Grünbichler
2021-06-11 11:44 ` [pve-devel] [RFC v6 proxmox-backup 6/6] enable release upgrade for package repositories Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` Fabian Ebner [this message]
2021-06-11 11:44   ` [pbs-devel] [PATCH v6 pve-rs 1/4] initial commit Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 pve-rs 2/4] add files for Debian packaging Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 pve-rs 3/4] apt: add upgrade_repositories call Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 pve-rs 4/4] depend on proxmox-apt 0.2.0 Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 pve-manager 1/5] api: apt: add call to list repositories Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 pve-manager 2/5] ui: add panel for listing APT repositories Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 pve-manager 3/5] api: apt: add call for repository check Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 pve-manager 4/5] api: apt: add upgrade repos call Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner
2021-06-11 11:44 ` [pve-devel] [PATCH v6 pve-manager 5/5] ui: node config: enable release upgrade button for package repositories Fabian Ebner
2021-06-11 11:44   ` [pbs-devel] " Fabian Ebner

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=20210611114418.28772-22-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pbs-devel@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal