Skip to content

ptsneves/ConfigurationScanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ConfigurationScanner

Contents

ConfigurationScanner type

Namespace

ConfigurationScanner

Summary

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.

ClassSectionName constants

Summary

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".

ConfigurationTokenKey constants

Summary

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".

ThrowOnConfiguredForbiddenToken(conf) method

Summary

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.

Returns

The unmodified IConfigurationRoot if no forbidden token exists.

Parameters
Name Type Description
conf Microsoft.Extensions.Configuration.IConfigurationRoot The configuration root to be scanned.
Exceptions
Name Description
System.ArgumentException Thrown when the forbidden token cannot be found in the configuration root.

ThrowOnForbiddenToken(conf,forbiddenToken) method

Summary

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.

Returns

The unmodified IConfigurationRoot if no forbidden token exists.

Parameters
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".
Exceptions
Name Description
ConfigurationScanner.ForbiddenValueConfigurationException Thrown when a forbidden token is found in the configuration.

ForbiddenValueConfigurationException type

Namespace

ConfigurationScanner

Summary

Exception class that informs on when forbidden values were found on the configuration by ThrowOnForbiddenToken or ThrowOnConfiguredForbiddenToken.

#ctor(foundValues) constructor

Summary

Initializes a new instance of the ForbiddenValueConfigurationException class.

Parameters
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.

FoundValues property

Summary

Gets list with the containing the configuration's key and value that were found and led to the current exception.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages