mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
win_exec: refactor PS exec runner (#45334)
* win_exec: refactor PS exec runner * more changes for PSCore compatibility * made some changes based on the recent review * split up module exec scripts for smaller payload * removed C# module support to focus on just error msg improvement * cleaned up c# test classifier code
This commit is contained in:
parent
aa2f3edb49
commit
e972287c35
34 changed files with 2751 additions and 1676 deletions
|
@ -14,29 +14,9 @@ $result = @{
|
|||
changed = $false
|
||||
}
|
||||
|
||||
Function ConvertTo-HashtableFromPsCustomObject($psObject)
|
||||
{
|
||||
$hashtable = @{}
|
||||
$psObject | Get-Member -MemberType *Property | ForEach-Object {
|
||||
$value = $psObject.($_.Name)
|
||||
if ($value -is [PSObject])
|
||||
{
|
||||
$value = ConvertTo-HashtableFromPsCustomObject -myPsObject $value
|
||||
}
|
||||
$hashtable.($_.Name) = $value
|
||||
}
|
||||
|
||||
return ,$hashtable
|
||||
}
|
||||
|
||||
Function Cast-ToCimInstance($name, $value, $className)
|
||||
{
|
||||
# this converts a hashtable to a CimInstance
|
||||
if ($value -is [PSObject])
|
||||
{
|
||||
# convert to hashtable
|
||||
$value = ConvertTo-HashtableFromPsCustomObject -psObject $value
|
||||
}
|
||||
|
||||
$valueType = $value.GetType()
|
||||
if ($valueType -ne [hashtable])
|
||||
|
|
|
@ -10,49 +10,7 @@
|
|||
|
||||
$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
|
||||
|
||||
# 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
|
||||
$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
|
||||
|
|
|
@ -9,13 +9,6 @@
|
|||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# NOTE: Ensure we get proper debug information when things fall over
|
||||
trap {
|
||||
if ($null -eq $result) { $result = @{} }
|
||||
$result.exception = "$($_ | Out-String)`r`n$($_.ScriptStackTrace)"
|
||||
Fail-Json -obj $result -message "Uncaught exception: $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
$params = Parse-Args -arguments $args -supports_check_mode $true
|
||||
|
||||
$process_name_exact = Get-AnsibleParam -obj $params -name "process_name_exact" -type "list"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue