-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathConvert-BicepConfigToInputConfig.ps1
More file actions
72 lines (57 loc) · 3.32 KB
/
Convert-BicepConfigToInputConfig.ps1
File metadata and controls
72 lines (57 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function Convert-BicepConfigToInputConfig {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $false)]
[PSCustomObject]$bicepConfig,
[Parameter(Mandatory = $false)]
[PSCustomObject]$validators,
[Parameter(Mandatory = $false)]
[PSCustomObject]$appendToObject = $null
)
if ($PSCmdlet.ShouldProcess("Parse Interface Variables into Config", "modify")) {
$configItems = [PSCustomObject]@{}
if ($appendToObject -ne $null) {
$configItems = $appendToObject
}
Write-Verbose $validators
foreach ($variable in $bicepConfig.inputs.PSObject.Properties) {
Write-Verbose "Parsing variable $($variable.Name)"
$description = $variable.Value.description
$configItem = [PSCustomObject]@{}
$configItem | Add-Member -NotePropertyName "Source" -NotePropertyValue $variable.Value.source
$configItem | Add-Member -NotePropertyName "Value" -NotePropertyValue ""
if ($variable.Value.PSObject.Properties.Name -contains "sourceInput") {
$configItem | Add-Member -NotePropertyName "SourceInput" -NotePropertyValue $variable.Value.sourceInput
}
if ($variable.Value.PSObject.Properties.Name -contains "pattern") {
$configItem | Add-Member -NotePropertyName "Pattern" -NotePropertyValue $variable.Value.pattern
}
if ($variable.Value.PSObject.Properties.Name -contains "process") {
$configItem | Add-Member -NotePropertyName "Process" -NotePropertyValue $variable.Value.process
}
if ($variable.Value.PSObject.Properties.Name -contains "default") {
$defaultValue = $variable.Value.default
$configItem | Add-Member -NotePropertyName "DefaultValue" -NotePropertyValue $defaultValue
}
if ($variable.Value.PSObject.Properties.Name -contains "validation") {
$validationType = $variable.Value.validation
$validator = $validators.PSObject.Properties[$validationType].Value
$description = "$description ($($validator.Description))"
Write-Verbose "Adding $($variable.Value.validation) validation for $($variable.Name). Validation type: $($validator.Type)"
if ($validator.Type -eq "AllowedValues") {
$configItem | Add-Member -NotePropertyName "AllowedValues" -NotePropertyValue $validator.AllowedValues
}
if ($validator.Type -eq "Valid") {
$configItem | Add-Member -NotePropertyName "Valid" -NotePropertyValue $validator.Valid
}
$configItem | Add-Member -NotePropertyName "Validator" -NotePropertyValue $validationType
}
if ($variable.Value.PSObject.Properties.Name -contains "targets") {
$configItem | Add-Member -NotePropertyName "targets" -NotePropertyValue $variable.Value.targets
}
$configItem | Add-Member -NotePropertyName "Description" -NotePropertyValue $description
$configItems | Add-Member -NotePropertyName $variable.Name -NotePropertyValue $configItem
}
}
return $configItems
}