From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id BA70873A90; Fri, 28 May 2021 16:31:00 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3490FB04E; Fri, 28 May 2021 16:30:23 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id BF8E8AC64; Fri, 28 May 2021 16:30:10 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 96C2B4179F; Fri, 28 May 2021 16:30:10 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com, pbs-devel@lists.proxmox.com Date: Fri, 28 May 2021 16:29:55 +0200 Message-Id: <20210528143002.16190-17-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210528143002.16190-1-f.ebner@proxmox.com> References: <20210528143002.16190-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.003 Adjusted score from AWL reputation of From: address 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lib.rs, repositories.rs, mod.rs, proxmox.com] Subject: [pve-devel] [RFC v5 pve-rs 16/23] add perlmod crate with initial APT module 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: , X-List-Received-Date: Fri, 28 May 2021 14:31:00 -0000 and disable diskmanage for now, whose Cargo.toml references local paths. Signed-off-by: Fabian Ebner --- New in v5. Cargo.toml | 3 +- perlmod/Cargo.toml | 17 ++++++++++ perlmod/src/apt/mod.rs | 1 + perlmod/src/apt/repositories.rs | 55 +++++++++++++++++++++++++++++++++ perlmod/src/lib.rs | 1 + 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 perlmod/Cargo.toml create mode 100644 perlmod/src/apt/mod.rs create mode 100644 perlmod/src/apt/repositories.rs create mode 100644 perlmod/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index d16a498..0ffd4a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] members = [ - "diskmanage", +# "diskmanage", + "perlmod", ] diff --git a/perlmod/Cargo.toml b/perlmod/Cargo.toml new file mode 100644 index 0000000..397f444 --- /dev/null +++ b/perlmod/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "pve-rs" +version = "0.1.0" +authors = ["Proxmox Support Team "] +edition = "2018" +license = "AGPL-3" +description = "Perl bindings for proxmox-apt" +homepage = "https://www.proxmox.com" + +[lib] +crate-type = [ "cdylib" ] + +[dependencies] +anyhow = "1.0" +proxmox = { version = "0.11.5" } +proxmox-apt = "0.1.0" +perlmod = { version = "0.4.3", features = [ "exporter" ] } diff --git a/perlmod/src/apt/mod.rs b/perlmod/src/apt/mod.rs new file mode 100644 index 0000000..574c1a7 --- /dev/null +++ b/perlmod/src/apt/mod.rs @@ -0,0 +1 @@ +mod repositories; diff --git a/perlmod/src/apt/repositories.rs b/perlmod/src/apt/repositories.rs new file mode 100644 index 0000000..37a62f2 --- /dev/null +++ b/perlmod/src/apt/repositories.rs @@ -0,0 +1,55 @@ +#[perlmod::package(name = "PVE::RS::APT::Repositories", lib = "pve_rs")] +mod export { + use anyhow::{bail, Error}; + + use perlmod::{to_value, Value}; + + #[export(raw_return)] + 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)?, + )) + } + + #[export(raw_return)] + fn check_repositories(digest: String) -> Result<(Value, Value, Value), Error> { + let (files, _) = proxmox_apt::repositories::repositories()?; + + if files.is_empty() { + bail!("no APT repository files could be parsed!"); + } + + if !digest.is_empty() { + 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/perlmod/src/lib.rs b/perlmod/src/lib.rs new file mode 100644 index 0000000..10b3376 --- /dev/null +++ b/perlmod/src/lib.rs @@ -0,0 +1 @@ +pub mod apt; -- 2.20.1