mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
Allow feature flag state configuration via application settings (#2963)
* Allow feature flag state configuration via application settings * Use string values for flags * Update src/Core/Services/Implementations/LaunchDarklyFeatureService.cs Remove useless `ToString()`. Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
This commit is contained in:
parent
5079c2b231
commit
beb3479746
@ -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)
|
||||
{
|
||||
|
@ -545,5 +545,6 @@ public class GlobalSettings : IGlobalSettings
|
||||
{
|
||||
public string SdkKey { get; set; }
|
||||
public string FlagDataFilePath { get; set; } = "flags.json";
|
||||
public Dictionary<string, string> FlagValues { get; set; } = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,5 @@ public interface ILaunchDarklySettings
|
||||
{
|
||||
public string SdkKey { get; set; }
|
||||
public string FlagDataFilePath { get; set; }
|
||||
public Dictionary<string, string> FlagValues { get; set; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user