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 E44F17AA46 for ; Mon, 10 May 2021 09:23:44 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E1C001445E for ; Mon, 10 May 2021 09:23:44 +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 36C1C14429 for ; Mon, 10 May 2021 09:23:44 +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 114EB441CB for ; Mon, 10 May 2021 09:23:44 +0200 (CEST) To: pbs-devel@lists.proxmox.com References: <20210510063914.7527-1-dietmar@proxmox.com> <20210510063914.7527-2-dietmar@proxmox.com> From: Dietmar Maurer Message-ID: Date: Mon, 10 May 2021 09:23:42 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210510063914.7527-2-dietmar@proxmox.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-SPAM-LEVEL: Spam detection results: 0 AWL 0.175 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] applied: [PATCH proxmox-backup 2/2] fix 3296: add http_proxy to node config, and provide a cli 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: Mon, 10 May 2021 07:23:44 -0000 applied On 5/10/21 8:39 AM, Dietmar Maurer wrote: > From: Dylan Whyte > > Signed-off-by: Dylan Whyte > Signed-off-by: Dietmar Maurer > --- > src/bin/proxmox-backup-manager.rs | 1 + > src/bin/proxmox_backup_manager/mod.rs | 2 ++ > src/bin/proxmox_backup_manager/node.rs | 47 ++++++++++++++++++++++++++ > src/config/node.rs | 31 ++++++++++++++++- > 4 files changed, 80 insertions(+), 1 deletion(-) > create mode 100644 src/bin/proxmox_backup_manager/node.rs > > diff --git a/src/bin/proxmox-backup-manager.rs b/src/bin/proxmox-backup-manager.rs > index 522c800e..c3806a31 100644 > --- a/src/bin/proxmox-backup-manager.rs > +++ b/src/bin/proxmox-backup-manager.rs > @@ -352,6 +352,7 @@ fn main() { > .insert("disk", disk_commands()) > .insert("dns", dns_commands()) > .insert("network", network_commands()) > + .insert("node", node_commands()) > .insert("user", user_commands()) > .insert("remote", remote_commands()) > .insert("garbage-collection", garbage_collection_commands()) > diff --git a/src/bin/proxmox_backup_manager/mod.rs b/src/bin/proxmox_backup_manager/mod.rs > index e574e4d4..21004bbe 100644 > --- a/src/bin/proxmox_backup_manager/mod.rs > +++ b/src/bin/proxmox_backup_manager/mod.rs > @@ -22,3 +22,5 @@ mod subscription; > pub use subscription::*; > mod disk; > pub use disk::*; > +mod node; > +pub use node::*; > diff --git a/src/bin/proxmox_backup_manager/node.rs b/src/bin/proxmox_backup_manager/node.rs > new file mode 100644 > index 00000000..42109960 > --- /dev/null > +++ b/src/bin/proxmox_backup_manager/node.rs > @@ -0,0 +1,47 @@ > +use proxmox::api::{api, cli::*, ApiHandler, RpcEnvironment}; > +use anyhow::Error; > +use serde_json::Value; > + > +use proxmox_backup::api2; > + > +#[api( > + input: { > + properties: { > + "output-format": { > + schema: OUTPUT_FORMAT, > + optional: true, > + }, > + } > + } > +)] > +/// Show node configuration > +fn get_node_config(param: Value, rpcenv: &mut dyn RpcEnvironment) -> Result { > + > + let output_format = get_output_format(¶m); > + > + let info = &api2::node::config::API_METHOD_GET_NODE_CONFIG; > + let mut data = match info.handler { > + ApiHandler::Sync(handler) => (handler)(param, info, rpcenv)?, > + _ => unreachable!(), > + }; > + > + let options = default_table_format_options(); > + format_and_print_result_full(&mut data, &info.returns, &output_format, &options); > + > + Ok(Value::Null) > +} > + > +pub fn node_commands() -> CommandLineInterface { > + let cmd_def = CliCommandMap::new() > + .insert( > + "show", > + CliCommand::new(&API_METHOD_GET_NODE_CONFIG), > + ) > + .insert( > + "update", > + CliCommand::new(&api2::node::config::API_METHOD_UPDATE_NODE_CONFIG) > + .fixed_param("node", String::from("localhost")) > + ); > + > + cmd_def.into() > +} > diff --git a/src/config/node.rs b/src/config/node.rs > index 6f48409f..31a2c5ab 100644 > --- a/src/config/node.rs > +++ b/src/config/node.rs > @@ -10,8 +10,14 @@ use proxmox::api::api; > use proxmox::api::schema::{ApiStringFormat, Updater}; > use proxmox::tools::fs::{replace_file, CreateOptions}; > > -use crate::api2::types::{AcmeDomain, AcmeAccountName, ACME_DOMAIN_PROPERTY_SCHEMA}; > +use crate::api2::types::{ > + AcmeDomain, > + AcmeAccountName, > + ACME_DOMAIN_PROPERTY_SCHEMA, > + HTTP_PROXY_SCHEMA > +}; > use crate::acme::AcmeClient; > +use crate::tools::http::ProxyConfig; > > const CONF_FILE: &str = configdir!("/node.cfg"); > const LOCK_FILE: &str = configdir!("/.node.lck"); > @@ -88,9 +94,14 @@ pub struct AcmeConfig { > schema: ACME_DOMAIN_PROPERTY_SCHEMA, > optional: true, > }, > + "http-proxy": { > + schema: HTTP_PROXY_SCHEMA, > + optional: true, > + }, > }, > )] > #[derive(Deserialize, Serialize, Updater)] > +#[serde(rename_all = "kebab-case")] > /// Node specific configuration. > pub struct NodeConfig { > /// The acme account to use on this node. > @@ -111,6 +122,9 @@ pub struct NodeConfig { > > #[serde(skip_serializing_if = "Updater::is_empty")] > acmedomain4: Option, > + > + #[serde(skip_serializing_if = "Updater::is_empty")] > + http_proxy: Option, > } > > impl NodeConfig { > @@ -137,6 +151,21 @@ impl NodeConfig { > AcmeDomainIter::new(self) > } > > + pub fn http_proxy(&self) -> Option { > + if let Some(http_proxy) = &self.http_proxy { > + match ProxyConfig::parse_proxy_url(&http_proxy) { > + Ok(proxy) => Some(proxy), > + Err(_) => None, > + } > + } else { > + None > + } > + } > + > + pub fn set_proxy(&mut self, http_proxy: Option) { > + self.http_proxy = http_proxy; > + } > + > /// Validate the configuration. > pub fn validate(&self) -> Result<(), Error> { > let mut domains = HashSet::new();