ConfigurationScanner
Extension class for IConfigurationRoot scanning. See ThrowOnForbiddenToken and ThrowOnConfiguredForbiddenToken. The goal of this library is to provide a simple way to ensure no "forbidden" values are found in the configuration. The reason i personally use this library is that I have properties on the my appSettings which have placeholder values that must be overriden by environmental variables, otherwise the program cannot run. This library makes sure the forbidden values/placeholders are not in the final configuration.
The hard coded name of the section used to look for the forbidden token. Can be read to programatically inject a forbidden token into an existing configuration. Value: "ConfigurationScanner".
The hard coded name of the Configuration Token Key inside ClassSectionName section. Can be read to programatically inject a forbidden token into an existing configuration. Value: "Token".
Has the same function as as ThrowOnForbiddenToken but the token is actually read from the configuration itself. For this method to work there needs to be a section with the name equal to ClassSectionName. It also needs to have the key with the value equal to ConfigurationTokenKey. The actual value of the mentioned key contains the token that will be taken as forbidden.
The unmodified IConfigurationRoot if no forbidden token exists.
Name | Type | Description |
---|---|---|
conf | Microsoft.Extensions.Configuration.IConfigurationRoot | The configuration root to be scanned. |
Name | Description |
---|---|
System.ArgumentException | Thrown when the forbidden token cannot be found in the configuration root. |
Extension method that throws an exception when a given token is found on a value of the configuration root. A configuration provider may have a property of a secret set to a placeholder that another configuration provider is supposed to overwrite. If the overwrite is not done this extension will throw an exception. This is useful for example in the case where the appSettings json file has a structure where some properties are secrets to be injected through other means like for example environmental variables. If the environmental variables are not injected and thus not override the placeholders, the method will throw an exception and give the program the opportunity to handle such situation.
The unmodified IConfigurationRoot if no forbidden token exists.
Name | Type | Description |
---|---|---|
conf | Microsoft.Extensions.Configuration.IConfigurationRoot | The configuration root to be scanned. |
forbiddenToken | System.String | The token that, if found will throw an exception "T:ForbiddenValueConfigurationException". |
Name | Description |
---|---|
ConfigurationScanner.ForbiddenValueConfigurationException | Thrown when a forbidden token is found in the configuration. |
ConfigurationScanner
Exception class that informs on when forbidden values were found on the configuration by ThrowOnForbiddenToken or ThrowOnConfiguredForbiddenToken.
Initializes a new instance of the ForbiddenValueConfigurationException class.
Name | Type | Description |
---|---|---|
foundValues | System.Collections.Generic.List{System.Collections.Generic.KeyValuePair{System.String,System.String}} | A list with the keys and values of the found forbidden properties found |
in the configuration. |
Gets list with the containing the configuration's key and value that were found and led to the current exception.