Add new functions for credential handling, node lookup, and context-aware parameter overrides; update module version to 1.2.0
This commit is contained in:
@@ -35,6 +35,71 @@ function Invoke-ConfigurationDataExpressionFunction {
|
||||
|
||||
throw "Function [$Name] expects 1 or 2 arguments, but received [$($Arguments.Count)]."
|
||||
}
|
||||
"parentkey" {
|
||||
Assert-ConfigurationDataExpressionArgumentCount -Name $Name -Arguments $Arguments -Count 0
|
||||
|
||||
$Path = @($Context.CurrentPath)
|
||||
if($Path.Count -lt 2){
|
||||
throw "Function [$Name] requires the expression to be nested inside a parent map."
|
||||
}
|
||||
|
||||
return [string]$Path[$Path.Count - 2]
|
||||
}
|
||||
"credentialwithdomain" {
|
||||
Assert-ConfigurationDataExpressionArgumentCount -Name $Name -Arguments $Arguments -Count 2
|
||||
|
||||
if(-not ($Arguments[0] -is [System.Management.Automation.PSCredential])){
|
||||
throw "Function [$Name] expects a PSCredential as first argument."
|
||||
}
|
||||
|
||||
return ConvertTo-ConfigurationDataDomainCredential -Credential ([System.Management.Automation.PSCredential]$Arguments[0]) -Domain ([string]$Arguments[1])
|
||||
}
|
||||
"firstnodenamewhere" {
|
||||
if($Arguments.Count -ne 1 -and $Arguments.Count -ne 2){
|
||||
throw "Function [$Name] expects 1 or 2 arguments, but received [$($Arguments.Count)]."
|
||||
}
|
||||
|
||||
$PropertyName = [string]$Arguments[0]
|
||||
if([string]::IsNullOrWhiteSpace($PropertyName)){
|
||||
throw "Function [$Name] requires a non-empty node property name."
|
||||
}
|
||||
|
||||
$ExpectedValue = $true
|
||||
if($Arguments.Count -eq 2){
|
||||
$ExpectedValue = $Arguments[1]
|
||||
}
|
||||
|
||||
$AllNodes = $null
|
||||
if($Context.ConfigurationData.ContainsKey("AllNodes")){
|
||||
$AllNodes = $Context.ConfigurationData.AllNodes
|
||||
}elseif($Context.ConfigurationData.ContainsKey("Resources") -and
|
||||
$Context.ConfigurationData.Resources -is [System.Collections.IDictionary] -and
|
||||
$Context.ConfigurationData.Resources.ContainsKey("AllNodes")){
|
||||
$AllNodes = $Context.ConfigurationData.Resources.AllNodes
|
||||
}
|
||||
|
||||
foreach($Node in @($AllNodes)){
|
||||
if($null -eq $Node -or -not ($Node -is [System.Collections.IDictionary])){
|
||||
continue
|
||||
}
|
||||
|
||||
if(-not $Node.ContainsKey($PropertyName)){
|
||||
continue
|
||||
}
|
||||
|
||||
if($Node[$PropertyName] -ne $ExpectedValue){
|
||||
continue
|
||||
}
|
||||
|
||||
if(-not $Node.ContainsKey("NodeName") -or [string]::IsNullOrWhiteSpace([string]$Node.NodeName)){
|
||||
throw "Function [$Name] matched a node by [$PropertyName], but the node does not define [NodeName]."
|
||||
}
|
||||
|
||||
return [string]$Node.NodeName
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
"concat" {
|
||||
return (@($Arguments) | ForEach-Object { [string]$_ }) -join ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user