-
Notifications
You must be signed in to change notification settings - Fork 119
Add support for the ':' character in feature flags when using the default feature flag definition provider. #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ namespace Microsoft.FeatureManagement | |
| sealed class ConfigurationFeatureDefinitionProvider : IFeatureDefinitionProvider, IDisposable | ||
| { | ||
| private const string FeatureFiltersSectionName = "EnabledFor"; | ||
| private static readonly string[] SectionSeparator = new string[] { ConfigurationPath.KeyDelimiter }; | ||
| private readonly IConfiguration _configuration; | ||
| private readonly ConcurrentDictionary<string, FeatureDefinition> _definitions; | ||
| private IDisposable _changeSubscription; | ||
|
|
@@ -83,8 +84,39 @@ public async IAsyncEnumerable<FeatureDefinition> GetAllFeatureDefinitionsAsync() | |
|
|
||
| private FeatureDefinition ReadFeatureDefinition(string featureName) | ||
| { | ||
| IConfigurationSection configuration = GetFeatureDefinitionSections() | ||
| .FirstOrDefault(section => section.Key.Equals(featureName, StringComparison.OrdinalIgnoreCase)); | ||
| IConfigurationSection configuration; | ||
|
|
||
| if (!featureName.Contains(ConfigurationPath.KeyDelimiter)) | ||
| { | ||
| configuration = GetFeatureDefinitionSections() | ||
| .FirstOrDefault(section => section.Key.Equals(featureName, StringComparison.OrdinalIgnoreCase)); | ||
| } | ||
| else | ||
| { | ||
| // | ||
| // Feature names with configuration path delimiters require traversing children sections for resolution | ||
| IEnumerable<string> sectionNames = featureName.Split(SectionSeparator, StringSplitOptions.None); | ||
|
|
||
| IEnumerable<IConfigurationSection> sections; | ||
|
|
||
| IConfigurationSection section = null; | ||
|
|
||
| foreach (string sectionName in sectionNames) | ||
| { | ||
| sections = section == null ? | ||
| GetFeatureDefinitionSections() : | ||
| section.GetChildren(); | ||
|
Comment on lines
+106
to
+108
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| section = sections.FirstOrDefault(section => section.Key.Equals(sectionName, StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| if (section == null) | ||
| { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| configuration = section; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. This made me realize a bigger problem which is how this works with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GetFeatureDefinitionAsync can't detect features that have |
||
| } | ||
|
|
||
| if (configuration == null) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,16 @@ | |
| } | ||
| } | ||
| ] | ||
| }, | ||
| "Feature:With:Colons": { | ||
| "EnabledFor": [ | ||
| { | ||
| "Name": "Test", | ||
| "Parameters": { | ||
| "P1": "V1" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we define
SectionSeparatoras astringinstead ofstring[]? Another option is to directly useConfigurationPath.KeyDelimiterbecause this is a special delimiter that's unlikely to change in .NET.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just stored it that way since
Splitaccepts string[] andConfigurationPath.KeyDelimiteris a string instead of a char. It's an optimization instead of creating a new string array every time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, Split also accepts string delimiter.