Skip to content

Commit

Permalink
Incorporated review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ykuijs committed Jun 9, 2021
1 parent f6dbc53 commit 15fdac5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,52 +149,49 @@ function Get-TargetResource
}

Write-Verbose -Message "Checking Farm account permissions"
$correctFarmAccountPermissions = $true
$farmAccountPermissionsNeedCorrecting = $false

$farmAccount = (Get-SPFarm).DefaultServiceAccount.Name
$dbServer = $serviceApp.SearchAdminDatabase.NormalizedDataSource

Write-Verbose -Message "Checking Admin Database"
$adminDB = $serviceApp.SearchAdminDatabase.Name
if ($correctFarmAccountPermissions -eq $true)
{
$correctFarmAccountPermissions = Confirm-UserIsDBOwner -SQLServer $dbServer `
$farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $adminDB `
-User $farmAccount
}
-User $farmAccount) -eq $false

Write-Verbose -Message "Checking Analytics reporting Database"
$analyticsDB = "$($adminDB)_AnalyticsReportingStore"
if ($correctFarmAccountPermissions -eq $true)
if ($farmAccountPermissionsNeedCorrecting -eq $false)
{
$correctFarmAccountPermissions = Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $analyticsDB `
-User $farmAccount
$farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $analyticsDB `
-User $farmAccount) -eq $false
}

Write-Verbose -Message "Checking Crawl Database(s)"
if ($correctFarmAccountPermissions -eq $true)
if ($farmAccountPermissionsNeedCorrecting -eq $false)
{
foreach ($database in (Get-SPEnterpriseSearchCrawlDatabase -SearchApplication $serviceApp))
{
$crawlDB = $database.Database.Name
$dbServer = $database.Database.NormalizedDataSource
$correctFarmAccountPermissions = Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $crawlDB `
-User $farmAccount
$farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $crawlDB `
-User $farmAccount) -eq $false
}
}

Write-Verbose -Message "Checking Links Database(s)"
if ($correctFarmAccountPermissions -eq $true)
if ($farmAccountPermissionsNeedCorrecting -eq $false)
{
foreach ($database in (Get-SPEnterpriseSearchLinksDatabase -SearchApplication $serviceApp))
{
$linksDB = $database.Database.Name
$dbServer = $database.Database.NormalizedDataSource
$correctFarmAccountPermissions = Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $linksDB `
-User $farmAccount
$farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $linksDB `
-User $farmAccount) -eq $false
}
}

Expand All @@ -209,7 +206,7 @@ function Get-TargetResource
DefaultContentAccessAccount = $defaultAccount
CloudIndex = $cloudIndex
AlertsEnabled = $serviceApp.AlertsEnabled
FixFarmAccountPermissions = $correctFarmAccountPermissions
FixFarmAccountPermissions = $farmAccountPermissionsNeedCorrecting
}
return $returnVal
}
Expand Down Expand Up @@ -510,7 +507,7 @@ function Set-TargetResource
# Only check and correct when Ensure=Present, FixFarmAccountPermissions=True and the permissions are incorrect
if ($Ensure -eq "Present" -and `
$FixFarmAccountPermissions -eq $true -and `
$result.FixFarmAccountPermissions -eq $false)
$result.FixFarmAccountPermissions -eq $true)
{
Write-Verbose -Message "Fixing database permissions for Search Service Application $Name"
Invoke-SPDscCommand -Credential $InstallAccount `
Expand Down Expand Up @@ -708,7 +705,7 @@ function Test-TargetResource

if ($FixFarmAccountPermissions -eq $true)
{
if ($CurrentValues.FixFarmAccountPermissions -eq $false)
if ($CurrentValues.FixFarmAccountPermissions -eq $true)

This comment has been minimized.

Copy link
@shurick81

shurick81 Aug 20, 2021

That does not look logically

{
$message = ("FixFarmAccountPermissions is set to True, but the Search databases " + `
"do not have the correct permissions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ try
}

It "Should return FixFarmAccountPermissions=False from the get method" {
(Get-TargetResource @testParams).FixFarmAccountPermissions | Should -Be $false
(Get-TargetResource @testParams).FixFarmAccountPermissions | Should -Be $true
Assert-MockCalled Confirm-UserIsDBOwner
}

Expand Down

0 comments on commit 15fdac5

Please sign in to comment.