diff --git a/src/Core/Services/Implementations/LaunchDarklyFeatureService.cs b/src/Core/Services/Implementations/LaunchDarklyFeatureService.cs index b3ac5bc62..adf2a6e96 100644 --- a/src/Core/Services/Implementations/LaunchDarklyFeatureService.cs +++ b/src/Core/Services/Implementations/LaunchDarklyFeatureService.cs @@ -25,15 +25,37 @@ public class LaunchDarklyFeatureService : IFeatureService, IDisposable .FilePaths(globalSettings.LaunchDarkly?.FlagDataFilePath) .AutoUpdate(true) ); + } + // support configuration directly from settings + else if (globalSettings.LaunchDarkly?.FlagValues?.Any() is true) + { + var source = TestData.DataSource(); + foreach (var kvp in globalSettings.LaunchDarkly.FlagValues) + { + if (bool.TryParse(kvp.Value, out bool boolValue)) + { + source.Update(source.Flag(kvp.Key).ValueForAll(LaunchDarkly.Sdk.LdValue.Of(boolValue))); + } + else if (int.TryParse(kvp.Value, out int intValue)) + { + source.Update(source.Flag(kvp.Key).ValueForAll(LaunchDarkly.Sdk.LdValue.Of(intValue))); + } + else + { + source.Update(source.Flag(kvp.Key).ValueForAll(LaunchDarkly.Sdk.LdValue.Of(kvp.Value))); + } + } - // do not provide analytics events - ldConfig.Events(Components.NoEvents); + ldConfig.DataSource(source); } else { - // when a file-based fallback isn't available, work offline + // when fallbacks aren't available, work offline ldConfig.Offline(true); } + + // do not provide analytics events + ldConfig.Events(Components.NoEvents); } else if (globalSettings.SelfHosted) { diff --git a/src/Core/Settings/GlobalSettings.cs b/src/Core/Settings/GlobalSettings.cs index a2768458a..758ee9e58 100644 --- a/src/Core/Settings/GlobalSettings.cs +++ b/src/Core/Settings/GlobalSettings.cs @@ -545,5 +545,6 @@ public class GlobalSettings : IGlobalSettings { public string SdkKey { get; set; } public string FlagDataFilePath { get; set; } = "flags.json"; + public Dictionary FlagValues { get; set; } = new Dictionary(); } } diff --git a/src/Core/Settings/ILaunchDarklySettings.cs b/src/Core/Settings/ILaunchDarklySettings.cs index e395a6965..05cd6dbc4 100644 --- a/src/Core/Settings/ILaunchDarklySettings.cs +++ b/src/Core/Settings/ILaunchDarklySettings.cs @@ -4,4 +4,5 @@ public interface ILaunchDarklySettings { public string SdkKey { get; set; } public string FlagDataFilePath { get; set; } + public Dictionary FlagValues { get; set; } }