diff --git a/src/Core/Constants.cs b/src/Core/Constants.cs index 8db721d17e..132b1db447 100644 --- a/src/Core/Constants.cs +++ b/src/Core/Constants.cs @@ -46,4 +46,13 @@ public static class FeatureFlagKeys .Select(x => (string)x.GetRawConstantValue()) .ToList(); } + + public static Dictionary GetLocalOverrideFlagValues() + { + // place overriding values when needed locally (offline), or return null + return new Dictionary() + { + { TrustedDeviceEncryption, "true" } + }; + } } diff --git a/src/Core/Services/Implementations/LaunchDarklyFeatureService.cs b/src/Core/Services/Implementations/LaunchDarklyFeatureService.cs index adf2a6e96a..501db21d82 100644 --- a/src/Core/Services/Implementations/LaunchDarklyFeatureService.cs +++ b/src/Core/Services/Implementations/LaunchDarklyFeatureService.cs @@ -29,24 +29,12 @@ public class LaunchDarklyFeatureService : IFeatureService, IDisposable // 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))); - } - } - - ldConfig.DataSource(source); + ldConfig.DataSource(BuildDataSource(globalSettings.LaunchDarkly.FlagValues)); + } + // support local overrides + else if (FeatureFlagKeys.GetLocalOverrideFlagValues()?.Any() is true) + { + ldConfig.DataSource(BuildDataSource(FeatureFlagKeys.GetLocalOverrideFlagValues())); } else { @@ -187,4 +175,26 @@ public class LaunchDarklyFeatureService : IFeatureService, IDisposable return builder.Build(); } + + private TestData BuildDataSource(Dictionary values) + { + var source = TestData.DataSource(); + foreach (var kvp in values) + { + 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))); + } + } + + return source; + } } diff --git a/test/Core.Test/Services/LaunchDarklyFeatureServiceTests.cs b/test/Core.Test/Services/LaunchDarklyFeatureServiceTests.cs index 3644dc805b..37ced167be 100644 --- a/test/Core.Test/Services/LaunchDarklyFeatureServiceTests.cs +++ b/test/Core.Test/Services/LaunchDarklyFeatureServiceTests.cs @@ -20,14 +20,6 @@ public class LaunchDarklyFeatureServiceTests .Create(); } - [Fact] - public void Offline_WhenSelfHost() - { - var sutProvider = GetSutProvider(new Core.Settings.GlobalSettings() { SelfHosted = true }); - - Assert.False(sutProvider.Sut.IsOnline()); - } - [Theory, BitAutoData] public void DefaultFeatureValue_WhenSelfHost(string key) {