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 DB12E75C71 for ; Thu, 22 Apr 2021 16:02:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CBCB51CDF0 for ; Thu, 22 Apr 2021 16:02:27 +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 E38521CC6E for ; Thu, 22 Apr 2021 16:02:19 +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 BE5AD463D4 for ; Thu, 22 Apr 2021 16:02:19 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Thu, 22 Apr 2021 16:02:06 +0200 Message-Id: <20210422140213.30989-21-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210422140213.30989-1-w.bumiller@proxmox.com> References: <20210422140213.30989-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.062 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. [node.rs, config.rs] Subject: [pbs-devel] [PATCH v2 backup 20/27] add node/{node}/config api path X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Apr 2021 14:02:57 -0000 Signed-off-by: Wolfgang Bumiller --- src/api2/node.rs | 2 + src/api2/node/config.rs | 81 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/api2/node/config.rs diff --git a/src/api2/node.rs b/src/api2/node.rs index ebb51aaf..75271cd5 100644 --- a/src/api2/node.rs +++ b/src/api2/node.rs @@ -28,6 +28,7 @@ use crate::tools::ticket::{self, Empty, Ticket}; pub mod apt; pub mod certificates; +pub mod config; pub mod disks; pub mod dns; pub mod network; @@ -316,6 +317,7 @@ fn upgrade_to_websocket( pub const SUBDIRS: SubdirMap = &[ ("apt", &apt::ROUTER), ("certificates", &certificates::ROUTER), + ("config", &config::ROUTER), ("disks", &disks::ROUTER), ("dns", &dns::ROUTER), ("journal", &journal::ROUTER), diff --git a/src/api2/node/config.rs b/src/api2/node/config.rs new file mode 100644 index 00000000..2e7fd670 --- /dev/null +++ b/src/api2/node/config.rs @@ -0,0 +1,81 @@ +use anyhow::Error; +use serde_json::Value; + +use proxmox::api::schema::Updatable; +use proxmox::api::{api, Permission, Router, RpcEnvironment}; + +use crate::api2::types::NODE_SCHEMA; +use crate::config::acl::PRIV_SYS_MODIFY; +use crate::config::node::NodeConfigUpdater; + +pub const ROUTER: Router = Router::new() + .get(&API_METHOD_GET_NODE_CONFIG) + .put(&API_METHOD_UPDATE_NODE_CONFIG); + +#[api( + input: { + properties: { + node: { schema: NODE_SCHEMA }, + }, + }, + access: { + permission: &Permission::Privilege(&["system"], PRIV_SYS_MODIFY, false), + }, +)] +/// Create a new changer device. +pub fn get_node_config(mut rpcenv: &mut dyn RpcEnvironment) -> Result { + let _lock = crate::config::node::read_lock()?; + let (config, digest) = crate::config::node::config()?; + rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into(); + Ok(serde_json::to_value(config)?) +} + +#[api( + input: { + properties: { + node: { schema: NODE_SCHEMA }, + digest: { + description: "Digest to protect against concurrent updates", + optional: true, + }, + updater: { + type: NodeConfigUpdater, + flatten: true, + }, + delete: { + description: "Options to remove from the configuration", + optional: true, + }, + }, + }, + access: { + permission: &Permission::Privilege(&["system"], PRIV_SYS_MODIFY, false), + }, + protected: true, +)] +/// Create a new changer device. +pub fn update_node_config( + updater: NodeConfigUpdater, + delete: Option, + digest: Option, +) -> Result<(), Error> { + let _lock = crate::config::node::write_lock()?; + let (mut config, expected_digest) = crate::config::node::config()?; + if let Some(digest) = digest { + // FIXME: GUI doesn't handle our non-inlined digest part here properly... + if !digest.is_empty() { + let digest = proxmox::tools::hex_to_digest(&digest)?; + crate::tools::detect_modified_configuration_file(&digest, &expected_digest)?; + } + } + + let delete: Vec<&str> = delete + .as_deref() + .unwrap_or("") + .split(&[' ', ',', ';', '\0'][..]) + .collect(); + + config.update_from(updater, &delete)?; + + crate::config::node::save_config(&config) +} -- 2.20.1