Enhance configuration data handling with new reference resolution functions, dummy secret support, and update module version to 1.1.0
This commit is contained in:
68
Private/New-ConfigurationDataDummySecretValue.ps1
Normal file
68
Private/New-ConfigurationDataDummySecretValue.ps1
Normal file
@@ -0,0 +1,68 @@
|
||||
function New-ConfigurationDataDummySecretValue {
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[ValidateSet("credential", "securestring", "string")]
|
||||
[string]
|
||||
$ExpectedType,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[System.Collections.IDictionary]
|
||||
$Reference,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$ParameterName = ""
|
||||
)
|
||||
|
||||
$Name = ""
|
||||
if($null -ne $Reference -and (Test-ConfigurationDataMapContainsKey -Map $Reference -Key "Name")){
|
||||
$Name = [string](Get-ConfigurationDataMapValue -Map $Reference -Key "Name" -DefaultValue "")
|
||||
}
|
||||
|
||||
$UserName = ""
|
||||
if($null -ne $Reference -and (Test-ConfigurationDataMapContainsKey -Map $Reference -Key "UserName")){
|
||||
$UserName = [string](Get-ConfigurationDataMapValue -Map $Reference -Key "UserName" -DefaultValue "")
|
||||
}
|
||||
|
||||
if([string]::IsNullOrWhiteSpace($UserName)){
|
||||
$UserNameSource = $ParameterName
|
||||
if([string]::IsNullOrWhiteSpace($UserNameSource)){
|
||||
$UserNameSource = $Name
|
||||
}
|
||||
|
||||
if([string]::IsNullOrWhiteSpace($UserNameSource)){
|
||||
$UserNameSource = "Credential"
|
||||
}
|
||||
|
||||
$UserNameLeaf = @($UserNameSource -split '[\\/]+')[-1]
|
||||
if([string]::IsNullOrWhiteSpace($UserNameLeaf)){
|
||||
$UserNameLeaf = "Credential"
|
||||
}
|
||||
|
||||
$UserName = "DUMMY\$UserNameLeaf"
|
||||
}
|
||||
|
||||
switch($ExpectedType.ToLowerInvariant()){
|
||||
"credential" {
|
||||
return [pscredential]::new(
|
||||
$UserName,
|
||||
(ConvertTo-SecureString -String "DummyPassword!" -AsPlainText -Force)
|
||||
)
|
||||
}
|
||||
"securestring" {
|
||||
return ConvertTo-SecureString -String "DummySecret!" -AsPlainText -Force
|
||||
}
|
||||
"string" {
|
||||
if([string]::IsNullOrWhiteSpace($Name)){
|
||||
$Name = $ParameterName
|
||||
}
|
||||
|
||||
if([string]::IsNullOrWhiteSpace($Name)){
|
||||
return "DummySecret"
|
||||
}
|
||||
|
||||
return "DummySecret:$Name"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user