Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
/ config-validate Public archive

A .NET Global Tool Designed to Sniff Out Configuration Issues Between Different Environments

License

Notifications You must be signed in to change notification settings

ritterim/config-validate

Repository files navigation

Config-Validate

A .NET Global Tool designed to sniff out configuration issues between different environments.

Build status

Conventions

This tool assumes a two things are true about your configuration files.

  1. There is a core configuration, known as the blueprint. The blueprint is normally appSettings.json and should have all, if not a large majority, of the keys that are part of your configuration.
  2. There is a set of environment configurations. For example, your solution may have appSettings.Development.json, appSettings.Staging.json, and appSettings.Production.json. These are additive configurations to be layered on top of the blueprint.

If your solution doesn't follow this convention, then this tool will most likely not work for you.

Running The Tool

From within the solution directory, first add the package.

dotnet add package config-validate

Once installed, you can run the config-validate command from withing your project.

/src/Host> dotnet config-validate

Results

You first need to learn the vocabulary of config-validate used to understand the output.

Key

The key is the string value used to access the configuration from within your .NET Core project.

For example, when using JSON as your configuration mechanism, you may get the following key.

{
  "test": {
    "nested": "hello,world"
  }
}

With the key of test:nested and a value of hello,world.

Missing

We mentioned that every project will have a blueprint configuration. When a key is missing, it means that the key is found in the blueprint but is not mentioned in the environment congifuration.

// appSettings
// blueprint
{
    "test" : {
        "nested" : "hello,world"
    }
}
// production
{

}

If you were to run config-validate you would get the following results:

-- Production
|     Key     | Missing | Unknown |    Value    |
| ----------- | ------- | ------- | ----------- |
| test:nested | Yes     | No      | hello,world |

Unknown

Unknown keys are configuration settings found in environment configurations, but not found in the blueprint.

// appSettings
// blueprint
{
    "test" : {
        "nested" : "hello,world"
    }
}
// production
{
    "what" : "new"
}

When running config-validate you would get the following results:

-- Production
|     Key     | Missing | Unknown |    Value    |
| ----------- | ------- | ------- | ----------- |
| test:nested | Yes     | No      | hello,world |
| what        | No      | Yes     | new         |

Value

The value column shows you the value of the setting when it is combined with the blueprint.

Part Of The Build

The point of config-validate is to run during a CI/CD process to catch common mistakes. Because of that, the process will return exit codes that will fail most builds. We also understand that builds and configuration are complicated, so we've built some mechanism to ignore certain issues.

Dot File Configuration

The .config-validate file should be placed in the project root and allows you to ignore certain keys, decide failure states, and enable artifacts

{
    "config-validate-settings" : {
        "artificat" : {
            "enabled" : "true",
            "filename" : "config-validate.txt"
        },
        "fail-on" : "Unknown", //All, Missing, Unknown
        "ignore-keys" : [
            "data:protection",
            "my:ignored:key"
        ]
    }
}

About

A .NET Global Tool Designed to Sniff Out Configuration Issues Between Different Environments

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published