diff options
| author | Stefan Boberg <[email protected]> | 2025-10-15 09:51:52 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-10-15 09:51:52 +0200 |
| commit | e747932819e2a64a1396cfbc3422a9b61c9470dc (patch) | |
| tree | 1db1d13cf7fe873d71128a7879d269174f8eaf16 /src/zenserver/storage/storageconfig.cpp | |
| parent | refactor builds cmd part3 (#573) (diff) | |
| download | zen-e747932819e2a64a1396cfbc3422a9b61c9470dc.tar.xz zen-e747932819e2a64a1396cfbc3422a9b61c9470dc.zip | |
restructured zenserver configuration (#575)
this breaks out the configuration logic to allow multiple applications to share common configuration and initialization logic whilst customizing chosen aspects of the process
Diffstat (limited to 'src/zenserver/storage/storageconfig.cpp')
| -rw-r--r-- | src/zenserver/storage/storageconfig.cpp | 86 |
1 files changed, 41 insertions, 45 deletions
diff --git a/src/zenserver/storage/storageconfig.cpp b/src/zenserver/storage/storageconfig.cpp index 86bb09c21..61844140e 100644 --- a/src/zenserver/storage/storageconfig.cpp +++ b/src/zenserver/storage/storageconfig.cpp @@ -18,8 +18,10 @@ ZEN_THIRD_PARTY_INCLUDES_END namespace zen { void -ValidateOptions(ZenStorageServerOptions& ServerOptions) +ZenStorageServerConfigurator::ValidateOptions() { + auto& ServerOptions = m_ServerOptions; + if (ServerOptions.EncryptionKey.empty() == false) { const auto Key = AesKey256Bit::FromString(ServerOptions.EncryptionKey); @@ -363,18 +365,11 @@ MakeOption(std::vector<std::pair<std::string, ZenStructuredCacheBucketConfig>>& }; void -ParseConfigFile(const std::filesystem::path& Path, - ZenStorageServerOptions& ServerOptions, - const cxxopts::ParseResult& CmdLineResult, - std::string_view OutputConfigFile) +ZenStorageServerConfigurator::AddConfigOptions(LuaConfig::Options& LuaOptions) { - ZEN_TRACE_CPU("ParseConfigFile"); - using namespace std::literals; - LuaConfig::Options LuaOptions; - - AddServerConfigOptions(LuaOptions, ServerOptions); + auto& ServerOptions = m_ServerOptions; ////// server LuaOptions.AddOption("server.pluginsconfigfile"sv, ServerOptions.PluginsConfigFile, "plugins-config"sv); @@ -507,36 +502,50 @@ ParseConfigFile(const std::filesystem::path& Path, LuaOptions.AddOption("workspaces.allowconfigchanges"sv, ServerOptions.WorksSpacesConfig.AllowConfigurationChanges, "workspaces-allow-changes"sv); +} - LuaOptions.Parse(Path, CmdLineResult); +void +ZenStorageServerConfigurator::OnConfigFileParsed(LuaConfig::Options& LuaOptions) +{ + using namespace std::literals; // These have special command line processing so we make sure we export them if they were configured on command line - if (!ServerOptions.AuthConfig.OpenIdProviders.empty()) + + if (!m_ServerOptions.AuthConfig.OpenIdProviders.empty()) { LuaOptions.Touch("security.openidproviders"sv); } - if (!ServerOptions.ObjectStoreConfig.Buckets.empty()) + if (!m_ServerOptions.ObjectStoreConfig.Buckets.empty()) { LuaOptions.Touch("server.objectstore.buckets"sv); } - if (!ServerOptions.StructuredCacheConfig.PerBucketConfigs.empty()) + if (!m_ServerOptions.StructuredCacheConfig.PerBucketConfigs.empty()) { LuaOptions.Touch("cache.buckets"sv); } - if (!OutputConfigFile.empty()) + // Also parse plugins config file + + if (!m_ServerOptions.PluginsConfigFile.empty()) { - std::filesystem::path WritePath(MakeSafeAbsolutePath(OutputConfigFile)); - ExtendableStringBuilder<512> ConfigStringBuilder; - LuaOptions.Print(ConfigStringBuilder, CmdLineResult); - BasicFile Output; - Output.Open(WritePath, BasicFile::Mode::kTruncate); - Output.Write(ConfigStringBuilder.Data(), ConfigStringBuilder.Size(), 0); + ParsePluginsConfigFile(m_ServerOptions.PluginsConfigFile); } } void -ParsePluginsConfigFile(const std::filesystem::path& Path, ZenStorageServerOptions& ServerOptions, int BasePort) +ZenStorageServerConfigurator::AddCliOptions(cxxopts::Options& options) +{ + m_StorageOptions.AddCliOptions(options, m_ServerOptions); +} + +void +ZenStorageServerConfigurator::ApplyOptions(cxxopts::Options& options) +{ + m_StorageOptions.ApplyOptions(options, m_ServerOptions); +} + +void +ZenStorageServerConfigurator::ParsePluginsConfigFile(const std::filesystem::path& Path) { using namespace std::literals; @@ -590,19 +599,16 @@ ParsePluginsConfigFile(const std::filesystem::path& Path, ZenStorageServerOption // add a default base port in case if json config didn't provide one if (bNeedsPort) { - Config.PluginOptions.push_back({"port", std::to_string(BasePort)}); + Config.PluginOptions.push_back({"port", std::to_string(m_ServerOptions.BasePort)}); } - ServerOptions.HttpServerConfig.PluginConfigs.push_back(Config); + m_ServerOptions.HttpServerConfig.PluginConfigs.push_back(Config); } } void -ZenStorageServerCmdLineOptions::AddCliOptions(cxxopts::Options& options, ZenStorageServerOptions& ServerOptions) +ZenStorageServerCmdLineOptions::AddCliOptions(cxxopts::Options& options, ZenStorageServerConfig& ServerOptions) { - options.add_options()("snapshot-dir", - "Specify a snapshot of server state to mirror into the persistence root at startup", - cxxopts::value<std::string>(BaseSnapshotDir)); options.add_options()("plugins-config", "Path to plugins config file", cxxopts::value<std::string>(PluginsConfigFile)); options.add_options()("scrub", "Validate state at startup", @@ -618,7 +624,7 @@ ZenStorageServerCmdLineOptions::AddCliOptions(cxxopts::Options& options, ZenStor } void -ZenStorageServerCmdLineOptions::AddSecurityOptions(cxxopts::Options& options, ZenStorageServerOptions& ServerOptions) +ZenStorageServerCmdLineOptions::AddSecurityOptions(cxxopts::Options& options, ZenStorageServerConfig& ServerOptions) { options.add_option("security", "", @@ -646,7 +652,7 @@ ZenStorageServerCmdLineOptions::AddSecurityOptions(cxxopts::Options& options, Ze } void -ZenStorageServerCmdLineOptions::AddCacheOptions(cxxopts::Options& options, ZenStorageServerOptions& ServerOptions) +ZenStorageServerCmdLineOptions::AddCacheOptions(cxxopts::Options& options, ZenStorageServerConfig& ServerOptions) { options.add_option("cache", "", @@ -831,7 +837,7 @@ ZenStorageServerCmdLineOptions::AddCacheOptions(cxxopts::Options& options, ZenSt } void -ZenStorageServerCmdLineOptions::AddGcOptions(cxxopts::Options& options, ZenStorageServerOptions& ServerOptions) +ZenStorageServerCmdLineOptions::AddGcOptions(cxxopts::Options& options, ZenStorageServerConfig& ServerOptions) { options.add_option("gc", "", @@ -970,7 +976,7 @@ ZenStorageServerCmdLineOptions::AddGcOptions(cxxopts::Options& options, ZenStora } void -ZenStorageServerCmdLineOptions::AddObjectStoreOptions(cxxopts::Options& options, ZenStorageServerOptions& ServerOptions) +ZenStorageServerCmdLineOptions::AddObjectStoreOptions(cxxopts::Options& options, ZenStorageServerConfig& ServerOptions) { options.add_option("objectstore", "", @@ -988,7 +994,7 @@ ZenStorageServerCmdLineOptions::AddObjectStoreOptions(cxxopts::Options& options, } void -ZenStorageServerCmdLineOptions::AddBuildStoreOptions(cxxopts::Options& options, ZenStorageServerOptions& ServerOptions) +ZenStorageServerCmdLineOptions::AddBuildStoreOptions(cxxopts::Options& options, ZenStorageServerConfig& ServerOptions) { options.add_option("buildstore", "", @@ -1005,7 +1011,7 @@ ZenStorageServerCmdLineOptions::AddBuildStoreOptions(cxxopts::Options& options, } void -ZenStorageServerCmdLineOptions::AddWorkspacesOptions(cxxopts::Options& options, ZenStorageServerOptions& ServerOptions) +ZenStorageServerCmdLineOptions::AddWorkspacesOptions(cxxopts::Options& options, ZenStorageServerConfig& ServerOptions) { options.add_option("workspaces", "", @@ -1023,21 +1029,11 @@ ZenStorageServerCmdLineOptions::AddWorkspacesOptions(cxxopts::Options& options, } void -ZenStorageServerCmdLineOptions::ApplyOptions(cxxopts::Options& options, ZenStorageServerOptions& ServerOptions) +ZenStorageServerCmdLineOptions::ApplyOptions(cxxopts::Options& options, ZenStorageServerConfig& ServerOptions) { - ServerOptions.BaseSnapshotDir = MakeSafeAbsolutePath(BaseSnapshotDir); ServerOptions.PluginsConfigFile = MakeSafeAbsolutePath(PluginsConfigFile); ServerOptions.UpstreamCacheConfig.CachePolicy = ParseUpstreamCachePolicy(UpstreamCachePolicyOptions); - if (!BaseSnapshotDir.empty()) - { - if (ServerOptions.DataDir.empty()) - throw OptionParseException("'--snapshot-dir' requires '--data-dir'", options.help()); - - if (!IsDir(ServerOptions.BaseSnapshotDir)) - throw std::runtime_error(fmt::format("'--snapshot-dir' ('{}') must be a directory", ServerOptions.BaseSnapshotDir)); - } - if (OpenIdProviderUrl.empty() == false) { if (OpenIdClientId.empty()) |