Fix win_environment: strict-mode fix for 'value' (#2404)

reviewable/pr18780/r1
Andrea Scarpino 9 years ago committed by Matt Davis
parent 65fe9eb2b0
commit ac32a1b808

@ -20,37 +20,18 @@
# POWERSHELL_COMMON # POWERSHELL_COMMON
$params = Parse-Args $args; $params = Parse-Args $args;
$state = Get-Attr $params "state" $null; $state = Get-AnsibleParam -obj $params -name "state" -default "present" -validateSet "present","absent"
$result = New-Object PSObject; $name = Get-AnsibleParam -obj $params -name "name" -failifempty $true
Set-Attr $result "changed" $false; $level = Get-AnsibleParam -obj $params -name "level" -validateSet "machine","process","user" -failifempty $true
$value = Get-AnsibleParam -obj $params -name "value"
If ($state) { If ($level) {
$state = $state.ToString().ToLower() $level = $level.ToString().ToLower()
If (($state -ne 'present') -and ($state -ne 'absent') ) {
Fail-Json $result "state is '$state'; must be 'present', or 'absent'"
}
} else {
$state = 'present'
}
If ($params.name)
{
$name = $params.name
} else {
Fail-Json $result "missing required argument: name"
}
$value = $params.value
If ($params.level) {
$level = $params.level.ToString().ToLower()
If (( $level -ne 'machine') -and ( $level -ne 'user' ) -and ( $level -ne 'process')) {
Fail-Json $result "level is '$level'; must be 'machine', 'user', or 'process'"
}
} }
$before_value = [Environment]::GetEnvironmentVariable($name, $level) $before_value = [Environment]::GetEnvironmentVariable($name, $level)
$state = $state.ToString().ToLower()
if ($state -eq "present" ) { if ($state -eq "present" ) {
[Environment]::SetEnvironmentVariable($name, $value, $level) [Environment]::SetEnvironmentVariable($name, $value, $level)
} Elseif ($state -eq "absent") { } Elseif ($state -eq "absent") {
@ -59,6 +40,8 @@ if ($state -eq "present" ) {
$after_value = [Environment]::GetEnvironmentVariable($name, $level) $after_value = [Environment]::GetEnvironmentVariable($name, $level)
$result = New-Object PSObject;
Set-Attr $result "changed" $false;
Set-Attr $result "name" $name; Set-Attr $result "name" $name;
Set-Attr $result "before_value" $before_value; Set-Attr $result "before_value" $before_value;
Set-Attr $result "value" $after_value; Set-Attr $result "value" $after_value;

Loading…
Cancel
Save