[pbs-devel] [PATCH proxmox-backup 1/4] api: add consent api handler and config

Gabriel Goller g.goller at proxmox.com
Wed May 22 15:19:41 CEST 2024


Add config function to retrieve consent text from file and add it to
template function.

Signed-off-by: Gabriel Goller <g.goller at proxmox.com>
---
 src/bin/proxmox-backup-proxy.rs |  6 ++++++
 src/config/consent.rs           | 11 +++++++++++
 src/config/mod.rs               |  1 +
 3 files changed, 18 insertions(+)
 create mode 100644 src/config/consent.rs

diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
index 15444685..16b7fb6c 100644
--- a/src/bin/proxmox-backup-proxy.rs
+++ b/src/bin/proxmox-backup-proxy.rs
@@ -152,6 +152,11 @@ async fn get_index_future(env: RestEnvironment, parts: Parts) -> Response<Body>
 
     let theme = get_theme(&parts.headers);
 
+    let consent = if let Ok(text) = proxmox_backup::config::consent::config() {
+        text
+    } else {
+        "".to_string()
+    };
     let data = json!({
         "NodeName": nodename,
         "UserName": user,
@@ -160,6 +165,7 @@ async fn get_index_future(env: RestEnvironment, parts: Parts) -> Response<Body>
         "theme": theme,
         "auto": theme == "auto",
         "debug": debug,
+        "consentText": consent,
     });
 
     let (ct, index) = match api.render_template(template_file, &data) {
diff --git a/src/config/consent.rs b/src/config/consent.rs
new file mode 100644
index 00000000..55ef201c
--- /dev/null
+++ b/src/config/consent.rs
@@ -0,0 +1,11 @@
+use anyhow::Error;
+
+use pbs_buildcfg::configdir;
+
+const CONF_FILE: &str = configdir!("/consent.txt");
+
+/// Read the Consent config.
+pub fn config() -> Result<String, Error> {
+    let content = proxmox_sys::fs::file_read_optional_string(CONF_FILE)?.unwrap_or_default();
+    Ok(content)
+}
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 324fabca..81caf0d5 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -15,6 +15,7 @@ use proxmox_lang::try_block;
 use pbs_buildcfg::{self, configdir};
 
 pub mod acme;
+pub mod consent;
 pub mod node;
 pub mod tfa;
 
-- 
2.43.0





More information about the pbs-devel mailing list