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

View file

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

View file

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