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);
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
}
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;
// 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>;
}
}
- 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 => {
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
}
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) {