Core/Config: Implement config override with env vars (#26811)

* Core/Config: Implement config override with env vars

Implement overriding of configuration from the .conf file with environment variables.
Environment variables keys are autogenerated based on the keys defined in .conf file.
Usage example:
$ export TC_DATA_DIR=/usr
$ TC_WORLD_SERVER_PORT=8080 ./worldserver

* Core/Config Fix typo in logs

Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>

* Core/Config Fix code style in EnvVarForIniKey

Co-authored-by: Shauren <shauren.trinity@gmail.com>

* Update tests/common/Config.cpp

* Apply suggestions from code review

Co-authored-by: Peter Keresztes Schmidt <carbenium@outlook.com>

* Apply suggestions from code review

Co-authored-by: Peter Keresztes Schmidt <carbenium@outlook.com>

Co-authored-by: Anton Popovichenko <anton.popovichenko@mendix.com>
Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
Co-authored-by: Shauren <shauren.trinity@gmail.com>
Co-authored-by: Peter Keresztes Schmidt <carbenium@outlook.com>
(cherry picked from commit 1ddd9dc19c)
This commit is contained in:
Anton Popovichenko
2021-08-19 22:26:16 +02:00
committed by Shauren
parent 1e9327d92c
commit 8447f627ba
5 changed files with 254 additions and 2 deletions

View File

@@ -192,6 +192,8 @@ extern int main(int argc, char** argv)
return 1;
}
std::vector<std::string> overriddenKeys = sConfigMgr->OverrideWithEnvVariablesIfAny();
std::shared_ptr<Trinity::Asio::IoContext> ioContext = std::make_shared<Trinity::Asio::IoContext>();
sLog->RegisterAppender<AppenderDB>();
@@ -211,6 +213,9 @@ extern int main(int argc, char** argv)
}
);
for (std::string const& key : overriddenKeys)
TC_LOG_INFO("server.worldserver", "Configuration field '%s' was overridden with environment variable.", key.c_str());
OpenSSLCrypto::threadsSetup();
std::shared_ptr<void> opensslHandle(nullptr, [](void*) { OpenSSLCrypto::threadsCleanup(); });