Skip to content

Commit

Permalink
SqlServerPermission: Added localization (dsccommunity#1328)
Browse files Browse the repository at this point in the history
- Changes to SqlServerPermission
  - Added en-US localization (issue dsccommunity#619).
  • Loading branch information
johlju authored Apr 25, 2019
1 parent cce75a3 commit 857cefb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- Concatenated Robocopy localization strings ([issue #694](https://github.com/PowerShell/SqlServerDsc/issues/694)).
- Changes to SqlWaitForAG
- Added en-US localization ([issue #625](https://github.com/PowerShell/SqlServerDsc/issues/625)).
- Changes to SqlServerPermission
- Added en-US localization ([issue #619](https://github.com/PowerShell/SqlServerDsc/issues/619)).

## 12.4.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Import-Module -Name (Join-Path -Path $script:localizationModulePath -ChildPath '
$script:resourceHelperModulePath = Join-Path -Path $script:modulesFolderPath -ChildPath 'DscResource.Common'
Import-Module -Name (Join-Path -Path $script:resourceHelperModulePath -ChildPath 'DscResource.Common.psm1')

$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlServerPermission'

<#
.SYNOPSIS
Returns the current state of the permissions for the principal (login).
Expand Down Expand Up @@ -47,7 +49,9 @@ function Get-TargetResource
$Permission
)

New-VerboseMessage -Message "Enumerating permissions for $Principal"
Write-Verbose -Message (
$script:localizedData.EnumeratingPermission -f $Principal
)

try
{
Expand Down Expand Up @@ -83,7 +87,8 @@ function Get-TargetResource
}
catch
{
throw New-TerminatingError -ErrorType PermissionGetError -FormatArgs @($Principal) -ErrorCategory InvalidOperation -InnerException $_.Exception
$errorMessage = $script:localizedData.PermissionGetError -f $Principal
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}

return @{
Expand Down Expand Up @@ -161,25 +166,32 @@ function Set-TargetResource

if ($Ensure -eq 'Present')
{
Write-Verbose -Message ('Grant permission for ''{0}''' -f $Principal)
Write-Verbose -Message (
$script:localizedData.GrantPermission -f $Principal
)

$sqlServerObject.Grant($permissionSet, $Principal)
}
else
{
Write-Verbose -Message ('Revoke permission for ''{0}''' -f $Principal)
Write-Verbose -Message (
$script:localizedData.RevokePermission -f $Principal
)

$sqlServerObject.Revoke($permissionSet, $Principal)
}
}
catch
{
throw New-TerminatingError -ErrorType ChangingPermissionFailed -FormatArgs @($Principal) -ErrorCategory InvalidOperation -InnerException $_.Exception
$errorMessage = $script:localizedData.ChangingPermissionFailed -f $Principal
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}
}
else
{
New-VerboseMessage -Message "State is already $Ensure"
Write-Verbose -Message (
$script:localizedData.InDesiredState -f $Ensure
)
}
}

Expand Down Expand Up @@ -238,7 +250,9 @@ function Test-TargetResource
Permission = $Permission
}

New-VerboseMessage -Message "Verifying permissions for $Principal"
Write-Verbose -Message (
$script:localizedData.EvaluatingPermission -f $Principal
)

$getTargetResourceResult = Get-TargetResource @getTargetResourceParameters

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ConvertFrom-StringData @'
EnumeratingPermission = Enumerating permissions for '{0}'.
GrantPermission = Grant permission for '{0}'.
RevokePermission = Revoke permission for '{0}'.
ChangingPermissionFailed = Changing permission for principal '{0}' failed.
PermissionGetError = Unexpected result when trying to get permissions for '{0}'.
InDesiredState = The state is already {0}.
EvaluatingPermission = Determines the permissions for the principal '{0}'.
'@
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ ConvertFrom-StringData @'
EndpointErrorVerifyExist = Unexpected result when trying to verify existence of endpoint '{0}'.
EndpointFoundButWrongType = Endpoint '{0}' does exist, but it is not of type 'DatabaseMirroring'.
# Permission
PermissionGetError = Unexpected result when trying to get permissions for '{0}'.
ChangingPermissionFailed = Changing permission for principal '{0}' failed.
# AlwaysOnService
AlterAlwaysOnServiceFailed = Failed to ensure Always On is {0} on the instance '{1}'.
UnexpectedAlwaysOnStatus = The status of property Server.IsHadrEnabled was neither $true or $false. Status is '{0}'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ ConvertFrom-StringData @'
EndpointErrorVerifyExist = Unexpected result when trying to verify existence of endpoint '{0}'.
EndpointFoundButWrongType = Endpoint '{0}' does exist, but it is not of type 'DatabaseMirroring'.
# Permission
PermissionGetError = Unexpected result when trying to get permissions for '{0}'.
ChangingPermissionFailed = Changing permission for principal '{0}' failed.
# Configuration
ConfigurationOptionNotFound = Specified option '{0}' could not be found.
ConfigurationRestartRequired = Configuration option '{0}' has been updated, but a manual restart of SQL Server is required for it to take effect.
Expand Down
4 changes: 2 additions & 2 deletions Tests/Unit/MSFT_SqlServerPermission.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ try
throw 'Mocked error.'
}

{ Get-TargetResource @testParameters } | Should -Throw 'Unexpected result when trying to get permissions for ''COMPANY\SqlServiceAcct''. InnerException: Mocked error.'
{ Get-TargetResource @testParameters } | Should -Throw ($script:localizedData.PermissionGetError -f $mockPrincipal)
}
}
}
Expand Down Expand Up @@ -336,7 +336,7 @@ try
return $mockObjectSmoServer
} -Verifiable

{ Set-TargetResource @testParameters } | Should -Throw 'Changing permission for principal ''COMPANY\SqlServiceAcct'' failed. InnerException: Exception calling "Grant" with "2" argument(s): "Expected to get granteeName == ''COMPANY\OtherAccount''. But got ''COMPANY\SqlServiceAcct'''
{ Set-TargetResource @testParameters } | Should -Throw ($script:localizedData.ChangingPermissionFailed -f $mockPrincipal)
}
}
}
Expand Down

0 comments on commit 857cefb

Please sign in to comment.