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 9BF6A73ADD for ; Fri, 16 Apr 2021 15:35:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id D5F3C24EF4 for ; Fri, 16 Apr 2021 15:35:29 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (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 119D024C83 for ; Fri, 16 Apr 2021 15:35:24 +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 CE3D245B36 for ; Fri, 16 Apr 2021 15:35:23 +0200 (CEST) From: Wolfgang Bumiller To: pbs-devel@lists.proxmox.com Date: Fri, 16 Apr 2021 15:35:12 +0200 Message-Id: <20210416133517.23349-20-w.bumiller@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210416133517.23349-1-w.bumiller@proxmox.com> References: <20210416133517.23349-1-w.bumiller@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.031 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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] [RFC backup 19/23] 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: Fri, 16 Apr 2021 13:35:54 -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