diff --git a/contract-tests/data-model/include/data_model/data_model.hpp b/contract-tests/data-model/include/data_model/data_model.hpp index a752ccd7d..12ca2e28d 100644 --- a/contract-tests/data-model/include/data_model/data_model.hpp +++ b/contract-tests/data-model/include/data_model/data_model.hpp @@ -5,41 +5,30 @@ #include #include "nlohmann/json.hpp" -namespace nlohmann -{ - template - struct adl_serializer> - { - static void to_json(json& j, std::optional const& opt) - { - if (opt == std::nullopt) - { - j = nullptr; - } - else - { - j = *opt; // this will call adl_serializer::to_json which will - // find the free function to_json in T's namespace! - } +namespace nlohmann { +template +struct adl_serializer> { + static void to_json(json& j, std::optional const& opt) { + if (opt == std::nullopt) { + j = nullptr; + } else { + j = *opt; // this will call adl_serializer::to_json which will + // find the free function to_json in T's namespace! } - - static void from_json(json const& j, std::optional& opt) - { - if (j.is_null()) - { - opt = std::nullopt; - } - else - { - opt = j.get(); // same as above, but with - // adl_serializer::from_json - } + } + + static void from_json(json const& j, std::optional& opt) { + if (j.is_null()) { + opt = std::nullopt; + } else { + opt = j.get(); // same as above, but with + // adl_serializer::from_json } - }; -} // namespace nlohmann + } +}; +} // namespace nlohmann -struct ConfigTLSParams -{ +struct ConfigTLSParams { std::optional skipVerifyPeer; std::optional customCAFile; }; @@ -48,8 +37,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigTLSParams, skipVerifyPeer, customCAFile); -struct ConfigStreamingParams -{ +struct ConfigStreamingParams { std::optional baseUri; std::optional initialRetryDelayMs; std::optional filter; @@ -57,10 +45,10 @@ struct ConfigStreamingParams NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigStreamingParams, baseUri, - initialRetryDelayMs, filter); + initialRetryDelayMs, + filter); -struct ConfigPollingParams -{ +struct ConfigPollingParams { std::optional baseUri; std::optional pollIntervalMs; std::optional filter; @@ -68,10 +56,10 @@ struct ConfigPollingParams NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigPollingParams, baseUri, - pollIntervalMs, filter); + pollIntervalMs, + filter); -struct ConfigEventParams -{ +struct ConfigEventParams { std::optional baseUri; std::optional capacity; std::optional enableDiagnostics; @@ -88,8 +76,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigEventParams, globalPrivateAttributes, flushIntervalMs); -struct ConfigServiceEndpointsParams -{ +struct ConfigServiceEndpointsParams { std::optional streaming; std::optional polling; std::optional events; @@ -100,8 +87,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigServiceEndpointsParams, polling, events); -struct ConfigClientSideParams -{ +struct ConfigClientSideParams { nlohmann::json initialContext; std::optional evaluationReasons; std::optional useReport; @@ -112,8 +98,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigClientSideParams, evaluationReasons, useReport); -struct ConfigTags -{ +struct ConfigTags { std::optional applicationId; std::optional applicationVersion; }; @@ -122,8 +107,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigTags, applicationId, applicationVersion); -struct ConfigParams -{ +struct ConfigParams { std::string credential; std::optional startWaitTimeMs; std::optional initCanFail; @@ -148,8 +132,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ConfigParams, tags, tls); -struct ContextSingleParams -{ +struct ContextSingleParams { std::optional kind; std::string key; std::optional name; @@ -161,8 +144,7 @@ struct ContextSingleParams // These are defined manually because of the 'private' field, which is a // reserved keyword in C++. inline void to_json(nlohmann::json& nlohmann_json_j, - ContextSingleParams const& nlohmann_json_t) -{ + ContextSingleParams const& nlohmann_json_t) { nlohmann_json_j["kind"] = nlohmann_json_t.kind; nlohmann_json_j["key"] = nlohmann_json_t.key; nlohmann_json_j["name"] = nlohmann_json_t.name; @@ -172,8 +154,7 @@ inline void to_json(nlohmann::json& nlohmann_json_j, } inline void from_json(nlohmann::json const& nlohmann_json_j, - ContextSingleParams& nlohmann_json_t) -{ + ContextSingleParams& nlohmann_json_t) { ContextSingleParams nlohmann_json_default_obj; nlohmann_json_t.kind = nlohmann_json_j.value("kind", nlohmann_json_default_obj.kind); @@ -189,8 +170,7 @@ inline void from_json(nlohmann::json const& nlohmann_json_j, nlohmann_json_j.value("custom", nlohmann_json_default_obj.custom); } -struct ContextBuildParams -{ +struct ContextBuildParams { std::optional single; std::optional> multi; }; @@ -199,23 +179,20 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ContextBuildParams, single, multi); -struct ContextConvertParams -{ +struct ContextConvertParams { std::string input; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ContextConvertParams, input); -struct ContextResponse -{ +struct ContextResponse { std::optional output; std::optional error; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ContextResponse, output, error); -struct CreateInstanceParams -{ +struct CreateInstanceParams { ConfigParams configuration; std::string tag; }; @@ -228,14 +205,13 @@ enum class ValueType { Bool = 1, Int, Double, String, Any, Unspecified }; NLOHMANN_JSON_SERIALIZE_ENUM(ValueType, {{ValueType::Bool, "bool"}, - {ValueType::Int, "int"}, - {ValueType::Double, "double"}, - {ValueType::String, "string"}, - {ValueType::Any, "any"}, - {ValueType::Unspecified, ""}}) - -struct EvaluateFlagParams -{ + {ValueType::Int, "int"}, + {ValueType::Double, "double"}, + {ValueType::String, "string"}, + {ValueType::Any, "any"}, + {ValueType::Unspecified, ""}}) + +struct EvaluateFlagParams { std::string flagKey; std::optional context; ValueType valueType; @@ -251,8 +227,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(EvaluateFlagParams, defaultValue, detail); -struct EvaluateFlagResponse -{ +struct EvaluateFlagResponse { nlohmann::json value; std::optional variationIndex; std::optional reason; @@ -263,8 +238,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(EvaluateFlagResponse, variationIndex, reason); -struct EvaluateAllFlagParams -{ +struct EvaluateAllFlagParams { std::optional context; std::optional withReasons; std::optional clientSideOnly; @@ -277,16 +251,14 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(EvaluateAllFlagParams, clientSideOnly, detailsOnlyForTrackedFlags); -struct EvaluateAllFlagsResponse -{ +struct EvaluateAllFlagsResponse { nlohmann::json state; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(EvaluateAllFlagsResponse, state); -struct CustomEventParams -{ +struct CustomEventParams { std::string eventKey; std::optional context; std::optional data; @@ -301,15 +273,13 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(CustomEventParams, omitNullData, metricValue); -struct IdentifyEventParams -{ +struct IdentifyEventParams { nlohmann::json context; }; NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(IdentifyEventParams, context); -enum class Command -{ +enum class Command { Unknown = -1, EvaluateFlag, EvaluateAllFlags, @@ -322,16 +292,15 @@ enum class Command NLOHMANN_JSON_SERIALIZE_ENUM(Command, {{Command::Unknown, nullptr}, - {Command::EvaluateFlag, "evaluate"}, - {Command::EvaluateAllFlags, "evaluateAll"}, - {Command::IdentifyEvent, "identifyEvent"}, - {Command::CustomEvent, "customEvent"}, - {Command::FlushEvents, "flushEvents"}, - {Command::ContextBuild, "contextBuild"}, - {Command::ContextConvert, "contextConvert"}}); - -struct CommandParams -{ + {Command::EvaluateFlag, "evaluate"}, + {Command::EvaluateAllFlags, "evaluateAll"}, + {Command::IdentifyEvent, "identifyEvent"}, + {Command::CustomEvent, "customEvent"}, + {Command::FlushEvents, "flushEvents"}, + {Command::ContextBuild, "contextBuild"}, + {Command::ContextConvert, "contextConvert"}}); + +struct CommandParams { Command command; std::optional evaluate; std::optional evaluateAll; diff --git a/contract-tests/server-contract-tests/src/entity_manager.cpp b/contract-tests/server-contract-tests/src/entity_manager.cpp index c92093d0e..71e2d479e 100644 --- a/contract-tests/server-contract-tests/src/entity_manager.cpp +++ b/contract-tests/server-contract-tests/src/entity_manager.cpp @@ -11,8 +11,7 @@ using namespace launchdarkly::server_side; EntityManager::EntityManager(boost::asio::any_io_executor executor, launchdarkly::Logger& logger) - : counter_{0}, executor_{std::move(executor)}, logger_{logger} { -} + : counter_{0}, executor_{std::move(executor)}, logger_{logger} {} std::optional EntityManager::create(ConfigParams const& in) { std::string id = std::to_string(counter_++); @@ -32,9 +31,9 @@ std::optional EntityManager::create(ConfigParams const& in) { auto& endpoints = config_builder.ServiceEndpoints() - .EventsBaseUrl(default_endpoints.EventsBaseUrl()) - .PollingBaseUrl(default_endpoints.PollingBaseUrl()) - .StreamingBaseUrl(default_endpoints.StreamingBaseUrl()); + .EventsBaseUrl(default_endpoints.EventsBaseUrl()) + .PollingBaseUrl(default_endpoints.PollingBaseUrl()) + .StreamingBaseUrl(default_endpoints.StreamingBaseUrl()); if (in.serviceEndpoints) { if (in.serviceEndpoints->streaming) { diff --git a/libs/common/include/launchdarkly/config/shared/builders/data_source_builder.hpp b/libs/common/include/launchdarkly/config/shared/builders/data_source_builder.hpp index 08e262083..9fffa74ce 100644 --- a/libs/common/include/launchdarkly/config/shared/builders/data_source_builder.hpp +++ b/libs/common/include/launchdarkly/config/shared/builders/data_source_builder.hpp @@ -5,8 +5,8 @@ #include #include -#include #include +#include namespace launchdarkly::config::shared::builders { /** @@ -17,19 +17,17 @@ template class DataSourceBuilder; template -struct is_server_sdk : std::false_type { -}; +struct is_server_sdk : std::false_type {}; template <> -struct is_server_sdk : std::true_type { -}; +struct is_server_sdk : std::true_type {}; /** * Builds a configuration for a streaming data source. */ template class StreamingBuilder { -public: + public: StreamingBuilder(); /** @@ -77,7 +75,7 @@ class StreamingBuilder { */ [[nodiscard]] built::StreamingConfig Build() const; -private: + private: built::StreamingConfig config_; }; @@ -86,7 +84,7 @@ class StreamingBuilder { */ template class PollingBuilder { -public: + public: PollingBuilder(); /** @@ -97,23 +95,23 @@ class PollingBuilder { PollingBuilder& PollInterval(std::chrono::seconds poll_interval); /** - * Sets the filter key for the polling connection. - * - * By default, the SDK is able to evaluate all flags in an environment. - * - * If this is undesirable - for example, because the environment contains - * thousands of flags, but this application only needs to evaluate - * a smaller, known subset - then a filter may be setup in LaunchDarkly, - * and the filter's key specified here. - * - * Evaluations for flags that aren't part of the filtered environment will - * return default values. - * - * @param filter_key The filter key. If the key is malformed or nonexistent, - * then a full LaunchDarkly environment will be fetched. In the case of a - * malformed key, the SDK will additionally log a runtime error. - * @return Reference to this builder. - */ + * Sets the filter key for the polling connection. + * + * By default, the SDK is able to evaluate all flags in an environment. + * + * If this is undesirable - for example, because the environment contains + * thousands of flags, but this application only needs to evaluate + * a smaller, known subset - then a filter may be setup in LaunchDarkly, + * and the filter's key specified here. + * + * Evaluations for flags that aren't part of the filtered environment will + * return default values. + * + * @param filter_key The filter key. If the key is malformed or nonexistent, + * then a full LaunchDarkly environment will be fetched. In the case of a + * malformed key, the SDK will additionally log a runtime error. + * @return Reference to this builder. + */ template std::enable_if_t::value, PollingBuilder&> Filter( std::string filter_key) { @@ -127,14 +125,13 @@ class PollingBuilder { */ [[nodiscard]] built::PollingConfig Build() const; -private: + private: built::PollingConfig config_; }; - template <> class DataSourceBuilder { -public: + public: using Streaming = StreamingBuilder; using Polling = PollingBuilder; @@ -199,9 +196,9 @@ class DataSourceBuilder { */ [[nodiscard]] built::DataSourceConfig Build() const; -private: + private: std::variant method_; bool with_reasons_; bool use_report_; }; -} // namespace launchdarkly::config::shared::builders +} // namespace launchdarkly::config::shared::builders diff --git a/libs/common/include/launchdarkly/config/shared/built/data_source_config.hpp b/libs/common/include/launchdarkly/config/shared/built/data_source_config.hpp index 45742e3c4..035e29c1d 100644 --- a/libs/common/include/launchdarkly/config/shared/built/data_source_config.hpp +++ b/libs/common/include/launchdarkly/config/shared/built/data_source_config.hpp @@ -27,8 +27,8 @@ struct StreamingConfig { inline bool operator==(StreamingConfig const& lhs, StreamingConfig const& rhs) { return lhs.initial_reconnect_delay == rhs.initial_reconnect_delay && - lhs.streaming_path == rhs.streaming_path && lhs.filter_key == rhs. - filter_key; + lhs.streaming_path == rhs.streaming_path && + lhs.filter_key == rhs.filter_key; } template @@ -62,6 +62,5 @@ struct DataSourceConfig { }; template <> -struct DataSourceConfig { -}; -} // namespace launchdarkly::config::shared::built +struct DataSourceConfig {}; +} // namespace launchdarkly::config::shared::built diff --git a/libs/common/src/config/data_source_builder.cpp b/libs/common/src/config/data_source_builder.cpp index f5252c061..e19a9417e 100644 --- a/libs/common/src/config/data_source_builder.cpp +++ b/libs/common/src/config/data_source_builder.cpp @@ -1,15 +1,15 @@ #include namespace launchdarkly::config::shared::builders { + template -struct MethodVisitor { -}; +struct MethodVisitor {}; template <> struct MethodVisitor { using SDK = ClientSDK; using Result = - std::variant, built::PollingConfig>; + std::variant, built::PollingConfig>; Result operator()(StreamingBuilder const& streaming) const { return streaming.Build(); @@ -22,8 +22,7 @@ struct MethodVisitor { template StreamingBuilder::StreamingBuilder() - : config_(Defaults::StreamingConfig()) { -} + : config_(Defaults::StreamingConfig()) {} template StreamingBuilder& StreamingBuilder::InitialReconnectDelay( @@ -39,8 +38,7 @@ built::StreamingConfig StreamingBuilder::Build() const { template PollingBuilder::PollingBuilder() - : config_(Defaults::PollingConfig()) { -} + : config_(Defaults::PollingConfig()) {} template PollingBuilder& PollingBuilder::PollInterval( @@ -55,8 +53,7 @@ built::PollingConfig PollingBuilder::Build() const { } DataSourceBuilder::DataSourceBuilder() - : with_reasons_(false), use_report_(false), method_(Streaming()) { -} + : with_reasons_(false), use_report_(false), method_(Streaming()) {} DataSourceBuilder& DataSourceBuilder::WithReasons( bool value) { @@ -92,4 +89,5 @@ template class PollingBuilder; template class StreamingBuilder; template class StreamingBuilder; -} // namespace launchdarkly::config::shared::builders + +} // namespace launchdarkly::config::shared::builders diff --git a/libs/common/tests/data_source_builder_test.cpp b/libs/common/tests/data_source_builder_test.cpp index 6e66d954d..8f16edc94 100644 --- a/libs/common/tests/data_source_builder_test.cpp +++ b/libs/common/tests/data_source_builder_test.cpp @@ -11,37 +11,37 @@ using namespace launchdarkly; TEST(DataSourceBuilderTests, CanCreateStreamingClientConfig) { auto client_config = client_side::DataSourceBuilder() - .WithReasons(true) - .UseReport(true) - .Method(client_side::DataSourceBuilder::Streaming() - .InitialReconnectDelay(std::chrono::milliseconds{1500})) - .Build(); + .WithReasons(true) + .UseReport(true) + .Method(client_side::DataSourceBuilder::Streaming() + .InitialReconnectDelay(std::chrono::milliseconds{1500})) + .Build(); EXPECT_TRUE(client_config.use_report); EXPECT_TRUE(client_config.with_reasons); EXPECT_EQ( std::chrono::milliseconds{1500}, std::get< - config::shared::built::StreamingConfig>( + config::shared::built::StreamingConfig>( client_config.method) - .initial_reconnect_delay); + .initial_reconnect_delay); } TEST(DataSourceBuilderTests, CanCreatePollingClientConfig) { auto client_config = client_side::DataSourceBuilder() - .WithReasons(false) - .UseReport(false) - .Method(client_side::DataSourceBuilder::Polling().PollInterval( - std::chrono::seconds{88000})) - .Build(); + .WithReasons(false) + .UseReport(false) + .Method(client_side::DataSourceBuilder::Polling().PollInterval( + std::chrono::seconds{88000})) + .Build(); EXPECT_FALSE(client_config.use_report); EXPECT_FALSE(client_config.with_reasons); EXPECT_EQ( std::chrono::seconds{88000}, std::get< - config::shared::built::PollingConfig>( + config::shared::built::PollingConfig>( client_config.method) - .poll_interval); + .poll_interval); } diff --git a/libs/server-sdk/include/launchdarkly/server_side/bindings/c/config/builder.h b/libs/server-sdk/include/launchdarkly/server_side/bindings/c/config/builder.h index 6f45c963c..9ac1a8cf1 100644 --- a/libs/server-sdk/include/launchdarkly/server_side/bindings/c/config/builder.h +++ b/libs/server-sdk/include/launchdarkly/server_side/bindings/c/config/builder.h @@ -21,10 +21,10 @@ extern "C" { typedef struct _LDServerConfigBuilder* LDServerConfigBuilder; typedef struct _LDServerDataSourceStreamBuilder* -LDServerDataSourceStreamBuilder; + LDServerDataSourceStreamBuilder; typedef struct _LDServerDataSourcePollBuilder* LDServerDataSourcePollBuilder; typedef struct _LDServerHttpPropertiesTlsBuilder* -LDServerHttpPropertiesTlsBuilder; + LDServerHttpPropertiesTlsBuilder; /** * Constructs a client-side config builder. @@ -64,8 +64,8 @@ LDServerConfigBuilder_ServiceEndpoints_EventsBaseURL(LDServerConfigBuilder b, */ LD_EXPORT(void) LDServerConfigBuilder_ServiceEndpoints_RelayProxyBaseURL( - LDServerConfigBuilder b, - char const* url); + LDServerConfigBuilder b, + char const* url); /** * Sets an identifier for the application. @@ -202,8 +202,8 @@ LDServerConfigBuilder_Events_PrivateAttribute(LDServerConfigBuilder b, */ LD_EXPORT(void) LDServerConfigBuilder_DataSystem_BackgroundSync_Streaming( - LDServerConfigBuilder b, - LDServerDataSourceStreamBuilder stream_builder); + LDServerConfigBuilder b, + LDServerDataSourceStreamBuilder stream_builder); /** * Configures the Background Sync data system with a Polling synchronizer. @@ -220,8 +220,8 @@ LDServerConfigBuilder_DataSystem_BackgroundSync_Streaming( */ LD_EXPORT(void) LDServerConfigBuilder_DataSystem_BackgroundSync_Polling( - LDServerConfigBuilder b, - LDServerDataSourcePollBuilder poll_builder); + LDServerConfigBuilder b, + LDServerDataSourcePollBuilder poll_builder); /** * Configures the Lazy Load data system. This method is mutually exclusive with @@ -236,8 +236,8 @@ LDServerConfigBuilder_DataSystem_BackgroundSync_Polling( */ LD_EXPORT(void) LDServerConfigBuilder_DataSystem_LazyLoad( - LDServerConfigBuilder b, - LDServerLazyLoadBuilder lazy_load_builder); + LDServerConfigBuilder b, + LDServerLazyLoadBuilder lazy_load_builder); /** * Specify if the SDK's data system should be enabled or not. @@ -275,31 +275,30 @@ LDServerDataSourceStreamBuilder_New(); */ LD_EXPORT(void) LDServerDataSourceStreamBuilder_InitialReconnectDelayMs( - LDServerDataSourceStreamBuilder b, - unsigned int milliseconds); - -/** -* Sets the filter key for the streaming connection. -* -* By default, the SDK is able to evaluate all flags in an environment. -* -* If this is undesirable - for example, because the environment contains -* thousands of flags, but this application only needs to evaluate -* a smaller, known subset - then a filter may be setup in LaunchDarkly, -* and the filter's key specified here. -* -* Evaluations for flags that aren't part of the filtered environment will -* return default values. -* -* @param b Streaming method builder. Must not be NULL. - * @param filter_key The filter key. Must not be NULL. If the key is malformed or - * nonexistent, then a full LaunchDarkly environment will be fetched. In the case - * of a malformed key, the SDK will additionally log a runtime error. -*/ -LD_EXPORT(void) -LDServerDataSourceStreamBuilder_Filter( - LDServerDataSourceStreamBuilder b, - char const* filter_key); + LDServerDataSourceStreamBuilder b, + unsigned int milliseconds); + +/** + * Sets the filter key for the streaming connection. + * + * By default, the SDK is able to evaluate all flags in an environment. + * + * If this is undesirable - for example, because the environment contains + * thousands of flags, but this application only needs to evaluate + * a smaller, known subset - then a filter may be setup in LaunchDarkly, + * and the filter's key specified here. + * + * Evaluations for flags that aren't part of the filtered environment will + * return default values. + * + * @param b Streaming method builder. Must not be NULL. + * @param filter_key The filter key. Must not be NULL. If the key is malformed + * or nonexistent, then a full LaunchDarkly environment will be fetched. In the + * case of a malformed key, the SDK will additionally log a runtime error. + */ +LD_EXPORT(void) +LDServerDataSourceStreamBuilder_Filter(LDServerDataSourceStreamBuilder b, + char const* filter_key); /** * Frees a Streaming method builder. Do not call if the builder was consumed by @@ -332,27 +331,26 @@ LDServerDataSourcePollBuilder_IntervalS(LDServerDataSourcePollBuilder b, unsigned int seconds); /** -* Sets the filter key for the polling connection. -* -* By default, the SDK is able to evaluate all flags in an environment. -* -* If this is undesirable - for example, because the environment contains -* thousands of flags, but this application only needs to evaluate -* a smaller, known subset - then a filter may be setup in LaunchDarkly, -* and the filter's key specified here. -* -* Evaluations for flags that aren't part of the filtered environment will -* return default values. -* -* @param b Polling method builder. Must not be NULL. -* @param filter_key The filter key. Must not be NULL. If the key is malformed or -* nonexistent, then a full LaunchDarkly environment will be fetched. In the case -* of a malformed key, the SDK will additionally log a runtime error. -*/ -LD_EXPORT(void) -LDServerDataSourcePollBuilder_Filter( - LDServerDataSourcePollBuilder b, - char const* filter_key); + * Sets the filter key for the polling connection. + * + * By default, the SDK is able to evaluate all flags in an environment. + * + * If this is undesirable - for example, because the environment contains + * thousands of flags, but this application only needs to evaluate + * a smaller, known subset - then a filter may be setup in LaunchDarkly, + * and the filter's key specified here. + * + * Evaluations for flags that aren't part of the filtered environment will + * return default values. + * + * @param b Polling method builder. Must not be NULL. + * @param filter_key The filter key. Must not be NULL. If the key is malformed + * or nonexistent, then a full LaunchDarkly environment will be fetched. In the + * case of a malformed key, the SDK will additionally log a runtime error. + */ +LD_EXPORT(void) +LDServerDataSourcePollBuilder_Filter(LDServerDataSourcePollBuilder b, + char const* filter_key); /** * Frees a Polling method builder. Do not call if the builder was consumed by @@ -383,8 +381,8 @@ LDServerConfigBuilder_HttpProperties_WrapperName(LDServerConfigBuilder b, */ LD_EXPORT(void) LDServerConfigBuilder_HttpProperties_WrapperVersion( - LDServerConfigBuilder b, - char const* wrapper_version); + LDServerConfigBuilder b, + char const* wrapper_version); /** * Set a custom header value. May be called more than once with additional @@ -406,8 +404,8 @@ LDServerConfigBuilder_HttpProperties_Header(LDServerConfigBuilder b, */ LD_EXPORT(void) LDServerConfigBuilder_HttpProperties_Tls( - LDServerConfigBuilder b, - LDServerHttpPropertiesTlsBuilder tls_builder); + LDServerConfigBuilder b, + LDServerHttpPropertiesTlsBuilder tls_builder); /** * Creates a new TLS options builder for the HttpProperties builder. @@ -441,8 +439,8 @@ LDServerHttpPropertiesTlsBuilder_Free(LDServerHttpPropertiesTlsBuilder b); */ LD_EXPORT(void) LDServerHttpPropertiesTlsBuilder_SkipVerifyPeer( - LDServerHttpPropertiesTlsBuilder b, - bool skip_verify_peer); + LDServerHttpPropertiesTlsBuilder b, + bool skip_verify_peer); /** * Configures TLS peer certificate verification to use a custom @@ -461,8 +459,8 @@ LDServerHttpPropertiesTlsBuilder_SkipVerifyPeer( */ LD_EXPORT(void) LDServerHttpPropertiesTlsBuilder_CustomCAFile( - LDServerHttpPropertiesTlsBuilder b, - char const* custom_ca_file); + LDServerHttpPropertiesTlsBuilder b, + char const* custom_ca_file); /** * Disables the default SDK logging. diff --git a/libs/server-sdk/src/bindings/c/builder.cpp b/libs/server-sdk/src/bindings/c/builder.cpp index 90a0f355b..655113720 100644 --- a/libs/server-sdk/src/bindings/c/builder.cpp +++ b/libs/server-sdk/src/bindings/c/builder.cpp @@ -76,7 +76,7 @@ LDServerConfigBuilder_Free(LDServerConfigBuilder builder) { LD_EXPORT(void) LDServerConfigBuilder_ServiceEndpoints_PollingBaseURL(LDServerConfigBuilder b, - char const* url) { + char const* url) { LD_ASSERT_NOT_NULL(b); LD_ASSERT_NOT_NULL(url); @@ -85,7 +85,7 @@ LDServerConfigBuilder_ServiceEndpoints_PollingBaseURL(LDServerConfigBuilder b, LD_EXPORT(void) LDServerConfigBuilder_ServiceEndpoints_StreamingBaseURL(LDServerConfigBuilder b, - char const* url) { + char const* url) { LD_ASSERT_NOT_NULL(b); LD_ASSERT_NOT_NULL(url); @@ -94,7 +94,7 @@ LDServerConfigBuilder_ServiceEndpoints_StreamingBaseURL(LDServerConfigBuilder b, LD_EXPORT(void) LDServerConfigBuilder_ServiceEndpoints_EventsBaseURL(LDServerConfigBuilder b, - char const* url) { + char const* url) { LD_ASSERT_NOT_NULL(b); LD_ASSERT_NOT_NULL(url); diff --git a/libs/server-sdk/src/data_systems/background_sync/sources/polling/polling_data_source.cpp b/libs/server-sdk/src/data_systems/background_sync/sources/polling/polling_data_source.cpp index 0f2b5c5cb..fad6beb94 100644 --- a/libs/server-sdk/src/data_systems/background_sync/sources/polling/polling_data_source.cpp +++ b/libs/server-sdk/src/data_systems/background_sync/sources/polling/polling_data_source.cpp @@ -23,7 +23,8 @@ static char const* const kCouldNotParseEndpoint = "Could not parse polling endpoint URL"; static char const* const kInvalidFilterKey = - "Invalid payload filter configured on polling data source, full environment " + "Invalid payload filter configured on polling data source, full " + "environment " "will be fetched.\nEnsure the filter key is not empty and was copied " "correctly from LaunchDarkly settings"; @@ -64,22 +65,22 @@ PollingDataSource::PollingDataSource( data_components::DataSourceStatusManager& status_manager, config::built::ServiceEndpoints const& endpoints, config::built::BackgroundSyncConfig::PollingConfig const& - data_source_config, + data_source_config, config::built::HttpProperties const& http_properties) : logger_(logger), status_manager_(status_manager), requester_(ioc, http_properties.Tls()), polling_interval_(data_source_config.poll_interval), - request_(MakeRequest(logger_, data_source_config, endpoints, - http_properties)), + request_( + MakeRequest(logger_, data_source_config, endpoints, http_properties)), timer_(ioc), sink_(nullptr) { if (polling_interval_ < data_source_config.min_polling_interval) { LD_LOG(logger_, LogLevel::kWarn) << "Polling interval too frequent, defaulting to " << std::chrono::duration_cast( - data_source_config.min_polling_interval) - .count() + data_source_config.min_polling_interval) + .count() << " seconds"; polling_interval_ = data_source_config.min_polling_interval; @@ -249,4 +250,4 @@ void PollingDataSource::ShutdownAsync(std::function completion) { boost::asio::post(timer_.get_executor(), completion); } } -} // namespace launchdarkly::server_side::data_systems +} // namespace launchdarkly::server_side::data_systems diff --git a/libs/server-sdk/tests/config_builder_test.cpp b/libs/server-sdk/tests/config_builder_test.cpp index 10b232dcd..7e4bb0631 100644 --- a/libs/server-sdk/tests/config_builder_test.cpp +++ b/libs/server-sdk/tests/config_builder_test.cpp @@ -11,15 +11,12 @@ using namespace launchdarkly; using namespace launchdarkly::server_side; using namespace launchdarkly::server_side::config; -class ConfigBuilderTest - : public ::testing:: - Test { +class ConfigBuilderTest : public ::testing::Test { // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) -protected: + protected: Logger logger; - ConfigBuilderTest() : logger(logging::NullLogger()) { - } + ConfigBuilderTest() : logger(logging::NullLogger()) {} }; TEST_F(ConfigBuilderTest, DefaultConstruction_Succeeds) { @@ -59,8 +56,7 @@ TEST_F(ConfigBuilderTest, CanSetStreamingPayloadFilterKey) { ConfigBuilder builder("sdk-123"); builder.DataSystem().Method( builders::DataSystemBuilder::BackgroundSync().Synchronizer( - builders::BackgroundSyncBuilder::Streaming().Filter( - "foo"))); + builders::BackgroundSyncBuilder::Streaming().Filter("foo"))); auto cfg = builder.Build(); @@ -85,8 +81,7 @@ TEST_F(ConfigBuilderTest, CanSetPollingPayloadFilterKey) { ConfigBuilder builder("sdk-123"); builder.DataSystem().Method( builders::DataSystemBuilder::BackgroundSync().Synchronizer( - builders::BackgroundSyncBuilder::Polling().Filter( - "foo"))); + builders::BackgroundSyncBuilder::Polling().Filter("foo"))); auto cfg = builder.Build(); @@ -112,8 +107,8 @@ TEST_F(ConfigBuilderTest, DefaultConstruction_HttpPropertyDefaultsAreUsed) { auto cfg = builder.Build(); ASSERT_EQ(cfg->HttpProperties(), ::launchdarkly::config::shared::Defaults< - launchdarkly::config::shared::ServerSDK>::Defaults:: - HttpProperties()); + launchdarkly::config::shared::ServerSDK>::Defaults:: + HttpProperties()); } TEST_F(ConfigBuilderTest, DefaultConstruction_ServiceEndpointDefaultsAreUsed) { @@ -121,8 +116,8 @@ TEST_F(ConfigBuilderTest, DefaultConstruction_ServiceEndpointDefaultsAreUsed) { auto cfg = builder.Build(); ASSERT_EQ(cfg->ServiceEndpoints(), ::launchdarkly::config::shared::Defaults< - launchdarkly::config::shared::ServerSDK>::Defaults:: - ServiceEndpoints()); + launchdarkly::config::shared::ServerSDK>::Defaults:: + ServiceEndpoints()); } TEST_F(ConfigBuilderTest, DefaultConstruction_EventDefaultsAreUsed) { @@ -130,7 +125,7 @@ TEST_F(ConfigBuilderTest, DefaultConstruction_EventDefaultsAreUsed) { auto cfg = builder.Build(); ASSERT_EQ(cfg->Events(), ::launchdarkly::config::shared::Defaults< - launchdarkly::config::shared::ServerSDK>::Defaults::Events()); + launchdarkly::config::shared::ServerSDK>::Defaults::Events()); } TEST_F(ConfigBuilderTest, CanDisableDataSystem) { diff --git a/libs/server-sdk/tests/server_c_bindings_test.cpp b/libs/server-sdk/tests/server_c_bindings_test.cpp index 4b7845836..54508ba20 100644 --- a/libs/server-sdk/tests/server_c_bindings_test.cpp +++ b/libs/server-sdk/tests/server_c_bindings_test.cpp @@ -24,7 +24,7 @@ TEST(ClientBindings, MinimalInstantiation) { char const* version = LDServerSDK_Version(); ASSERT_TRUE(version); - ASSERT_STREQ(version, "3.5.3"); // {x-release-please-version} + ASSERT_STREQ(version, "3.5.3"); // {x-release-please-version} LDServerSDK_Free(sdk); } @@ -46,7 +46,7 @@ TEST(ClientBindings, RegisterDataSourceStatusChangeListener) { LDServerSDK sdk = LDServerSDK_New(config); - struct LDServerDataSourceStatusListener listener{}; + struct LDServerDataSourceStatusListener listener {}; LDServerDataSourceStatusListener_Init(&listener); listener.UserData = const_cast("Potato"); @@ -115,7 +115,7 @@ TEST(ClientBindings, ComplexDataSourceStatus) { reinterpret_cast(&status))); EXPECT_EQ(200, LDServerDataSourceStatus_StateSince( - reinterpret_cast(&status))); + reinterpret_cast(&status))); LDDataSourceStatus_ErrorInfo info = LDServerDataSourceStatus_GetLastError( reinterpret_cast(&status)); @@ -188,12 +188,12 @@ TEST(ClientBindings, DoubleVariationPassesThroughDefault) { LDContext context = LDContextBuilder_Build(ctx_builder); std::string const flag = "weight"; - std::vector values = {0.0, 0.0001, 0.5, 1.234, + std::vector values = {0.0, 0.0001, 0.5, 1.234, 12.9, 13.211, 24.0, 1000.0}; for (auto const& v : values) { ASSERT_EQ(LDServerSDK_DoubleVariation(sdk, context, "weight", v), v); ASSERT_EQ(LDServerSDK_DoubleVariationDetail(sdk, context, "weight", v, - LD_DISCARD_DETAIL), + LD_DISCARD_DETAIL), v); } @@ -302,7 +302,6 @@ TEST(ClientBindings, TlsConfigurationSystemCAFile) { LDServerConfig_Free(config); } - TEST(ClientBindings, StreamingPayloadFilters) { LDServerConfigBuilder cfg_builder = LDServerConfigBuilder_New("sdk-123"); @@ -311,8 +310,8 @@ TEST(ClientBindings, StreamingPayloadFilters) { LDServerDataSourceStreamBuilder_Filter(stream_builder, "foo"); - LDServerConfigBuilder_DataSystem_BackgroundSync_Streaming( - cfg_builder, stream_builder); + LDServerConfigBuilder_DataSystem_BackgroundSync_Streaming(cfg_builder, + stream_builder); LDServerConfig config; LDStatus status = LDServerConfigBuilder_Build(cfg_builder, &config); @@ -329,8 +328,8 @@ TEST(ClientBindings, PollingPayloadFilters) { LDServerDataSourcePollBuilder_Filter(poll_builder, "foo"); - LDServerConfigBuilder_DataSystem_BackgroundSync_Polling( - cfg_builder, poll_builder); + LDServerConfigBuilder_DataSystem_BackgroundSync_Polling(cfg_builder, + poll_builder); LDServerConfig config; LDStatus status = LDServerConfigBuilder_Build(cfg_builder, &config);