Add ability to tolerate (ignore) old config options

This allows us to explicitly ignore (with a warning) old options
that are no longer supported.
pull/1248/head
Stephen Shelton 4 years ago
parent cdd4439cff
commit 331770b348
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -433,6 +433,7 @@ namespace llarp
ConfigDefinition conf;
initializeConfig(conf, params);
addBackwardsCompatibleConfigOptions(conf);
ConfigParser parser;
if (!parser.LoadFile(fname))
@ -505,6 +506,23 @@ namespace llarp
logging.defineConfigOptions(conf, params);
}
void
Config::addBackwardsCompatibleConfigOptions(ConfigDefinition& conf)
{
auto addIgnoreOption = [&](const std::string& section, const std::string& name) {
conf.defineOption<std::string>(section, name, false, true, "", [=](std::string arg) {
(void)arg;
LogWarn("*** WARNING: The config option [", section, "]:", name, " is deprecated");
});
};
addIgnoreOption("system", "user");
addIgnoreOption("system", "group");
addIgnoreOption("system", "pidfile");
addIgnoreOption("api", "authkey");
}
void
ensureConfig(
const fs::path& defaultDataDir, const fs::path& confFile, bool overwrite, bool asRouter)

@ -185,6 +185,13 @@ namespace llarp
void
initializeConfig(ConfigDefinition& conf, const ConfigGenParameters& params);
/// Insert config entries for backwards-compatibility (e.g. so that the config system will
/// tolerate old values that are no longer accepted)
///
/// @param conf is the config to modify
void
addBackwardsCompatibleConfigOptions(ConfigDefinition& conf);
// Load a config from the given file
bool
Load(const char* fname, bool isRelay, fs::path defaultDataDir);

Loading…
Cancel
Save