1
0
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:
Matt Bishop 2023-05-26 13:52:50 -04:00 committed by GitHub
parent 5079c2b231
commit beb3479746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 3 deletions

View File

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

View File

@ -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>();
}
}

View File

@ -4,4 +4,5 @@ public interface ILaunchDarklySettings
{
public string SdkKey { get; set; }
public string FlagDataFilePath { get; set; }
public Dictionary<string, string> FlagValues { get; set; }
}