1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-21 12:05:42 +01:00

[PM-3708] Allow local overrides for flag values (#3243)

* Allow local overrides for flag values

* Rename helper method
This commit is contained in:
Matt Bishop 2023-09-01 07:06:21 -04:00 committed by GitHub
parent c271e2dae2
commit d0cf8204c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 26 deletions

View File

@ -46,4 +46,13 @@ public static class FeatureFlagKeys
.Select(x => (string)x.GetRawConstantValue())
.ToList();
}
public static Dictionary<string, string> GetLocalOverrideFlagValues()
{
// place overriding values when needed locally (offline), or return null
return new Dictionary<string, string>()
{
{ TrustedDeviceEncryption, "true" }
};
}
}

View File

@ -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<string, string> 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;
}
}

View File

@ -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)
{