Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows pslint: Re-enable PSPossibleIncorrectComparisonWithNull #55065

Merged
merged 3 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ansible/executor/powershell/become_wrapper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Function Get-BecomeFlags($flags) {
$logon_type = [Ansible.Become.LogonType]::LOGON32_LOGON_INTERACTIVE
$logon_flags = [Ansible.Become.LogonFlags]::LOGON_WITH_PROFILE

if ($flags -eq $null -or $flags -eq "") {
if ($null -eq $flags -or $flags -eq "") {
$flag_split = @()
} elseif ($flags -is [string]) {
$flag_split = $flags.Split(" ")
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/windows/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ if($gather_subset.Contains('interfaces')) {
}
}

if ($gather_subset.Contains("local") -and $factpath -ne $null) {
if ($gather_subset.Contains("local") -and $null -ne $factpath) {
# Get any custom facts; results are updated in the
Get-CustomFacts -factpath $factpath
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/windows/win_certificate_store.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Function New-CertFile($module, $cert, $path, $type, $password) {
}
if ($type -eq "pkcs12") {
$missing_key = $false
if ($cert.PrivateKey -eq $null) {
if ($null -eq $cert.PrivateKey) {
$missing_key = $true
} elseif ($cert.PrivateKey.CspKeyContainerInfo.Exportable -eq $false) {
$missing_key = $true
Expand Down Expand Up @@ -97,7 +97,7 @@ Function New-CertFile($module, $cert, $path, $type, $password) {
$cert_bytes = $file_encoding.GetBytes($cert_content)
} elseif ($type -eq "pkcs12") {
$module.Result.key_exported = $false
if ($cert.PrivateKey -ne $null) {
if ($null -ne $cert.PrivateKey) {
$module.Result.key_exportable = $cert.PrivateKey.CspKeyContainerInfo.Exportable
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/windows/win_dns_client.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ Function Get-DnsClientMatch {

$current_dns_v4 = ($current_dns_all | Where-Object AddressFamily -eq 2 <# IPv4 #>).ServerAddresses

If (($current_dns_v4 -eq $null) -and ($ipv4_addresses -eq $null)) {
If (($null -eq $current_dns_v4) -and ($null -eq $ipv4_addresses)) {
$v4_match = $True
}

ElseIf (($current_dns_v4 -eq $null) -or ($ipv4_addresses -eq $null)) {
ElseIf (($null -eq $current_dns_v4) -or ($null -eq $ipv4_addresses)) {
$v4_match = $False
}

Expand Down Expand Up @@ -158,7 +158,7 @@ Function Set-DnsClientAddresses

Write-DebugLog ("Setting DNS addresses for adapter {0} to ({1})" -f $adapter_name, ($ipv4_addresses -join ", "))

If ($ipv4_addresses -eq $null) {
If ($null -eq $ipv4_addresses) {
Set-DnsClientServerAddress -InterfaceAlias $adapter_name -ResetServerAddress
}

Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/windows/win_domain.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ if ($check_mode -and $installed) {

# Check that we got a valid domain_mode
$valid_domain_modes = [Enum]::GetNames((Get-Command -Name Install-ADDSForest).Parameters.DomainMode.ParameterType)
if (($domain_mode -ne $null) -and -not ($domain_mode -in $valid_domain_modes)) {
if (($null -ne $domain_mode) -and -not ($domain_mode -in $valid_domain_modes)) {
Fail-Json -obj $result -message "The parameter 'domain_mode' does not accept '$domain_mode', please use one of: $valid_domain_modes"
}

# Check that we got a valid forest_mode
$valid_forest_modes = [Enum]::GetNames((Get-Command -Name Install-ADDSForest).Parameters.ForestMode.ParameterType)
if (($forest_mode -ne $null) -and -not ($forest_mode -in $valid_forest_modes)) {
if (($null -ne $forest_mode) -and -not ($forest_mode -in $valid_forest_modes)) {
Fail-Json -obj $result -message "The parameter 'forest_mode' does not accept '$forest_mode', please use one of: $valid_forest_modes"
}

Expand Down Expand Up @@ -103,7 +103,7 @@ if (-not $forest) {
$install_params.DomainNetBiosName = $domain_netbios_name
}

if ($create_dns_delegation -ne $null) {
if ($null -ne $create_dns_delegation) {
$install_params.CreateDnsDelegation = $create_dns_delegation
}

Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/windows/win_domain_computer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ If (-not $sam_account_name.EndsWith("$")) {
$enabled = Get-AnsibleParam -obj $params -name "enabled" -type "bool" -default $true
$description = Get-AnsibleParam -obj $params -name "description" -default $null
$domain_username = Get-AnsibleParam -obj $params -name "domain_username" -type "str"
$domain_password = Get-AnsibleParam -obj $params -name "domain_password" -type "str" -failifempty ($domain_username -ne $null)
$domain_password = Get-AnsibleParam -obj $params -name "domain_password" -type "str" -failifempty ($null -ne $domain_username)
$domain_server = Get-AnsibleParam -obj $params -name "domain_server" -type "str"
$state = Get-AnsibleParam -obj $params -name "state" -ValidateSet "present","absent" -default "present"

$extra_args = @{}
if ($domain_username -ne $null) {
if ($null -ne $domain_username) {
$domain_password = ConvertTo-SecureString $domain_password -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $domain_username, $domain_password
$extra_args.Credential = $credential
}
if ($domain_server -ne $null) {
if ($null -ne $domain_server) {
$extra_args.Server = $domain_server
}

Expand Down
56 changes: 28 additions & 28 deletions lib/ansible/modules/windows/win_domain_group.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $diff_mode = Get-AnsibleParam -obj $params -name "_ansible_diff" -type "bool" -d
$name = Get-AnsibleParam -obj $params -name "name" -type "str" -failifempty $true
$display_name = Get-AnsibleParam -obj $params -name "display_name" -type "str"
$domain_username = Get-AnsibleParam -obj $params -name "domain_username" -type "str"
$domain_password = Get-AnsibleParam -obj $params -name "domain_password" -type "str" -failifempty ($domain_username -ne $null)
$domain_password = Get-AnsibleParam -obj $params -name "domain_password" -type "str" -failifempty ($null -ne $domain_username)
$description = Get-AnsibleParam -obj $params -name "description" -type "str"
$category = Get-AnsibleParam -obj $params -name "category" -type "str" -validateset "distribution","security"
$scope = Get-AnsibleParam -obj $params -name "scope" -type "str" -validateset "domainlocal","global","universal"
Expand All @@ -40,12 +40,12 @@ if (-not (Get-Module -Name ActiveDirectory -ListAvailable)) {
Import-Module ActiveDirectory

$extra_args = @{}
if ($domain_username -ne $null) {
if ($null -ne $domain_username) {
$domain_password = ConvertTo-SecureString $domain_password -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $domain_username, $domain_password
$extra_args.Credential = $credential
}
if ($domain_server -ne $null) {
if ($null -ne $domain_server) {
$extra_args.Server = $domain_server
}

Expand All @@ -57,7 +57,7 @@ try {
Fail-Json $result "failed to retrieve initial details for group $($name): $($_.Exception.Message)"
}
if ($state -eq "absent") {
if ($group -ne $null) {
if ($null -ne $group) {
if ($group.ProtectedFromAccidentalDeletion -eq $true -and $ignore_protection -eq $true) {
$group = $group | Set-ADObject -ProtectedFromAccidentalDeletion $false -WhatIf:$check_mode -PassThru @extra_args
} elseif ($group.ProtectedFromAccidentalDeletion -eq $true -and $ignore_protection -eq $false) {
Expand All @@ -69,15 +69,15 @@ if ($state -eq "absent") {
} catch {
Fail-Json $result "failed to remove group $($name): $($_.Exception.Message)"
}

$result.changed = $true
if ($diff_mode) {
$result.diff.prepared = "-[$name]"
}
}
} else {
# validate that path is an actual path
if ($organizational_unit -ne $null) {
if ($null -ne $organizational_unit) {
try {
Get-ADObject -Identity $organizational_unit @extra_args | Out-Null
} catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
Expand All @@ -86,12 +86,12 @@ if ($state -eq "absent") {
}

$diff_text = $null
if ($group -ne $null) {
if ($null -ne $group) {
# will be overriden later if no change actually occurs
$diff_text += "[$name]`n"

# change the path of the group
if ($organizational_unit -ne $null) {
if ($null -ne $organizational_unit) {
$group_cn = $group.CN
$existing_path = $group.DistinguishedName -replace "^CN=$group_cn,",''
if ($existing_path -ne $organizational_unit) {
Expand All @@ -112,7 +112,7 @@ if ($state -eq "absent") {
$group | Set-ADObject -ProtectedFromAccidentalDeletion $true -WhatIf:$check_mode -PassThru @extra_args | Out-Null
}
}

$result.changed = $true
$diff_text += "-DistinguishedName = CN=$group_cn,$existing_path`n+DistinguishedName = CN=$group_cn,$organizational_unit`n"

Expand All @@ -129,7 +129,7 @@ if ($state -eq "absent") {
$run_change = $false
$set_args = $extra_args.Clone()

if ($scope -ne $null) {
if ($null -ne $scope) {
if ($group.GroupScope -ne $scope) {
# you cannot from from Global to DomainLocal and vice-versa, we
# need to change it to Universal and then finally to the target
Expand All @@ -148,26 +148,26 @@ if ($state -eq "absent") {
}
}

if ($description -ne $null -and $group.Description -cne $description) {
if ($null -ne $description -and $group.Description -cne $description) {
$set_args.Description = $description
$run_change = $true
$diff_text += "-Description = $($group.Description)`n+Description = $description`n"
}

if ($display_name -ne $null -and $group.DisplayName -cne $display_name) {
if ($null -ne $display_name -and $group.DisplayName -cne $display_name) {
$set_args.DisplayName = $display_name
$run_change = $true
$diff_text += "-DisplayName = $($group.DisplayName)`n+DisplayName = $display_name`n"
}

if ($category -ne $null -and $group.GroupCategory -ne $category) {
if ($null -ne $category -and $group.GroupCategory -ne $category) {
$set_args.GroupCategory = $category
$run_change = $true
$diff_text += "-GroupCategory = $($group.GroupCategory)`n+GroupCategory = $category`n"
}

if ($managed_by -ne $null) {
if ($group.ManagedBy -eq $null) {
if ($null -ne $managed_by) {
if ($null -eq $group.ManagedBy) {
$set_args.ManagedBy = $managed_by
$run_change = $true
$diff_text += "+ManagedBy = $managed_by`n"
Expand All @@ -190,7 +190,7 @@ if ($state -eq "absent") {
}
}

if ($attributes -ne $null) {
if ($null -ne $attributes) {
$add_attributes = @{}
$replace_attributes = @{}
foreach ($attribute in $attributes.GetEnumerator()) {
Expand Down Expand Up @@ -227,7 +227,7 @@ if ($state -eq "absent") {
}
$result.changed = $true

if ($extra_scope_change -ne $null) {
if ($null -ne $extra_scope_change) {
try {
$group = $group | Set-ADGroup -GroupScope $extra_scope_change -WhatIf:$check_mode -PassThru @extra_args
} catch {
Expand All @@ -242,7 +242,7 @@ if ($state -eq "absent") {
}
} else {
# validate if scope is set
if ($scope -eq $null) {
if ($null -eq $scope) {
Fail-Json $result "scope must be set when state=present and the group doesn't exist"
}

Expand All @@ -251,34 +251,34 @@ if ($state -eq "absent") {
$add_args.Name = $name
$add_args.GroupScope = $scope

if ($description -ne $null) {
if ($null -ne $description) {
$add_args.Description = $description
$diff_text += "+Description = $description`n"
}

if ($display_name -ne $null) {
if ($null -ne $display_name) {
$add_args.DisplayName = $display_name
$diff_text += "+DisplayName = $display_name`n"
}

if ($category -ne $null) {
if ($null -ne $category) {
$add_args.GroupCategory = $category
$diff_text += "+GroupCategory = $category`n"
}

if ($managed_by -ne $null) {
if ($null -ne $managed_by) {
$add_args.ManagedBy = $managed_by
$diff_text += "+ManagedBy = $managed_by`n"
}

if ($attributes -ne $null) {
if ($null -ne $attributes) {
$add_args.OtherAttributes = $attributes
foreach ($attribute in $attributes.GetEnumerator()) {
$diff_text += "+$($attribute.Name) = $($attribute.Value)`n"
}
}

if ($organizational_unit -ne $null) {
if ($null -ne $organizational_unit) {
$add_args.Path = $organizational_unit
$diff_text += "+Path = $organizational_unit`n"
}
Expand All @@ -292,12 +292,12 @@ if ($state -eq "absent") {
}

# set the protection value
if ($protect -ne $null) {
if ($null -ne $protect) {
if (-not $check_mode) {
$group = Get-ADGroup -Identity $name -Properties * @extra_args
}
$existing_protection_value = $group.ProtectedFromAccidentalDeletion
if ($existing_protection_value -eq $null) {
if ($null -eq $existing_protection_value) {
$existing_protection_value = $false
}
if ($existing_protection_value -ne $protect) {
Expand All @@ -311,7 +311,7 @@ if ($state -eq "absent") {
}
}

if ($diff_mode -and $diff_text -ne $null) {
if ($diff_mode -and $null -ne $diff_text) {
$result.diff.prepared = $diff_text
}

Expand All @@ -329,7 +329,7 @@ if ($state -eq "absent") {
$result.group_scope = ($group.GroupScope).ToString()
$result.category = ($group.GroupCategory).ToString()

if ($attributes -ne $null) {
if ($null -ne $attributes) {
$result.attributes = @{}
foreach ($attribute in $attributes.GetEnumerator()) {
$attribute_name = $attribute.Name
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/windows/win_domain_membership.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Try {
Write-DebugLog "adding hostname change to domain-join args"
$join_args.new_hostname = $hostname
}
If($domain_ou_path -ne $null){ # If OU Path is not empty
If($null -ne $domain_ou_path){ # If OU Path is not empty
Write-DebugLog "adding domain_ou_path to domain-join args"
$join_args.domain_ou_path = $domain_ou_path
}
Expand Down