mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
All feature state access through config API (#2785)
This commit is contained in:
@ -36,4 +36,11 @@ public interface IFeatureService
|
||||
/// <param name="defaultValue">The default value for the feature.</param>
|
||||
/// <returns>The feature variation value.</returns>
|
||||
string GetStringVariation(string key, ICurrentContext currentContext, string defaultValue = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all feature values.
|
||||
/// </summary>
|
||||
/// <param name="currentContext">A context providing information that can be used to evaluate the feature values.</param>
|
||||
/// <returns>A dictionary of feature keys and their values.</returns>
|
||||
Dictionary<string, object> GetAll(ICurrentContext currentContext);
|
||||
}
|
||||
|
@ -63,6 +63,38 @@ public class LaunchDarklyFeatureService : IFeatureService, IDisposable
|
||||
return _client.StringVariation(key, BuildContext(currentContext), defaultValue);
|
||||
}
|
||||
|
||||
public Dictionary<string, object> GetAll(ICurrentContext currentContext)
|
||||
{
|
||||
var results = new Dictionary<string, object>();
|
||||
|
||||
var keys = FeatureFlagKeys.GetAllKeys();
|
||||
|
||||
var values = _client.AllFlagsState(BuildContext(currentContext));
|
||||
if (values.Valid)
|
||||
{
|
||||
foreach (var key in keys)
|
||||
{
|
||||
var value = values.GetFlagValueJson(key);
|
||||
switch (value.Type)
|
||||
{
|
||||
case LaunchDarkly.Sdk.LdValueType.Bool:
|
||||
results.Add(key, value.AsBool);
|
||||
break;
|
||||
|
||||
case LaunchDarkly.Sdk.LdValueType.Number:
|
||||
results.Add(key, value.AsInt);
|
||||
break;
|
||||
|
||||
case LaunchDarkly.Sdk.LdValueType.String:
|
||||
results.Add(key, value.AsString);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_client?.Dispose();
|
||||
|
Reference in New Issue
Block a user