Add config-file support

This commit is contained in:
Lee *!* Clagett 2023-07-06 12:11:01 -04:00
parent 935acaacc5
commit 7df7fdb744

View file

@ -43,6 +43,7 @@
#include "config.h" #include "config.h"
#include "cryptonote_config.h" // monero/src/ #include "cryptonote_config.h" // monero/src/
#include "db/storage.h" #include "db/storage.h"
#include "error.h"
#include "options.h" #include "options.h"
#include "rest_server.h" #include "rest_server.h"
#include "scanner.h" #include "scanner.h"
@ -76,6 +77,7 @@ namespace
const command_line::arg_descriptor<unsigned short> log_level; const command_line::arg_descriptor<unsigned short> log_level;
const command_line::arg_descriptor<bool> disable_admin_auth; const command_line::arg_descriptor<bool> disable_admin_auth;
const command_line::arg_descriptor<std::string> webhook_ssl_verification; const command_line::arg_descriptor<std::string> webhook_ssl_verification;
const command_line::arg_descriptor<std::string> config_file;
static std::string get_default_zmq() static std::string get_default_zmq()
{ {
@ -117,6 +119,7 @@ namespace
, log_level{"log-level", "Log level [0-4]", 1} , log_level{"log-level", "Log level [0-4]", 1}
, disable_admin_auth{"disable-admin-auth", "Make auth field optional in HTTP-REST requests", false} , disable_admin_auth{"disable-admin-auth", "Make auth field optional in HTTP-REST requests", false}
, webhook_ssl_verification{"webhook-ssl-verification", "[<none|system_ca>] specify SSL verification mode for webhooks", "system_ca"} , webhook_ssl_verification{"webhook-ssl-verification", "[<none|system_ca>] specify SSL verification mode for webhooks", "system_ca"}
, config_file{"config-file", "Specify any option in a config file; <name>=<value> on separate lines"}
{} {}
void prepare(boost::program_options::options_description& description) const void prepare(boost::program_options::options_description& description) const
@ -146,6 +149,7 @@ namespace
command_line::add_arg(description, log_level); command_line::add_arg(description, log_level);
command_line::add_arg(description, disable_admin_auth); command_line::add_arg(description, disable_admin_auth);
command_line::add_arg(description, webhook_ssl_verification); command_line::add_arg(description, webhook_ssl_verification);
command_line::add_arg(description, config_file);
} }
}; };
@ -188,6 +192,18 @@ namespace
po::command_line_parser(argc, argv).options(description).run(), args po::command_line_parser(argc, argv).options(description).run(), args
); );
po::notify(args); po::notify(args);
if (!command_line::is_arg_defaulted(args, opts.config_file))
{
boost::filesystem::path config_path{command_line::get_arg(args, opts.config_file)};
if (!boost::filesystem::exists(config_path))
MONERO_THROW(lws::error::configuration, "Config file does not exist");
po::store(
po::parse_config_file<char>(config_path.string<std::string>().c_str(), description), args
);
po::notify(args);
}
} }
if (command_line::get_arg(args, command_line::arg_help)) if (command_line::get_arg(args, command_line::arg_help))