Skip to content

Commit

Permalink
Add Solution Items, NuGet build
Browse files Browse the repository at this point in the history
  • Loading branch information
TCFox committed Jan 4, 2019
1 parent a3aefc6 commit 1000bec
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 2 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @tcfox
19 changes: 17 additions & 2 deletions InFurSecDen.Utils.ConfigurationValidator.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InFurSecDen.Utils.ConfigurationValidator", "src\InFurSecDen.Utils.ConfigurationValidator\InFurSecDen.Utils.ConfigurationValidator.csproj", "{5F8A747C-23B9-4BCA-A448-41C043F3C522}"
VisualStudioVersion = 15.0.28307.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InFurSecDen.Utils.ConfigurationValidator", "src\InFurSecDen.Utils.ConfigurationValidator\InFurSecDen.Utils.ConfigurationValidator.csproj", "{5F8A747C-23B9-4BCA-A448-41C043F3C522}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7BA506D0-9F91-46EA-B280-607F33719F9E}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
CODEOWNERS = CODEOWNERS
LICENSE = LICENSE
Readme.md = Readme.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -14,4 +23,10 @@ Global
{5F8A747C-23B9-4BCA-A448-41C043F3C522}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F8A747C-23B9-4BCA-A448-41C043F3C522}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0B517F0D-EC37-4D13-B563-7ED28D219E75}
EndGlobalSection
EndGlobal
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 The InFurSec Den

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
81 changes: 81 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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:
```powershell
Install-Package InFurSecDen.Utils.ConfigutationValidator -IncludePrerelease
```

`dotnet` CLI:
```bash
dotnet add package InFurSecDen.Utils.ConfigurationValidator -prerelease
```

`.csproj`:
```xml
<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:

```json
{
"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):

```csharp
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:

```csharp
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.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ApplicationIcon />
<Win32Resource />
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>TC Fox</Authors>
<Description>An extension to IConfigurationBuilder that validates the final IConfiguration build based off a set of rules in a JSON file.</Description>
<RepositoryUrl>https://github.com/InFurSecDen/ConfigurationValidator</RepositoryUrl>
<PackageProjectUrl>https://github.com/InFurSecDen/ConfigurationValidator</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/InFurSecDen/ConfigurationValidator/blob/master/LICENSE</PackageLicenseUrl>
<Version>1.0.0-alpha1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 1000bec

Please sign in to comment.