-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
765fd9e
commit 4ddcd99
Showing
7 changed files
with
245 additions
and
167 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/ALZ/Private/Config-Helpers/Convert-ParametersToInputConfig.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
function Convert-ParametersToInputConfig { | ||
param( | ||
[Parameter(Mandatory = $false)] | ||
[PSCustomObject] $inputConfig, | ||
[Parameter(Mandatory = $false)] | ||
[hashtable] $parameters | ||
) | ||
|
||
foreach($parameterKey in $parameters.Keys) { | ||
$parameter = $parameters[$parameterKey] | ||
Write-Verbose "Processing parameter $parameterKey $(ConvertTo-Json $parameter -Depth 100)" | ||
|
||
foreach($parameterAlias in $parameter.aliases) { | ||
if($inputConfig.PsObject.Properties.Name -contains $parameterAlias) { | ||
Write-Verbose "Alias $parameterAlias exists in input config, renaming..." | ||
$configItem = $inputConfig.PSObject.Properties | Where-Object { $_.Name -eq $parameterAlias } | ||
$inputConfig | Add-Member -NotePropertyName $parameterKey -NotePropertyValue $configItem.Value | ||
$inputConfig.PSObject.Properties.Remove($configItem.Name) | ||
continue | ||
} | ||
} | ||
|
||
if($inputConfig.PsObject.Properties.Name -notcontains $parameterKey) { | ||
$variableValue = [Environment]::GetEnvironmentVariable("ALZ_$($parameterKey)") | ||
if($null -eq $variableValue) { | ||
if($parameter.type -eq "SwitchParameter") { | ||
$variableValue = $parameter.value.IsPresent | ||
} else { | ||
$variableValue = $parameter.value | ||
} | ||
} | ||
|
||
if($parameter.type -eq "SwitchParameter") { | ||
$variableValue = [bool]::Parse($variableValue) | ||
} | ||
Write-Verbose "Adding parameter $parameterKey with value $variableValue" | ||
$inputConfig | Add-Member -NotePropertyName $parameterKey -NotePropertyValue $variableValue | ||
} | ||
} | ||
|
||
return $inputConfig | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.