|
|
@ -10,7 +10,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Function ConvertTo-Hashtable {
|
|
|
|
|
|
|
|
param([Object]$Value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($null -eq $Value) {
|
|
|
|
|
|
|
|
return $null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$value_type = $Value.GetType()
|
|
|
|
|
|
|
|
if ($value_type.IsGenericType) {
|
|
|
|
|
|
|
|
$value_type = $value_type.GetGenericTypeDefinition()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($value_type -eq [System.Collections.Generic.Dictionary`2]) {
|
|
|
|
|
|
|
|
$new_value = @{}
|
|
|
|
|
|
|
|
foreach ($kv in $Value.GetEnumerator()) {
|
|
|
|
|
|
|
|
$new_value.Add($kv.Key, (ConvertTo-Hashtable -Value $kv.Value))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ,$new_value
|
|
|
|
|
|
|
|
} elseif ($value_type -eq [System.Collections.ArrayList]) {
|
|
|
|
|
|
|
|
for ($i = 0; $i -lt $Value.Count; $i++) {
|
|
|
|
|
|
|
|
$Value[$i] = ConvertTo-Hashtable -Value $Value[$i]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ,$Value.ToArray()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return ,$Value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$params = Parse-Args -arguments $args -supports_check_mode $true
|
|
|
|
$params = Parse-Args -arguments $args -supports_check_mode $true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# FUTURE: remove this once exec_wrapper has this behaviour inbuilt with the new
|
|
|
|
|
|
|
|
# json changes in the exec_wrapper.
|
|
|
|
|
|
|
|
# Currently ConvertFrom-Json creates a PSObject for the deserialized JSON and the
|
|
|
|
|
|
|
|
# exec_wrapper converts all dicts as Hashtable. Unfortunately it doesn't
|
|
|
|
|
|
|
|
# convert any dict in lists leaving to some confusing behaviour. We manually
|
|
|
|
|
|
|
|
# use JavaScriptSerializer to ensure we have the type of objects to simply the
|
|
|
|
|
|
|
|
# code in the module when it comes to type checking
|
|
|
|
|
|
|
|
$params_json = ConvertTo-Json -InputObject $params -Depth 99 -Compress
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Add-Type -AssemblyName System.Web.Extensions
|
|
|
|
|
|
|
|
$json = New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer
|
|
|
|
|
|
|
|
$json.MaxJsonLength = [Int32]::MaxValue
|
|
|
|
|
|
|
|
$json.RecursionLimit = [Int32]::MaxValue
|
|
|
|
|
|
|
|
$params = ConvertTo-Hashtable -Value ($json.Deserialize($params_json, [System.Collections.Generic.Dictionary`2[[String], [Object]]]))
|
|
|
|
|
|
|
|
|
|
|
|
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
|
|
|
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
|
|
|
$diff_mode = Get-AnsibleParam -obj $params -name "_ansible_diff" -type "bool" -default $false
|
|
|
|
$diff_mode = Get-AnsibleParam -obj $params -name "_ansible_diff" -type "bool" -default $false
|
|
|
|
$_remote_tmp = Get-AnsibleParam $params "_ansible_remote_tmp" -type "path" -default $env:TMP
|
|
|
|
$_remote_tmp = Get-AnsibleParam $params "_ansible_remote_tmp" -type "path" -default $env:TMP
|
|
|
@ -132,23 +174,6 @@ $env:TMP = $original_tmp
|
|
|
|
########################
|
|
|
|
########################
|
|
|
|
### HELPER FUNCTIONS ###
|
|
|
|
### HELPER FUNCTIONS ###
|
|
|
|
########################
|
|
|
|
########################
|
|
|
|
Function ConvertTo-HashtableFromPsCustomObject($object) {
|
|
|
|
|
|
|
|
if ($object -is [Hashtable]) {
|
|
|
|
|
|
|
|
return ,$object
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$hashtable = @{}
|
|
|
|
|
|
|
|
$object | Get-Member -MemberType *Property | % {
|
|
|
|
|
|
|
|
$value = $object.$($_.Name)
|
|
|
|
|
|
|
|
if ($value -is [PSObject]) {
|
|
|
|
|
|
|
|
$value = ConvertTo-HashtableFromPsCustomObject -object $value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$hashtable.$($_.Name) = $value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ,$hashtable
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Function Convert-SnakeToPascalCase($snake) {
|
|
|
|
Function Convert-SnakeToPascalCase($snake) {
|
|
|
|
# very basic function to convert snake_case to PascalCase for use in COM
|
|
|
|
# very basic function to convert snake_case to PascalCase for use in COM
|
|
|
|
# objects
|
|
|
|
# objects
|
|
|
@ -275,9 +300,9 @@ Function Compare-PropertyList {
|
|
|
|
$property_value = $new_property.$property_arg
|
|
|
|
$property_value = $new_property.$property_arg
|
|
|
|
|
|
|
|
|
|
|
|
if ($property_value -is [Hashtable]) {
|
|
|
|
if ($property_value -is [Hashtable]) {
|
|
|
|
foreach ($sub_property_arg in $property_value.Keys) {
|
|
|
|
foreach ($kv in $property_value.GetEnumerator()) {
|
|
|
|
$sub_com_name = Convert-SnakeToPascalCase -snake $sub_property_arg
|
|
|
|
$sub_com_name = Convert-SnakeToPascalCase -snake $kv.Key
|
|
|
|
$sub_property_value = $property_value.$sub_property_arg
|
|
|
|
$sub_property_value = $kv.Value
|
|
|
|
[void]$diff_list.Add("+$com_name.$sub_com_name=$sub_property_value")
|
|
|
|
[void]$diff_list.Add("+$com_name.$sub_com_name=$sub_property_value")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -299,9 +324,9 @@ Function Compare-PropertyList {
|
|
|
|
$property_value = $new_property.$property_arg
|
|
|
|
$property_value = $new_property.$property_arg
|
|
|
|
|
|
|
|
|
|
|
|
if ($property_value -is [Hashtable]) {
|
|
|
|
if ($property_value -is [Hashtable]) {
|
|
|
|
foreach ($sub_property_arg in $property_value.Keys) {
|
|
|
|
foreach ($kv in $property_value.GetEnumerator()) {
|
|
|
|
$sub_com_name = Convert-SnakeToPascalCase -snake $sub_property_arg
|
|
|
|
$sub_com_name = Convert-SnakeToPascalCase -snake $kv.Key
|
|
|
|
$sub_property_value = $property_value.$sub_property_arg
|
|
|
|
$sub_property_value = $kv.Value
|
|
|
|
[void]$diff_list.Add("+$com_name.$sub_com_name=$sub_property_value")
|
|
|
|
[void]$diff_list.Add("+$com_name.$sub_com_name=$sub_property_value")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -320,9 +345,9 @@ Function Compare-PropertyList {
|
|
|
|
$existing_value = $existing_property.$com_name
|
|
|
|
$existing_value = $existing_property.$com_name
|
|
|
|
|
|
|
|
|
|
|
|
if ($property_value -is [Hashtable]) {
|
|
|
|
if ($property_value -is [Hashtable]) {
|
|
|
|
foreach ($sub_property_arg in $property_value.Keys) {
|
|
|
|
foreach ($kv in $property_value.GetEnumerator()) {
|
|
|
|
$sub_property_value = $property_value.$sub_property_arg
|
|
|
|
$sub_property_value = $kv.Value
|
|
|
|
$sub_com_name = Convert-SnakeToPascalCase -snake $sub_property_arg
|
|
|
|
$sub_com_name = Convert-SnakeToPascalCase -snake $kv.Key
|
|
|
|
$sub_existing_value = $existing_property.$com_name.$sub_com_name
|
|
|
|
$sub_existing_value = $existing_property.$com_name.$sub_com_name
|
|
|
|
|
|
|
|
|
|
|
|
if ($sub_property_value -ne $null) {
|
|
|
|
if ($sub_property_value -ne $null) {
|
|
|
@ -356,11 +381,11 @@ Function Compare-PropertyList {
|
|
|
|
$existing_value = $existing_property.$com_name
|
|
|
|
$existing_value = $existing_property.$com_name
|
|
|
|
|
|
|
|
|
|
|
|
if ($property_value -is [Hashtable]) {
|
|
|
|
if ($property_value -is [Hashtable]) {
|
|
|
|
foreach ($sub_property_arg in $property_value.Keys) {
|
|
|
|
foreach ($kv in $property_value.GetEnumerator()) {
|
|
|
|
$sub_property_value = $property_value.$sub_property_arg
|
|
|
|
$sub_property_value = $kv.Value
|
|
|
|
|
|
|
|
|
|
|
|
if ($sub_property_value -ne $null) {
|
|
|
|
if ($sub_property_value -ne $null) {
|
|
|
|
$sub_com_name = Convert-SnakeToPascalCase -snake $sub_property_arg
|
|
|
|
$sub_com_name = Convert-SnakeToPascalCase -snake $kv.Key
|
|
|
|
$sub_existing_value = $existing_property.$com_name.$sub_com_name
|
|
|
|
$sub_existing_value = $existing_property.$com_name.$sub_com_name
|
|
|
|
|
|
|
|
|
|
|
|
if ($sub_property_value -cne $sub_existing_value) {
|
|
|
|
if ($sub_property_value -cne $sub_existing_value) {
|
|
|
@ -388,10 +413,10 @@ Function Compare-PropertyList {
|
|
|
|
$com_name = Convert-SnakeToPascalCase -snake $property_arg
|
|
|
|
$com_name = Convert-SnakeToPascalCase -snake $property_arg
|
|
|
|
$new_object_property = $new_object.$com_name
|
|
|
|
$new_object_property = $new_object.$com_name
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($key in $new_value.Keys) {
|
|
|
|
foreach ($kv in $new_value.GetEnumerator()) {
|
|
|
|
$value = $new_value.$key
|
|
|
|
$value = $kv.Value
|
|
|
|
if ($value -ne $null) {
|
|
|
|
if ($value -ne $null) {
|
|
|
|
Set-PropertyForComObject -com_object $new_object_property -name $property_name -arg $key -value $value
|
|
|
|
Set-PropertyForComObject -com_object $new_object_property -name $property_name -arg $kv.Key -value $value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ($new_value -ne $null) {
|
|
|
|
} elseif ($new_value -ne $null) {
|
|
|
@ -731,7 +756,7 @@ if ($run_level -ne $null) {
|
|
|
|
|
|
|
|
|
|
|
|
# manually add the only support action type for each action - also convert PSCustomObject to Hashtable
|
|
|
|
# manually add the only support action type for each action - also convert PSCustomObject to Hashtable
|
|
|
|
for ($i = 0; $i -lt $actions.Count; $i++) {
|
|
|
|
for ($i = 0; $i -lt $actions.Count; $i++) {
|
|
|
|
$action = ConvertTo-HashtableFromPsCustomObject -object $actions[$i]
|
|
|
|
$action = $actions[$i]
|
|
|
|
$action.type = [TASK_ACTION_TYPE]::TASK_ACTION_EXEC
|
|
|
|
$action.type = [TASK_ACTION_TYPE]::TASK_ACTION_EXEC
|
|
|
|
if (-not $action.ContainsKey("path")) {
|
|
|
|
if (-not $action.ContainsKey("path")) {
|
|
|
|
Fail-Json -obj $result -message "action entry must contain the key 'path'"
|
|
|
|
Fail-Json -obj $result -message "action entry must contain the key 'path'"
|
|
|
@ -741,7 +766,7 @@ for ($i = 0; $i -lt $actions.Count; $i++) {
|
|
|
|
|
|
|
|
|
|
|
|
# convert and validate the triggers - and convert PSCustomObject to Hashtable
|
|
|
|
# convert and validate the triggers - and convert PSCustomObject to Hashtable
|
|
|
|
for ($i = 0; $i -lt $triggers.Count; $i++) {
|
|
|
|
for ($i = 0; $i -lt $triggers.Count; $i++) {
|
|
|
|
$trigger = ConvertTo-HashtableFromPsCustomObject -object $triggers[$i]
|
|
|
|
$trigger = $triggers[$i]
|
|
|
|
$valid_trigger_types = @('event', 'time', 'daily', 'weekly', 'monthly', 'monthlydow', 'idle', 'registration', 'boot', 'logon', 'session_state_change')
|
|
|
|
$valid_trigger_types = @('event', 'time', 'daily', 'weekly', 'monthly', 'monthlydow', 'idle', 'registration', 'boot', 'logon', 'session_state_change')
|
|
|
|
if (-not $trigger.ContainsKey("type")) {
|
|
|
|
if (-not $trigger.ContainsKey("type")) {
|
|
|
|
Fail-Json -obj $result -message "a trigger entry must contain a key 'type' with a value of '$($valid_trigger_types -join "', '")'"
|
|
|
|
Fail-Json -obj $result -message "a trigger entry must contain a key 'type' with a value of '$($valid_trigger_types -join "', '")'"
|
|
|
@ -781,7 +806,10 @@ for ($i = 0; $i -lt $triggers.Count; $i++) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($trigger.ContainsKey("repetition")) {
|
|
|
|
if ($trigger.ContainsKey("repetition")) {
|
|
|
|
$trigger.repetition = ConvertTo-HashtableFromPsCustomObject -object $trigger.repetition
|
|
|
|
if ($trigger.repetition -is [Array]) {
|
|
|
|
|
|
|
|
Add-DeprecationWarning -obj $result -message "repetition is a list, should be defined as a dict" -version "2.12"
|
|
|
|
|
|
|
|
$trigger.repetition = $trigger.repetition[0]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$interval_timespan = $null
|
|
|
|
$interval_timespan = $null
|
|
|
|
if ($trigger.repetition.ContainsKey("interval") -and $trigger.repetition.interval -ne $null) {
|
|
|
|
if ($trigger.repetition.ContainsKey("interval") -and $trigger.repetition.interval -ne $null) {
|
|
|
|