StrictMode fixes for win_iis_webbinding

StrictMode fixes for win_scheduled_task

StrictMode fixes for win_webpicmd
This commit is contained in:
nitzmahone 2016-06-15 11:55:12 -07:00 committed by Matt Clay
parent 5bec8ad321
commit e5e1869403
3 changed files with 35 additions and 51 deletions

View file

@ -23,42 +23,35 @@
$params = Parse-Args $args; $params = Parse-Args $args;
# Name parameter $name = Get-AnsibleParam $params -name "name" -failifempty $true
$name = Get-Attr $params "name" $FALSE; $state = Get-AnsibleParam $params "state" -default "present" -validateSet "present","absent"
If ($name -eq $FALSE) { $host_header = Get-AnsibleParam $params -name "host_header"
Fail-Json (New-Object psobject) "missing required argument: name"; $protocol = Get-AnsibleParam $params -name "protocol"
} $port = Get-AnsibleParam $params -name "port"
$ip = Get-AnsibleParam $params -name "ip"
# State parameter $certificatehash = Get-AnsibleParam $params -name "certificate_hash" -default $false
$state = Get-Attr $params "state" $FALSE; $certificateStoreName = Get-AnsibleParam $params -name "certificate_store_name" -default "MY"
$valid_states = ($FALSE, 'present', 'absent');
If ($state -NotIn $valid_states) {
Fail-Json $result "state is '$state'; must be $($valid_states)"
}
$binding_parameters = New-Object psobject @{ $binding_parameters = New-Object psobject @{
Name = $name Name = $name
}; };
If ($params.host_header) { If ($host_header) {
$binding_parameters.HostHeader = $params.host_header $binding_parameters.HostHeader = $host_header
} }
If ($params.protocol) { If ($protocol) {
$binding_parameters.Protocol = $params.protocol $binding_parameters.Protocol = $protocol
} }
If ($params.port) { If ($port) {
$binding_parameters.Port = $params.port $binding_parameters.Port = $port
} }
If ($params.ip) { If ($ip) {
$binding_parameters.IPAddress = $params.ip $binding_parameters.IPAddress = $ip
} }
$certificateHash = Get-Attr $params "certificate_hash" $FALSE;
$certificateStoreName = Get-Attr $params "certificate_store_name" "MY";
# Ensure WebAdministration module is loaded # Ensure WebAdministration module is loaded
if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $null){ if ((Get-Module "WebAdministration" -ErrorAction SilentlyContinue) -eq $null){
Import-Module WebAdministration Import-Module WebAdministration
@ -98,12 +91,12 @@ try {
# Select certificat # Select certificat
if($certificateHash -ne $FALSE) { if($certificateHash -ne $FALSE) {
$ip = $binding_parameters.IPAddress $ip = $binding_parameters["IPAddress"]
if((!$ip) -or ($ip -eq "*")) { if((!$ip) -or ($ip -eq "*")) {
$ip = "0.0.0.0" $ip = "0.0.0.0"
} }
$port = $binding_parameters.Port $port = $binding_parameters["Port"]
if(!$port) { if(!$port) {
$port = 443 $port = 443
} }

View file

@ -24,29 +24,27 @@ $ErrorActionPreference = "Stop"
$params = Parse-Args $args; $params = Parse-Args $args;
$days_of_week = Get-Attr $params "days_of_week" $null; $days_of_week = Get-AnsibleParam $params -anem "days_of_week"
$enabled = Get-Attr $params "enabled" $true | ConvertTo-Bool; $enabled = Get-AnsibleParam $params -name "enabled" -default $true
$description = Get-Attr $params "description" " "; $enabled = $enabled | ConvertTo-Bool
$path = Get-Attr $params "path" $null; $description = Get-AnsibleParam $params -name "description" -default " "
$argument = Get-Attr $params "argument" $null; $path = Get-AnsibleParam $params -name "path"
$argument = Get-AnsibleParam $params -name "argument"
$result = New-Object PSObject; $result = New-Object PSObject;
Set-Attr $result "changed" $false; Set-Attr $result "changed" $false;
#Required vars #Required vars
$name = Get-Attr -obj $params -name name -failifempty $true -resultobj $result $name = Get-AnsibleParam -obj $params -name name -failifempty $true -resultobj $result
$state = Get-Attr -obj $params -name state -failifempty $true -resultobj $result $state = Get-AnsibleParam -obj $params -name state -failifempty $true -resultobj $result -validateSet "present","absent"
if( ($state -ne "present") -and ($state -ne "absent") ) {
Fail-Json $result "state must be present or absent"
}
#Vars conditionally required #Vars conditionally required
if($state -eq "present") { $present_args_required = $state -eq "present"
$execute = Get-Attr -obj $params -name execute -failifempty $true -resultobj $result $execute = Get-AnsibleParam -obj $params -name execute -failifempty $present_args_required -resultobj $result
$frequency = Get-Attr -obj $params -name frequency -failifempty $true -resultobj $result $frequency = Get-AnsibleParam -obj $params -name frequency -failifempty $present_args_required -resultobj $result
$time = Get-Attr -obj $params -name time -failifempty $true -resultobj $result $time = Get-AnsibleParam -obj $params -name time -failifempty $present_args_required -resultobj $result
$user = Get-Attr -obj $params -name user -failifempty $true -resultobj $result $user = Get-AnsibleParam -obj $params -name user -failifempty $present_args_required -resultobj $result
}
# Mandatory Vars # Mandatory Vars
if ($frequency -eq "weekly") if ($frequency -eq "weekly")
@ -59,7 +57,7 @@ if ($frequency -eq "weekly")
if ($path) if ($path)
{ {
$path = "\{0}\" -f $params.path $path = "\{0}\" -f $path
} }
else else
{ {
@ -70,7 +68,7 @@ try {
$task = Get-ScheduledTask -TaskPath "$path" | Where-Object {$_.TaskName -eq "$name"} $task = Get-ScheduledTask -TaskPath "$path" | Where-Object {$_.TaskName -eq "$name"}
# Correlate task state to enable variable, used to calculate if state needs to be changed # Correlate task state to enable variable, used to calculate if state needs to be changed
$taskState = $task.State $taskState = if ($task) { $task.State } else { $null }
if ($taskState -eq "Ready"){ if ($taskState -eq "Ready"){
$taskState = $true $taskState = $true
} }

View file

@ -25,14 +25,7 @@ $params = Parse-Args $args;
$result = New-Object PSObject; $result = New-Object PSObject;
Set-Attr $result "changed" $false; Set-Attr $result "changed" $false;
If ($params.name) $package = Get-AnsibleParam $params -name "name" -failifempty $true
{
$package = $params.name
}
Else
{
Fail-Json $result "missing required argument: name"
}
Function Find-Command Function Find-Command
{ {