mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[Server] Add per-run configuration overrides (#7820)
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / vcpkg baseline (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Fedora 45 release (push) Blocked by required conditions
Build Desktop / Fedora 45 debug (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 sanitize (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 27 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / Prune caches (push) Waiting to run
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / vcpkg baseline (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Fedora 45 release (push) Blocked by required conditions
Build Desktop / Fedora 45 debug (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 sanitize (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 27 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / Prune caches (push) Waiting to run
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
Add --set key=value to override a section-qualified scalar configuration key for a single run and --print-config to print the effective configuration, with secrets redacted. SettingsCache owns the override map, so reads see the override without rewriting the ini file, and rebuilds the disallowed-name regexps when users/disallowedregexp is overridden. Bare keys and array-scoped keys are rejected because array loops read them relative to the active group, where a full-key override would either be ignored or rewrite every entry. Cover the ini, default, override, override-only-key, regexp-rebuild, secret-redaction, and parse paths with a server-labelled gtest.
This commit is contained in:
parent
ccda73fe5c
commit
214b284814
5 changed files with 340 additions and 0 deletions
|
|
@ -40,6 +40,7 @@
|
|||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QThread>
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
|
|
@ -124,6 +125,37 @@ void myMessageOutput2(QtMsgType /*type*/, const QMessageLogContext &, const QStr
|
|||
std::cerr << msg.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
void printEffectiveConfig(const SettingsCache &settings)
|
||||
{
|
||||
for (const QString &key : settings.effectiveKeys()) {
|
||||
const QString rendered =
|
||||
SettingsCache::isSecretKey(key) ? QStringLiteral("<redacted>") : settings.value(key).toString();
|
||||
std::cout << key.toStdString() << '=' << rendered.toStdString() << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
bool applyConfigOverrides(SettingsCache &settings, const QStringList &values)
|
||||
{
|
||||
for (const QString &entry : values) {
|
||||
QString key;
|
||||
QVariant value;
|
||||
if (!SettingsCache::parseOverride(entry, key, value)) {
|
||||
qCritical() << "Invalid --set value; expected a scalar key=value:" << entry;
|
||||
return false;
|
||||
}
|
||||
|
||||
settings.setOverride(key, value);
|
||||
}
|
||||
|
||||
if (!values.isEmpty()) {
|
||||
settings.rebuildDisallowedRegExps();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
|
@ -147,6 +179,17 @@ int main(int argc, char *argv[])
|
|||
QCommandLineOption configPathOpt("config", "Read server configuration from <file>", "file", "");
|
||||
parser.addOption(configPathOpt);
|
||||
|
||||
QCommandLineOption setConfigOpt(
|
||||
"set",
|
||||
"Override a section-qualified scalar configuration value for this run (key=value), such as "
|
||||
"server/port. May be repeated; bare keys and array keys such as rooms/roomlist/1/name are "
|
||||
"rejected; never writes the config file.",
|
||||
"key=value");
|
||||
parser.addOption(setConfigOpt);
|
||||
|
||||
QCommandLineOption printConfigOpt("print-config", "Print the effective configuration and exit");
|
||||
parser.addOption(printConfigOpt);
|
||||
|
||||
parser.process(app);
|
||||
|
||||
bool testRandom = parser.isSet(testRandomOpt);
|
||||
|
|
@ -165,6 +208,15 @@ int main(int argc, char *argv[])
|
|||
qWarning() << "Using configuration file: " << configPath;
|
||||
settingsCache = new SettingsCache(configPath);
|
||||
|
||||
if (!applyConfigOverrides(*settingsCache, parser.values(setConfigOpt))) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (parser.isSet(printConfigOpt)) {
|
||||
printEffectiveConfig(*settingsCache);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
loggerThread = new QThread;
|
||||
loggerThread->setObjectName("logger");
|
||||
logger = new ServerLogger(logToConsole, settingsCache->value("server/writelog", 1).toBool(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue