Debian Codegraph @

ansible_collections/community/windows/plugins/modules/win_psrepository_info.ps1

raw
1 #!powershell
2
3 # Copyright: (c) 2020, Brian Scholer <@briantist>
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 #AnsibleRequires -CSharpUtil Ansible.Basic
7 #AnsibleRequires -PowerShell ..module_utils._Tls
8 #Requires -Module Ansible.ModuleUtils.CamelConversion
9 #Requires -Module PowerShellGet
10
11 $spec = @{
12 options = @{
13 name = @{ type = 'str' ; default = '*' }
14 }
15 supports_check_mode = $true
16 }
17 $module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)
18
19 function Convert-ObjectToSnakeCase {
20 <#
21 .SYNOPSIS
22 Converts an object with CamelCase properties to a dictionary with snake_case keys.
23 Works in the spirit of and depends on the existing CamelConversion module util.
24 #>
25 [CmdletBinding()]
26 param(
27 [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
28 [OutputType([System.Collections.Specialized.OrderedDictionary])]
29 [Object]
30 $InputObject ,
31
32 [Parameter()]
33 [Switch]
34 $NoRecurse ,
35
36 [Parameter()]
37 [Switch]
38 $OmitNull
39 )
40
41 Process {
42 $result = [Ordered]@{}
43 foreach ($property in $InputObject.PSObject.Properties) {
44 $value = $property.Value
45 if (-not $NoRecurse -and $value -is [System.Collections.IDictionary]) {
46 $value = Convert-DictToSnakeCase -dict $value
47 }
48 elseif (-not $NoRecurse -and ($value -is [Array] -or $value -is [System.Collections.ArrayList])) {
49 $value = Convert-ListToSnakeCase -list $value
50 }
51 elseif ($null -eq $value) {
52 if ($OmitNull) {
53 continue
54 }
55 }
56 elseif (-not $NoRecurse -and $value -isnot [System.ValueType] -and $value -isnot [string]) {
57 $value = Convert-ObjectToSnakeCase -InputObject $value
58 }
59
60 $name = Convert-StringToSnakeCase -string $property.Name
61 $result[$name] = $value
62 }
63 $result
64 }
65 }
66
67 Enable-TlsProtocol
68
69 $module.Result.repositories = @(Get-PSRepository -Name $module.Params.name | Convert-ObjectToSnakeCase)
70
71 $module.ExitJson()