Enhance configuration data validation and add new utility functions
- Added validation for empty values in Assert-ConfigurationDataParameter. - Introduced Assert-ConfigurationDataSecretReference for secret reference validation. - Implemented Test-ConfigurationDataExpressionParentheses to validate expression syntax. - Added Test-ConfigurationDataMissingReferenceError to check for missing parameter or variable definitions. - Updated Invoke-ConfigurationDataExpression to handle new validation logic. - Revised Readme.md to reflect changes in secret reference handling.
This commit is contained in:
45
Private/Assert-ConfigurationDataSecretReference.ps1
Normal file
45
Private/Assert-ConfigurationDataSecretReference.ps1
Normal file
@@ -0,0 +1,45 @@
|
||||
function Assert-ConfigurationDataSecretReference {
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
[ValidateSet("credential", "securestring")]
|
||||
[string]
|
||||
$TypeName,
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
$Value
|
||||
)
|
||||
|
||||
if(-not (Test-ConfigurationDataMap -Value $Value)){
|
||||
return
|
||||
}
|
||||
|
||||
if(-not (Test-ConfigurationDataMapContainsKey -Map $Value -Key "Provider")){
|
||||
throw "Parameter [$Name] uses type [$TypeName] and a secret reference, but [Provider] is not defined."
|
||||
}
|
||||
|
||||
if(-not (Test-ConfigurationDataMapContainsKey -Map $Value -Key "Name")){
|
||||
throw "Parameter [$Name] uses type [$TypeName] and a secret reference, but [Name] is not defined."
|
||||
}
|
||||
|
||||
$Provider = [string](Get-ConfigurationDataMapValue -Map $Value -Key "Provider")
|
||||
if([string]::IsNullOrWhiteSpace($Provider)){
|
||||
throw "Parameter [$Name] secret reference [Provider] must not be empty."
|
||||
}
|
||||
|
||||
$SecretName = [string](Get-ConfigurationDataMapValue -Map $Value -Key "Name")
|
||||
if([string]::IsNullOrWhiteSpace($SecretName)){
|
||||
throw "Parameter [$Name] secret reference [Name] must not be empty."
|
||||
}
|
||||
|
||||
switch($Provider.ToLowerInvariant()){
|
||||
"keepass" { return }
|
||||
default {
|
||||
throw "Parameter [$Name] uses unsupported secret provider [$Provider]."
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user