]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Handle values set to default values.
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 28 Oct 2025 15:30:40 +0000 (16:30 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 4 Nov 2025 12:40:38 +0000 (13:40 +0100)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/recursordist/rec-rust-lib/cxxsettings.hh
pdns/recursordist/rec-rust-lib/cxxsupport.cc
pdns/recursordist/rec-rust-lib/rust-bridge-in.rs
pdns/recursordist/rec-rust-lib/rust/src/bridge.rs
pdns/recursordist/rec_channel_rec.cc

index cf4fc318cb6ac0721531dc1b7d899e1fd4ac1008..9e82016d6d7487651056edb9da0e1b0f2ebb9d1a 100644 (file)
@@ -43,7 +43,7 @@ void oldStyleForwardsFileToBridgeStruct(const std::string& filename, ::rust::Vec
 void oldStyleAllowFileToBridgeStruct(const std::string& filename, ::rust::Vec<::rust::String>& vec);
 bool oldKVToBridgeStruct(string& key, const string& value, ::rust::String& section, ::rust::String& fieldname, ::rust::String& type_name, pdns::rust::settings::rec::Value& rustvalue);
 std::string oldStyleSettingsFileToYaml(const string& fname, bool mainFile);
-std::string defaultsToYaml();
+std::string defaultsToYaml(bool postProcess = true);
 YamlSettingsStatus readYamlSettings(const std::string& configname, const std::string& includeDirOnCommandLine, rust::settings::rec::Recursorsettings& settings, std::string& msg, Logr::log_t log);
 void processAPIDir(const string& includeDirOnCommandLine, pdns::rust::settings::rec::Recursorsettings& settings, Logr::log_t log);
 void bridgeStructToOldStyleSettings(const pdns::rust::settings::rec::Recursorsettings& settings);
index 02117358587a84ab842781eb0e18558589d0816c..0c7a7cb918621eb52e0639dac045fdb3b3ec5d5c 100644 (file)
@@ -631,7 +631,7 @@ std::string pdns::settings::rec::oldStyleSettingsFileToYaml(const string& fname,
   return std::string(pdns::rust::settings::rec::map_to_yaml_string(vec));
 }
 
-std::string pdns::settings::rec::defaultsToYaml()
+std::string pdns::settings::rec::defaultsToYaml(bool postProcess)
 {
   // In this function we make use of the fact that we know a little about the formatting of YAML by
   // serde_yaml.  ATM there's no way around that, as serde_yaml itself does not have any support for
@@ -689,6 +689,9 @@ std::string pdns::settings::rec::defaultsToYaml()
   }
   const auto defs = std::string(pdns::rust::settings::rec::map_to_yaml_string(vec));
 
+  if (!postProcess) {
+    return defs;
+  }
   // We now have a YAML string, with all sections and all default values. Do a litle bit of parsing
   // to insert the help text lines.
   std::vector<std::string> lines;
index 9963ef2376ef6b15cde9b6fbf8c7b63560a34af8..1e75d07b15f9ae8a4bf936dc11b7311e78e66124 100644 (file)
@@ -403,7 +403,7 @@ extern "Rust" {
 
     // Prdoduce a YAML formatted string given a data structure known to Serde
     fn to_yaml_string(self: &Recursorsettings) -> Result<String>;
-    fn get_value(self: &Recursorsettings, field: &Vec<String>) -> Result<String>;
+    fn get_value(self: &Recursorsettings, field: &Vec<String>, defaults: &str) -> Result<String>;
     // When doing a conversion of old-style to YAML style we use a vector of OldStyle structs
     fn map_to_yaml_string(map: &Vec<OldStyle>) -> Result<String>;
     fn forward_zones_to_yaml_string(vec: &Vec<ForwardZone>) -> Result<String>;
index cc218652aee6eb97efcac9ac10a6b148f48a0918..0000a8c5c28ff98c8d86b981c07b53489b8e8d32 100644 (file)
@@ -942,12 +942,7 @@ impl Recursorsettings {
         }
     }
 
-    pub fn get_value(&self, field: &Vec<String>) -> Result<String, std::io::Error> {
-        let value = serde_yaml::to_value(self);
-        let value = match value {
-            Ok(value) => value,
-            Err(error) => return Err(std::io::Error::other(error.to_string()))
-        };
+    fn get_value1(value: &serde_yaml::Value, field: &[String]) -> Result<String, std::io::Error> {
         if let Some(map) = value.as_mapping() {
             match field.len() {
                 0 => {
@@ -969,6 +964,25 @@ impl Recursorsettings {
         Err(std::io::Error::other(field[0].to_owned() + ": not a map"))
     }
 
+    pub fn get_value(&self, field: &Vec<String>, defaults: &str) -> Result<String, std::io::Error> {
+        let value = serde_yaml::to_value(self);
+        let value = match value {
+            Ok(value) => value,
+            Err(error) => return Err(std::io::Error::other(error.to_string()))
+        };
+        match Self::get_value1(&value, field) {
+            Ok(result) => Ok(result),
+            Err(_) => {
+                let defaults_value: serde_yaml::Value = serde_yaml::from_str(defaults).unwrap();
+                let yaml = Self::get_value1(&defaults_value, field);
+                match yaml {
+                    Ok(yaml) => Ok("# Not explicitly set, default value is:\n".to_owned() + &yaml),
+                    Err(x) => Err(x)
+                }
+            }
+        }
+    }
+
     // validate() is implemented in the (generated) lib.rs
 }
 
index 6d5bc4bc194dada838226190057d1f14e82eccbd..9b0f3a041136841f3a6bc8f9dcf77f4840f4d938 100644 (file)
@@ -315,7 +315,7 @@ static Answer doGetParameter(ArgIterator begin, ArgIterator end)
   rust::Vec<::rust::String> field;
   stringtok(field, *begin, ".");
   try {
-    auto yaml = settings->get_value(field);
+    auto yaml = settings->get_value(field, pdns::settings::rec::defaultsToYaml(false));
     return {0, std::string(yaml)};
   }
   catch (const std::exception& stdex) {