71 lines
2.6 KiB
PowerShell
71 lines
2.6 KiB
PowerShell
function Assert-ConfigurationDataParameterType {
|
|
[CmdletBinding()]
|
|
Param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]
|
|
$Name,
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
$Definition,
|
|
|
|
[AllowNull()]
|
|
$Value
|
|
)
|
|
|
|
if(-not (Test-ConfigurationDataMapContainsKey -Map $Definition -Key "Type")){
|
|
return
|
|
}
|
|
|
|
$TypeName = ([string](Get-ConfigurationDataMapValue -Map $Definition -Key "Type")).ToLowerInvariant()
|
|
|
|
switch($TypeName){
|
|
"string" {
|
|
if(Test-ConfigurationDataSecretReference -Value $Value){
|
|
Assert-ConfigurationDataSecretReference -Name $Name -TypeName "string" -Value $Value
|
|
return
|
|
}
|
|
|
|
if($Value -isnot [string]){
|
|
throw "Parameter [$Name] expects type [string], but received [$($Value.GetType().Name)]."
|
|
}
|
|
}
|
|
{ $_ -in @("int", "integer") } {
|
|
if(-not (Test-ConfigurationDataValueIsInteger -Value $Value)){
|
|
throw "Parameter [$Name] expects type [int], but received [$($Value.GetType().Name)]."
|
|
}
|
|
}
|
|
{ $_ -in @("bool", "boolean") } {
|
|
if($Value -isnot [bool]){
|
|
throw "Parameter [$Name] expects type [bool], but received [$($Value.GetType().Name)]."
|
|
}
|
|
}
|
|
"array" {
|
|
if($Value -isnot [System.Array] -or $Value -is [string]){
|
|
throw "Parameter [$Name] expects type [array], but received [$($Value.GetType().Name)]."
|
|
}
|
|
}
|
|
{ $_ -in @("hashtable", "object") } {
|
|
if(-not (Test-ConfigurationDataMap -Value $Value)){
|
|
throw "Parameter [$Name] expects type [hashtable], but received [$($Value.GetType().Name)]."
|
|
}
|
|
}
|
|
"securestring" {
|
|
if(($Value -isnot [string]) -and ($Value -isnot [System.Security.SecureString]) -and (-not (Test-ConfigurationDataMap -Value $Value))){
|
|
throw "Parameter [$Name] expects type [secureString], but received [$($Value.GetType().Name)]."
|
|
}
|
|
|
|
Assert-ConfigurationDataSecretReference -Name $Name -TypeName "securestring" -Value $Value
|
|
}
|
|
"credential" {
|
|
if(($Value -isnot [System.Management.Automation.PSCredential]) -and (-not (Test-ConfigurationDataMap -Value $Value))){
|
|
throw "Parameter [$Name] expects type [credential], but received [$($Value.GetType().Name)]."
|
|
}
|
|
|
|
Assert-ConfigurationDataSecretReference -Name $Name -TypeName "credential" -Value $Value
|
|
}
|
|
default {
|
|
throw "Parameter [$Name] uses unsupported type [$TypeName]."
|
|
}
|
|
}
|
|
}
|