fix 3296: add http_proxy to node config, and provide a cli
Signed-off-by: Dylan Whyte <d.whyte@proxmox.com> Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
parent
2732c47466
commit
72e311c6b2
@ -352,6 +352,7 @@ fn main() {
|
|||||||
.insert("disk", disk_commands())
|
.insert("disk", disk_commands())
|
||||||
.insert("dns", dns_commands())
|
.insert("dns", dns_commands())
|
||||||
.insert("network", network_commands())
|
.insert("network", network_commands())
|
||||||
|
.insert("node", node_commands())
|
||||||
.insert("user", user_commands())
|
.insert("user", user_commands())
|
||||||
.insert("remote", remote_commands())
|
.insert("remote", remote_commands())
|
||||||
.insert("garbage-collection", garbage_collection_commands())
|
.insert("garbage-collection", garbage_collection_commands())
|
||||||
|
@ -22,3 +22,5 @@ mod subscription;
|
|||||||
pub use subscription::*;
|
pub use subscription::*;
|
||||||
mod disk;
|
mod disk;
|
||||||
pub use disk::*;
|
pub use disk::*;
|
||||||
|
mod node;
|
||||||
|
pub use node::*;
|
||||||
|
47
src/bin/proxmox_backup_manager/node.rs
Normal file
47
src/bin/proxmox_backup_manager/node.rs
Normal file
@ -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<Value, Error> {
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
@ -10,8 +10,14 @@ use proxmox::api::api;
|
|||||||
use proxmox::api::schema::{ApiStringFormat, Updater};
|
use proxmox::api::schema::{ApiStringFormat, Updater};
|
||||||
use proxmox::tools::fs::{replace_file, CreateOptions};
|
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::acme::AcmeClient;
|
||||||
|
use crate::tools::http::ProxyConfig;
|
||||||
|
|
||||||
const CONF_FILE: &str = configdir!("/node.cfg");
|
const CONF_FILE: &str = configdir!("/node.cfg");
|
||||||
const LOCK_FILE: &str = configdir!("/.node.lck");
|
const LOCK_FILE: &str = configdir!("/.node.lck");
|
||||||
@ -88,9 +94,14 @@ pub struct AcmeConfig {
|
|||||||
schema: ACME_DOMAIN_PROPERTY_SCHEMA,
|
schema: ACME_DOMAIN_PROPERTY_SCHEMA,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
"http-proxy": {
|
||||||
|
schema: HTTP_PROXY_SCHEMA,
|
||||||
|
optional: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
#[derive(Deserialize, Serialize, Updater)]
|
#[derive(Deserialize, Serialize, Updater)]
|
||||||
|
#[serde(rename_all = "kebab-case")]
|
||||||
/// Node specific configuration.
|
/// Node specific configuration.
|
||||||
pub struct NodeConfig {
|
pub struct NodeConfig {
|
||||||
/// The acme account to use on this node.
|
/// The acme account to use on this node.
|
||||||
@ -111,6 +122,9 @@ pub struct NodeConfig {
|
|||||||
|
|
||||||
#[serde(skip_serializing_if = "Updater::is_empty")]
|
#[serde(skip_serializing_if = "Updater::is_empty")]
|
||||||
acmedomain4: Option<String>,
|
acmedomain4: Option<String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Updater::is_empty")]
|
||||||
|
http_proxy: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeConfig {
|
impl NodeConfig {
|
||||||
@ -137,6 +151,21 @@ impl NodeConfig {
|
|||||||
AcmeDomainIter::new(self)
|
AcmeDomainIter::new(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn http_proxy(&self) -> Option<ProxyConfig> {
|
||||||
|
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<String>) {
|
||||||
|
self.http_proxy = http_proxy;
|
||||||
|
}
|
||||||
|
|
||||||
/// Validate the configuration.
|
/// Validate the configuration.
|
||||||
pub fn validate(&self) -> Result<(), Error> {
|
pub fn validate(&self) -> Result<(), Error> {
|
||||||
let mut domains = HashSet::new();
|
let mut domains = HashSet::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user