Skip to content
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

Startup configuration options #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rebiiin
Copy link

@rebiiin rebiiin commented Oct 12, 2022

In the Startup.cs file we can use the below configuration to exclude some of sensitive contents
Example.

 public void ConfigureServices(IServiceCollection services)
        {
       
            services.AddVersionInfo()
                .With<ClrVersionProvider>(option => option.Keys = new string[] { "RuntimeInformation.ProcessArchitecture", "RuntimeInformation.RuntimeIdentifier" });
                
        }

Result of the above configuration:

{
  "Results": [
    {
      "ProviderName": "ClrVersionProvider",
      "Key": "RuntimeInformation.FrameworkDescription",
      "Value": ".NET 6.0.10"
    },
    {
      "ProviderName": "ClrVersionProvider",
      "Key": "RuntimeInformation.OsDescription",
      "Value": "Microsoft Windows 10.0.19044"
    },
    {
      "ProviderName": "ClrVersionProvider",
      "Key": "RuntimeInformation.OsArchitecture",
      "Value": "X64"
    },
    {
      "ProviderName": "ClrVersionProvider",
      "Key": "Environment.DotNetVersion",
      "Value": "6.0.10"
    }
  ],
  "Count": 4
}

We can add all as well.

 public void ConfigureServices(IServiceCollection services)
        {
            services.AddVersionInfo()
                .With<ClrVersionProvider>(option => option.Keys = new string[] { "RuntimeInformation.ProcessArchitecture", "RuntimeInformation.RuntimeIdentifier" })
                .With<AssemblyVersionProvider>()
                .With<AppDomainAssembliesVersionProvider>()
                .With<EnvironmentProvider>()
                .With<EnvironmentVariablesProvider>();
        }

The final example is.

public void ConfigureServices(IServiceCollection services)
        {

           services.AddVersionInfo()
                    .With<ClrVersionProvider>(option => option.Keys = new string[] { "RuntimeInformation.ProcessArchitecture", "RuntimeInformation.RuntimeIdentifier" })
                    .With<AssemblyVersionProvider>(option => option.Keys = new string[] { "EntryAssemblyFileVersion" })
                    .With<AppDomainAssembliesVersionProvider>(option => option.Keys = new string[] { "Basic", "Anonymously Hosted DynamicMethods Assembly", "Basic.Views", "AspNetCore.VersionInfo" })
                    .With<EnvironmentProvider>()
                    .With<EnvironmentVariablesProvider>(option => option.Keys = new string[] { "Environment.Is64BitOperatingSystem" });
        }  

@salem84
Copy link
Owner

salem84 commented Oct 12, 2022

Hi, we have to review some parts...however tests are missing.
Could you add to test project?
Asap I will add comments at your code.
Thanks for your support!

using Microsoft.Extensions.DependencyInjection;

namespace AspNetCore.VersionInfo
{
public static class VersionInfoBuilderExtensions
{
public static VersionInfoBuilder With<T>(this VersionInfoBuilder builder) where T : class, IInfoProvider
private static List<String> keyValues = new List<String>();
public static VersionInfoBuilder With<T>(this VersionInfoBuilder builder, Action<ExclusionSettings> configureOptions = null) where T : class, IInfoProvider
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this way configureOptions is specific for the provider configuration, but all (excluded) keys of each provider are merged in a single array (static).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better approach is using AspNet Options framework... as example you could inspect AspnetCore.Healthchecks code for it

https://github.com/dotnet/aspnetcore/tree/main/src/HealthChecks/HealthChecks/src/DependencyInjection

@rebiiin
Copy link
Author

rebiiin commented Oct 15, 2022

Hi, Thanks for review I will try to find a better approach , your comment is useful for the next PR.

@salem84
Copy link
Owner

salem84 commented Oct 17, 2022

Hi, Thanks for review I will try to find a better approach , your comment is useful for the next PR.

If you prefer, I create a new branch and support you in the first part (creating options, extension methods, ...) and then you integrate filter logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants