Windows: Get rid of remaining Get-Attr modules (#42921)

This is the final cleanup of modules still using the old Get-Attr
interface. Ready to deprecate this mechanism.
This commit is contained in:
Dag Wieers 2018-07-18 21:37:07 +02:00 committed by Jordan Borean
commit f2acc97b84
3 changed files with 52 additions and 84 deletions

View file

@ -5,38 +5,25 @@
#Requires -Module Ansible.ModuleUtils.Legacy
$params = Parse-Args $args;
$ErrorActionPreference = "Stop"
# Name parameter
$name = Get-Attr $params "name" $FALSE;
If ($name -eq $FALSE) {
Fail-Json @{} "missing required argument: name";
}
# State parameter
$state = Get-Attr $params "state" $FALSE;
$state.ToString().ToLower();
If (($state -ne $FALSE) -and ($state -ne 'started') -and ($state -ne 'stopped') -and ($state -ne 'restarted') -and ($state -ne 'absent')) {
Fail-Json @{} "state is '$state'; must be 'started', 'restarted', 'stopped' or 'absent'"
}
# Path parameter
$physical_path = Get-Attr $params "physical_path" $FALSE;
$site_id = Get-Attr $params "site_id" $FALSE;
# Application Pool Parameter
$application_pool = Get-Attr $params "application_pool" $FALSE;
$params = Parse-Args $args
$name = Get-AnsibleParam -obj $params -name "name" -type "str" -failifempty $true
$application_pool = Get-AnsibleParam -obj $params -name "application_pool" -type "str"
$physical_path = Get-AnsibleParam -obj $params -name "physical_path" -type "str"
$site_id = Get-AnsibleParam -obj $params -name "site_id" -type "str"
$state = Get-AnsibleParam -obj $params -name "state" -type "str" -validateset "absent","restarted","started","stopped"
# Binding Parameters
$bind_port = Get-Attr $params "port" $FALSE;
$bind_ip = Get-Attr $params "ip" $FALSE;
$bind_hostname = Get-Attr $params "hostname" $FALSE;
$bind_ssl = Get-Attr $params "ssl" $FALSE;
$bind_port = Get-AnsibleParam -obj $params -name "port" -type "int"
$bind_ip = Get-AnsibleParam -obj $params -name "ip" -type "str"
$bind_hostname = Get-AnsibleParam -obj $params -name "hostname" -type "str"
$bind_ssl = Get-AnsibleParam -obj $params -name "ssl" -type "str"
# Custom site Parameters from string where properties
# are separated by a pipe and property name/values by colon.
# Ex. "foo:1|bar:2"
$parameters = Get-Attr $params "parameters" $null;
$parameters = Get-AnsibleParam -obj $params -name "parameters" -type "str"
if($parameters -ne $null) {
$parameters = @($parameters -split '\|' | ForEach {
return ,($_ -split "\:", 2);
@ -53,7 +40,7 @@ if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $null) {
$result = @{
site = @{}
changed = $false
};
}
# Site info
$site = Get-Website | Where { $_.Name -eq $name }
@ -61,17 +48,17 @@ $site = Get-Website | Where { $_.Name -eq $name }
Try {
# Add site
If(($state -ne 'absent') -and (-not $site)) {
If ($physical_path -eq $FALSE) {
Fail-Json @{} "missing required arguments: physical_path"
If (-not $physical_path) {
Fail-Json -obj $result -message "missing required arguments: physical_path"
}
ElseIf (-not (Test-Path $physical_path)) {
Fail-Json @{} "specified folder must already exist: physical_path"
Fail-Json -obj $result -message "specified folder must already exist: physical_path"
}
$site_parameters = @{
Name = $name
PhysicalPath = $physical_path
};
}
If ($application_pool) {
$site_parameters.ApplicationPool = $application_pool
@ -114,7 +101,7 @@ Try {
# Change Physical Path if needed
if($physical_path) {
If (-not (Test-Path $physical_path)) {
Fail-Json @{} "specified folder must already exist: physical_path"
Fail-Json -obj $result -message "specified folder must already exist: physical_path"
}
$folder = Get-Item $physical_path
@ -142,7 +129,7 @@ Try {
"ConfigurationAttribute" { $parameter_value = $property_value.value }
"String" { $parameter_value = $property_value }
}
if((-not $parameter_value) -or ($parameter_value) -ne $_[1]) {
Set-ItemProperty "IIS:\Sites\$($site.Name)" $_[0] $_[1]
$result.changed = $true
@ -165,7 +152,7 @@ Try {
}
Catch
{
Fail-Json @{} $_.Exception.Message
Fail-Json -obj $result -message $_.Exception.Message
}
if ($state -ne 'absent')
@ -185,4 +172,4 @@ if ($site)
}
}
Exit-Json $result
Exit-Json -obj $result