From 857cefb2d1bb3227084e10a31dd49bd93e320433 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Thu, 25 Apr 2019 12:02:19 +0200 Subject: [PATCH] SqlServerPermission: Added localization (#1328) - Changes to SqlServerPermission - Added en-US localization (issue #619). --- CHANGELOG.md | 2 ++ .../MSFT_SqlServerPermission.psm1 | 28 ++++++++++++++----- .../MSFT_SqlServerPermission.strings.psd1 | 9 ++++++ .../en-US/DscResource.Common.strings.psd1 | 4 --- .../sv-SE/DscResource.Common.strings.psd1 | 4 --- Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 | 4 +-- 6 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 DSCResources/MSFT_SqlServerPermission/en-US/MSFT_SqlServerPermission.strings.psd1 diff --git a/CHANGELOG.md b/CHANGELOG.md index d43701bc8..24009aa23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 b/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 index e458479a7..fdad8738d 100644 --- a/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 +++ b/DSCResources/MSFT_SqlServerPermission/MSFT_SqlServerPermission.psm1 @@ -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). @@ -47,7 +49,9 @@ function Get-TargetResource $Permission ) - New-VerboseMessage -Message "Enumerating permissions for $Principal" + Write-Verbose -Message ( + $script:localizedData.EnumeratingPermission -f $Principal + ) try { @@ -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 @{ @@ -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 + ) } } @@ -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 diff --git a/DSCResources/MSFT_SqlServerPermission/en-US/MSFT_SqlServerPermission.strings.psd1 b/DSCResources/MSFT_SqlServerPermission/en-US/MSFT_SqlServerPermission.strings.psd1 new file mode 100644 index 000000000..df3d1217a --- /dev/null +++ b/DSCResources/MSFT_SqlServerPermission/en-US/MSFT_SqlServerPermission.strings.psd1 @@ -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}'. +'@ diff --git a/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 b/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 index 1a9799400..803740be0 100644 --- a/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 +++ b/Modules/DscResource.Common/en-US/DscResource.Common.strings.psd1 @@ -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}'. diff --git a/Modules/DscResource.Common/sv-SE/DscResource.Common.strings.psd1 b/Modules/DscResource.Common/sv-SE/DscResource.Common.strings.psd1 index dd7c9d056..fc258473a 100644 --- a/Modules/DscResource.Common/sv-SE/DscResource.Common.strings.psd1 +++ b/Modules/DscResource.Common/sv-SE/DscResource.Common.strings.psd1 @@ -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. diff --git a/Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 b/Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 index 92007b2c8..a27e484ec 100644 --- a/Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlServerPermission.Tests.ps1 @@ -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) } } } @@ -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) } } }