diff --git a/src/AspNetCore.VersionInfo/Configuration/ExclusionSettings.cs b/src/AspNetCore.VersionInfo/Configuration/ExclusionSettings.cs new file mode 100644 index 0000000..81dbf5e --- /dev/null +++ b/src/AspNetCore.VersionInfo/Configuration/ExclusionSettings.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AspNetCore.VersionInfo.Configuration +{ + public class ExclusionSettings + { + public IEnumerable Keys { get; set; } + } +} diff --git a/src/AspNetCore.VersionInfo/Configuration/ExclusionSettingsService.cs b/src/AspNetCore.VersionInfo/Configuration/ExclusionSettingsService.cs new file mode 100644 index 0000000..8b1395c --- /dev/null +++ b/src/AspNetCore.VersionInfo/Configuration/ExclusionSettingsService.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AspNetCore.VersionInfo.Configuration +{ + public class ExclusionSettingsService : IExclusionSettings + { + public IEnumerable keys { get; set; } + public ExclusionSettingsService(List keys) + { + this.keys = keys; + } + } +} diff --git a/src/AspNetCore.VersionInfo/Configuration/IExclusionSettings.cs b/src/AspNetCore.VersionInfo/Configuration/IExclusionSettings.cs new file mode 100644 index 0000000..9147788 --- /dev/null +++ b/src/AspNetCore.VersionInfo/Configuration/IExclusionSettings.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AspNetCore.VersionInfo.Configuration +{ + public interface IExclusionSettings + { + IEnumerable keys { get; set; } + } +} diff --git a/src/AspNetCore.VersionInfo/Extensions/VersionInfoBuilderExtensions.cs b/src/AspNetCore.VersionInfo/Extensions/VersionInfoBuilderExtensions.cs index b266d7d..b9fe1e4 100644 --- a/src/AspNetCore.VersionInfo/Extensions/VersionInfoBuilderExtensions.cs +++ b/src/AspNetCore.VersionInfo/Extensions/VersionInfoBuilderExtensions.cs @@ -1,12 +1,36 @@ -using AspNetCore.VersionInfo.Providers; +using System; +using System.Collections.Generic; +using AspNetCore.VersionInfo.Configuration; +using AspNetCore.VersionInfo.Providers; using Microsoft.Extensions.DependencyInjection; namespace AspNetCore.VersionInfo { public static class VersionInfoBuilderExtensions { - public static VersionInfoBuilder With(this VersionInfoBuilder builder) where T : class, IInfoProvider + private static List keyValues = new List(); + public static VersionInfoBuilder With(this VersionInfoBuilder builder, Action configureOptions = null) where T : class, IInfoProvider { + + if (configureOptions != null) + { + var settings = new ExclusionSettings(); + + configureOptions(settings); + + foreach (var keyItem in settings.Keys) + { + keyValues.Add(keyItem); + } + } + + builder.Services.AddTransient(serviceProvider => + { + + return new ExclusionSettingsService(keyValues); + + }); + builder.Services.AddTransient(); return builder; } diff --git a/src/AspNetCore.VersionInfo/Services/FlatInfoCollector.cs b/src/AspNetCore.VersionInfo/Services/FlatInfoCollector.cs index 4733fa8..dc822c4 100644 --- a/src/AspNetCore.VersionInfo/Services/FlatInfoCollector.cs +++ b/src/AspNetCore.VersionInfo/Services/FlatInfoCollector.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using System.Linq; +using AspNetCore.VersionInfo.Configuration; using AspNetCore.VersionInfo.Models; using AspNetCore.VersionInfo.Models.Collectors; using AspNetCore.VersionInfo.Providers; @@ -10,16 +12,18 @@ internal partial class FlatInfoCollector : IInfoCollector { private readonly IEnumerable _infoHandlers; private readonly ILogger _logger; + private readonly IExclusionSettings _exclusionSettings; #region LoggerMessage [LoggerMessage(Level = LogLevel.Debug, Message = "Elaborating {handlerName} provider")] private partial void LogElaboratingHandler(string handlerName); #endregion - public FlatInfoCollector(IEnumerable infoHandlers, ILogger logger) + public FlatInfoCollector(IEnumerable infoHandlers, ILogger logger, IExclusionSettings exclusionSettings) { _infoHandlers = infoHandlers; _logger = logger; + _exclusionSettings = exclusionSettings; } public ICollectorResult AggregateData() { @@ -30,12 +34,26 @@ public ICollectorResult AggregateData() LogElaboratingHandler(handler.Name); foreach (var d in handler.GetData()) { - result.Add(new VersionDataProviderKeyValueResult() + if (_exclusionSettings.keys.Count() == 0) { - Key = d.Key, - Value = d.Value, - ProviderName = handler.Name - }); + result.Add(new VersionDataProviderKeyValueResult() + { + Key = d.Key, + Value = d.Value, + ProviderName = handler.Name + }); + } + + else if (!_exclusionSettings.keys.Contains(d.Key)) + { + result.Add(new VersionDataProviderKeyValueResult() + { + Key = d.Key, + Value = d.Value, + ProviderName = handler.Name + }); + + } } }