diff options
Diffstat (limited to 'zenserver/config.cpp')
| -rw-r--r-- | zenserver/config.cpp | 130 |
1 files changed, 122 insertions, 8 deletions
diff --git a/zenserver/config.cpp b/zenserver/config.cpp index 6e8b48703..8fe9f72f2 100644 --- a/zenserver/config.cpp +++ b/zenserver/config.cpp @@ -97,10 +97,74 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z options.add_option("cache", "", - "enable-upstream-cache", - "Whether upstream caching is enabled", - cxxopts::value<bool>(ServiceConfig.UpstreamCacheEnabled)->default_value("false"), + "upstream-jupiter-url", + "URL to a Jupiter instance", + cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.Url)->default_value(""), ""); + + options.add_option("cache", + "", + "upstream-jupiter-oauth-url", + "URL to the OAuth provier", + cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthProvider)->default_value(""), + ""); + + options.add_option("cache", + "", + "upstream-jupiter-oauth-clientid", + "The OAuth client ID", + cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthClientId)->default_value(""), + ""); + + options.add_option("cache", + "", + "upstream-jupiter-oauth-clientsecret", + "The OAuth client secret", + cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthClientSecret)->default_value(""), + ""); + + options.add_option("cache", + "", + "upstream-jupiter-namespace", + "The Common Blob Store API namespace", + cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.Namespace)->default_value(""), + ""); + + options.add_option("cache", + "", + "upstream-jupiter-namespace-ddc", + "The lecacy DDC namespace", + cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.DdcNamespace)->default_value(""), + ""); + + options.add_option("cache", + "", + "upstream-jupiter-dev", + "Enable Jupiter upstream caching using development settings", + cxxopts::value<bool>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.UseDevelopmentSettings)->default_value("false"), + ""); + + options.add_option("cache", + "", + "upstream-zen-url", + "URL to a remote Zen server instance", + cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.ZenConfig.Url)->default_value(""), + ""); + + options.add_option("cache", + "", + "upstream-enabled", + "Whether upstream caching is disabled", + cxxopts::value<bool>(ServiceConfig.UpstreamCacheConfig.Enabled)->default_value("true"), + ""); + + options.add_option("cache", + "", + "upstream-thread-count", + "Number of threads used for upstream procsssing", + cxxopts::value<int>(ServiceConfig.UpstreamCacheConfig.UpstreamThreadCount)->default_value("4"), + ""); + try { auto result = options.parse(argc, argv); @@ -171,10 +235,60 @@ ParseServiceConfig(const std::filesystem::path& DataRoot, ZenServiceConfig& Serv throw std::exception("fatal zen global config script ({}) failure: {}"_format(ConfigScript, e.what()).c_str()); } - ServiceConfig.LegacyCacheEnabled = lua["legacycache"]["enable"].get_or(ServiceConfig.LegacyCacheEnabled); - const std::string path = lua["legacycache"]["readpath"].get_or(std::string()); - ServiceConfig.StructuredCacheEnabled = lua["structuredcache"]["enable"].get_or(ServiceConfig.StructuredCacheEnabled); - ServiceConfig.MeshEnabled = lua["mesh"]["enable"].get_or(ServiceConfig.MeshEnabled); - ServiceConfig.UpstreamCacheEnabled = lua["structuredcache"]["upstream"]["enable"].get_or(ServiceConfig.UpstreamCacheEnabled); + ServiceConfig.LegacyCacheEnabled = lua["legacycache"]["enable"].get_or(ServiceConfig.LegacyCacheEnabled); + const std::string path = lua["legacycache"]["readpath"].get_or(std::string()); + ServiceConfig.MeshEnabled = lua["mesh"]["enable"].get_or(ServiceConfig.MeshEnabled); + + auto UpdateStringValueFromConfig = [](const sol::table& Table, std::string_view Key, std::string& OutValue) { + // Update the specified config value unless it has been set, i.e. from command line + if (auto MaybeValue = Table.get<sol::optional<std::string>>(Key); MaybeValue.has_value() && OutValue.empty()) + { + OutValue = MaybeValue.value(); + } + }; + + if (sol::optional<sol::table> StructuredCacheConfig = lua["structuredcache"]) + { + ServiceConfig.StructuredCacheEnabled = StructuredCacheConfig->get_or("enable", ServiceConfig.StructuredCacheEnabled); + + if (auto UpstreamConfig = StructuredCacheConfig->get<sol::optional<sol::table>>("upstream")) + { + ServiceConfig.UpstreamCacheConfig.Enabled = UpstreamConfig->get_or("enable", ServiceConfig.UpstreamCacheConfig.Enabled); + ServiceConfig.UpstreamCacheConfig.UpstreamThreadCount = UpstreamConfig->get_or("upstreamthreadcount", 4); + + if (auto JupiterConfig = UpstreamConfig->get<sol::optional<sol::table>>("jupiter")) + { + UpdateStringValueFromConfig(JupiterConfig.value(), + std::string_view("url"), + ServiceConfig.UpstreamCacheConfig.JupiterConfig.Url); + UpdateStringValueFromConfig(JupiterConfig.value(), + std::string_view("oauthprovider"), + ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthProvider); + UpdateStringValueFromConfig(JupiterConfig.value(), + std::string_view("oauthclientid"), + ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthClientId); + UpdateStringValueFromConfig(JupiterConfig.value(), + std::string_view("oauthclientsecret"), + ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthClientSecret); + UpdateStringValueFromConfig(JupiterConfig.value(), + std::string_view("namespace"), + ServiceConfig.UpstreamCacheConfig.JupiterConfig.Namespace); + UpdateStringValueFromConfig(JupiterConfig.value(), + std::string_view("ddcnamespace"), + ServiceConfig.UpstreamCacheConfig.JupiterConfig.DdcNamespace); + + ServiceConfig.UpstreamCacheConfig.JupiterConfig.UseDevelopmentSettings = + JupiterConfig->get_or("usedevelopmentsettings", + ServiceConfig.UpstreamCacheConfig.JupiterConfig.UseDevelopmentSettings); + }; + + if (auto ZenConfig = UpstreamConfig->get<sol::optional<sol::table>>("zen")) + { + UpdateStringValueFromConfig(ZenConfig.value(), + std::string_view("url"), + ServiceConfig.UpstreamCacheConfig.ZenConfig.Url); + } + } + } } } |