InFurSecDen.Utils.ConfigurationValidator 1.0.0-alpha1

This is a prerelease version of InFurSecDen.Utils.ConfigurationValidator.
dotnet add package InFurSecDen.Utils.ConfigurationValidator --version 1.0.0-alpha1
                    
NuGet\Install-Package InFurSecDen.Utils.ConfigurationValidator -Version 1.0.0-alpha1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="InFurSecDen.Utils.ConfigurationValidator" Version="1.0.0-alpha1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="InFurSecDen.Utils.ConfigurationValidator" Version="1.0.0-alpha1" />
                    
Directory.Packages.props
<PackageReference Include="InFurSecDen.Utils.ConfigurationValidator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add InFurSecDen.Utils.ConfigurationValidator --version 1.0.0-alpha1
                    
#r "nuget: InFurSecDen.Utils.ConfigurationValidator, 1.0.0-alpha1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package InFurSecDen.Utils.ConfigurationValidator@1.0.0-alpha1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=InFurSecDen.Utils.ConfigurationValidator&version=1.0.0-alpha1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=InFurSecDen.Utils.ConfigurationValidator&version=1.0.0-alpha1&prerelease
                    
Install as a Cake Tool

Configuration Validator

A small side project for validating the items loaded into your .NET Core application's global configuration.

Currently supported validation rules:

  • required: Checks to see if the value for a specific key is set, and is not null.
    • Valid values: true, false

Future planned rules:

  • format: Checks to see if the value matches a specific format, such as an int, bool, or base64/byte[] type
  • regex: Checks to see if the value matches some supplied regex mask
  • maxlength: Checks to see that the string for this value does not exceed some specified length
  • minlength: Checks to see that the string for this value is not smaller than some specified length
  • minbytes: Checks to see the value is at least a minimum length of bytes (requires base64 format check)
  • matches: Checks to see the value matches one of a specified list of values
  • uniquepassword: Checks to see the value is not on a known list of compromised passwords (requires outbound internet connection to talk to https://haveibeenpwned.com/Passwords)
    • This will throw a warning but not an exception, since this will leak the presence of secrets if a new password is added to Pwned Passwords that is used by the application. It is up to the developer to rectify this.

How do I get this in my awesome project?

Add the InFurSecDen.Utils.ConfigutationValidator NuGet package using the usual NuGet methods:

Powershell:

Install-Package InFurSecDen.Utils.ConfigutationValidator -IncludePrerelease

dotnet CLI:

dotnet add package InFurSecDen.Utils.ConfigurationValidator -prerelease

.csproj:

<PackageReference Include="InFurSecDen.Utils.ConfigutationValidator" Version="x.x.x"/>

How do I use it?

configurationschema.json

Create a file (usually configurationschema.json) in the following format:

{
	"Key1": {
		"required": true
	},
	"Key2:SubKey1": {
		"required": true
	},
	"Key2:SubKey2": {
		"required": true
	}
}

Configuration Builder

In your IConfigurationBuilder builder methods (usually in Program.cs as of ASP.NET Core 2.1), after all of the configuration sources are defined, add the following line (assuming config is the name of your IConfigurationBuilder object):

var errors = config.Validate(File.ReadAllText("configurationschema.json"));

If errors.Count returns zero, the schema was successfully validated.

Optionally, you can throw an AggregateException with the following line:

config.Validate(File.ReadAllText("configurationschema.json"), throwOnError: true);

All this talk about NuGet is making me hungry for chicken nuggets! 🦊

Me too. If you're based in New Zealand, I recommend the BP Connect chicken nuggets, they're by far the biggest and have the tastiest seasonings. No, seriously.

Don't go to K-Fry. I don't know how but they somehow manage to totally fuck up cooking chicken, and this offends me mightily.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha1 758 1/4/2019