all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup 1/2] cleanup src/api2/node/config.rs
@ 2021-05-10  6:39 Dietmar Maurer
  2021-05-10  6:39 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix 3296: add http_proxy to node config, and provide a cli Dietmar Maurer
  2021-05-10  7:22 ` [pbs-devel] applied: [PATCH proxmox-backup 1/2] cleanup src/api2/node/config.rs Dietmar Maurer
  0 siblings, 2 replies; 4+ messages in thread
From: Dietmar Maurer @ 2021-05-10  6:39 UTC (permalink / raw)
  To: pbs-devel

- add return type
- fix permissions
- fix descriptions
---
 src/api2/node/config.rs | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/api2/node/config.rs b/src/api2/node/config.rs
index fd997062..92c0100e 100644
--- a/src/api2/node/config.rs
+++ b/src/api2/node/config.rs
@@ -1,12 +1,11 @@
 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;
+use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
+use crate::config::node::{NodeConfig, NodeConfigUpdater};
 
 pub const ROUTER: Router = Router::new()
     .get(&API_METHOD_GET_NODE_CONFIG)
@@ -19,14 +18,17 @@ pub const ROUTER: Router = Router::new()
         },
     },
     access: {
-        permission: &Permission::Privilege(&["system"], PRIV_SYS_MODIFY, false),
+        permission: &Permission::Privilege(&["system"], PRIV_SYS_AUDIT, false),
+    },
+    returns: {
+        type: NodeConfig,
     },
 )]
-/// Create a new changer device.
-pub fn get_node_config(mut rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
+/// Get the node configuration
+pub fn get_node_config(mut rpcenv: &mut dyn RpcEnvironment) -> Result<NodeConfig, Error> {
     let (config, digest) = crate::config::node::config()?;
     rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into();
-    Ok(serde_json::to_value(config)?)
+    Ok(config)
 }
 
 #[api(
@@ -52,7 +54,7 @@ pub fn get_node_config(mut rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Err
     },
     protected: true,
 )]
-/// Create a new changer device.
+/// Update the node configuration
 pub fn update_node_config(
     updater: NodeConfigUpdater,
     delete: Option<String>,
-- 
2.20.1




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pbs-devel] [PATCH proxmox-backup 2/2] fix 3296: add http_proxy to node config, and provide a cli
  2021-05-10  6:39 [pbs-devel] [PATCH proxmox-backup 1/2] cleanup src/api2/node/config.rs Dietmar Maurer
@ 2021-05-10  6:39 ` Dietmar Maurer
  2021-05-10  7:23   ` [pbs-devel] applied: " Dietmar Maurer
  2021-05-10  7:22 ` [pbs-devel] applied: [PATCH proxmox-backup 1/2] cleanup src/api2/node/config.rs Dietmar Maurer
  1 sibling, 1 reply; 4+ messages in thread
From: Dietmar Maurer @ 2021-05-10  6:39 UTC (permalink / raw)
  To: pbs-devel

From: Dylan Whyte <d.whyte@proxmox.com>

Signed-off-by: Dylan Whyte <d.whyte@proxmox.com>
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
---
 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<Value, Error> {
+
+    let output_format = get_output_format(&param);
+
+    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<String>,
+
+    #[serde(skip_serializing_if = "Updater::is_empty")]
+    http_proxy: Option<String>,
 }
 
 impl NodeConfig {
@@ -137,6 +151,21 @@ impl NodeConfig {
         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.
     pub fn validate(&self) -> Result<(), Error> {
         let mut domains = HashSet::new();
-- 
2.20.1




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pbs-devel] applied: [PATCH proxmox-backup 1/2] cleanup src/api2/node/config.rs
  2021-05-10  6:39 [pbs-devel] [PATCH proxmox-backup 1/2] cleanup src/api2/node/config.rs Dietmar Maurer
  2021-05-10  6:39 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix 3296: add http_proxy to node config, and provide a cli Dietmar Maurer
@ 2021-05-10  7:22 ` Dietmar Maurer
  1 sibling, 0 replies; 4+ messages in thread
From: Dietmar Maurer @ 2021-05-10  7:22 UTC (permalink / raw)
  To: pbs-devel

applied

On 5/10/21 8:39 AM, Dietmar Maurer wrote:
> - add return type
> - fix permissions
> - fix descriptions
> ---
>   src/api2/node/config.rs | 18 ++++++++++--------
>   1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/src/api2/node/config.rs b/src/api2/node/config.rs
> index fd997062..92c0100e 100644
> --- a/src/api2/node/config.rs
> +++ b/src/api2/node/config.rs
> @@ -1,12 +1,11 @@
>   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;
> +use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_SYS_MODIFY};
> +use crate::config::node::{NodeConfig, NodeConfigUpdater};
>   
>   pub const ROUTER: Router = Router::new()
>       .get(&API_METHOD_GET_NODE_CONFIG)
> @@ -19,14 +18,17 @@ pub const ROUTER: Router = Router::new()
>           },
>       },
>       access: {
> -        permission: &Permission::Privilege(&["system"], PRIV_SYS_MODIFY, false),
> +        permission: &Permission::Privilege(&["system"], PRIV_SYS_AUDIT, false),
> +    },
> +    returns: {
> +        type: NodeConfig,
>       },
>   )]
> -/// Create a new changer device.
> -pub fn get_node_config(mut rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Error> {
> +/// Get the node configuration
> +pub fn get_node_config(mut rpcenv: &mut dyn RpcEnvironment) -> Result<NodeConfig, Error> {
>       let (config, digest) = crate::config::node::config()?;
>       rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into();
> -    Ok(serde_json::to_value(config)?)
> +    Ok(config)
>   }
>   
>   #[api(
> @@ -52,7 +54,7 @@ pub fn get_node_config(mut rpcenv: &mut dyn RpcEnvironment) -> Result<Value, Err
>       },
>       protected: true,
>   )]
> -/// Create a new changer device.
> +/// Update the node configuration
>   pub fn update_node_config(
>       updater: NodeConfigUpdater,
>       delete: Option<String>,




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [pbs-devel] applied: [PATCH proxmox-backup 2/2] fix 3296: add http_proxy to node config, and provide a cli
  2021-05-10  6:39 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix 3296: add http_proxy to node config, and provide a cli Dietmar Maurer
@ 2021-05-10  7:23   ` Dietmar Maurer
  0 siblings, 0 replies; 4+ messages in thread
From: Dietmar Maurer @ 2021-05-10  7:23 UTC (permalink / raw)
  To: pbs-devel

applied

On 5/10/21 8:39 AM, Dietmar Maurer wrote:
> From: Dylan Whyte <d.whyte@proxmox.com>
>
> Signed-off-by: Dylan Whyte <d.whyte@proxmox.com>
> Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
> ---
>   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<Value, Error> {
> +
> +    let output_format = get_output_format(&param);
> +
> +    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<String>,
> +
> +    #[serde(skip_serializing_if = "Updater::is_empty")]
> +    http_proxy: Option<String>,
>   }
>   
>   impl NodeConfig {
> @@ -137,6 +151,21 @@ impl NodeConfig {
>           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.
>       pub fn validate(&self) -> Result<(), Error> {
>           let mut domains = HashSet::new();




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-10  7:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-10  6:39 [pbs-devel] [PATCH proxmox-backup 1/2] cleanup src/api2/node/config.rs Dietmar Maurer
2021-05-10  6:39 ` [pbs-devel] [PATCH proxmox-backup 2/2] fix 3296: add http_proxy to node config, and provide a cli Dietmar Maurer
2021-05-10  7:23   ` [pbs-devel] applied: " Dietmar Maurer
2021-05-10  7:22 ` [pbs-devel] applied: [PATCH proxmox-backup 1/2] cleanup src/api2/node/config.rs Dietmar Maurer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal