Set-SqlDscServerPermission: Added support for assigning permissions to a server role#2061
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2061 +/- ##
====================================
Coverage 94% 94%
====================================
Files 105 105
Lines 8088 8089 +1
====================================
+ Hits 7661 7662 +1
Misses 427 427
🚀 New features to boost your workflow:
|
Set-SqlServerPermission: Added support for assigning permissions to a server role
johlju
left a comment
There was a problem hiding this comment.
Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @IAMJDA)
source/Classes/020.SqlPermission.ps1 line 373 at r1 (raw file):
New-InvalidOperationException -Message $missingPrincipalMessage }
We should not need this check at all since it is already evaluated in the Set-SqlDscServerPermission command. I rather see this change for the resource SqlPermission in a separate PR as we also need integration tests. Please revert the changes for this file and move it to a separate PR. 🙂
Code quote:
$testSqlDscIsPrincipalParameters = @{
ServerObject = $serverObject
Name = $this.Name
}
# This will test wether the principal exist.
$isLogin = Test-SqlDscIsLogin @testSqlDscIsPrincipalParameters
$isRole = Test-SqlDscIsRole @testSqlDscIsPrincipalParameters
if (-not $isLogin -and -not $isRole)
{
$missingPrincipalMessage = $this.localizedData.NameIsMissing -f @(
$this.Name,
$this.InstanceName
)
New-InvalidOperationException -Message $missingPrincipalMessage
}source/Public/Set-SqlDscServerPermission.ps1 line 107 at r1 (raw file):
if (-not $isLogin -and -not $isRole) { $missingPrincipalMessage = $script:localizedData.ServerPermission_MissingPrincipal -f $Name, $ServerObject.InstanceName
We need to update the localized string
Code quote:
ServerPermission_MissingPrincipalsource/Public/Set-SqlDscServerPermission.ps1 line 117 at r1 (raw file):
) ) return
We should not need return here as we throw a terminating error?
Code quote:
returntests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 line 430 at r1 (raw file):
Mock -CommandName Test-SqlDscIsRole -MockWith { return $false }
We should add a test that actually test the it is a role and not a login.
Code quote:
Mock -CommandName Test-SqlDscIsRole -MockWith {
return $false
}Set-SqlServerPermission: Added support for assigning permissions to a server roleSet-SqlDscServerPermission: Added support for assigning permissions to a server role
|
Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again. |
872d519 to
65f803c
Compare
65f803c to
3764562
Compare
Reworked based on review comments
IAMJDA
left a comment
There was a problem hiding this comment.
Reviewable status: 0 of 5 files reviewed, 4 unresolved discussions (waiting on @IAMJDA and @johlju)
source/Public/Set-SqlDscServerPermission.ps1 line 107 at r1 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
We need to update the localized string
Done.
source/Public/Set-SqlDscServerPermission.ps1 line 117 at r1 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
We should not need
returnhere as we throw a terminating error?
Done.
tests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 line 430 at r1 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
We should add a test that actually test the it is a role and not a login.
Done.
source/Classes/020.SqlPermission.ps1 line 373 at r1 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
We should not need this check at all since it is already evaluated in the
Set-SqlDscServerPermissioncommand. I rather see this change for the resourceSqlPermissionin a separate PR as we also need integration tests. Please revert the changes for this file and move it to a separate PR. 🙂
Will do
johlju
left a comment
There was a problem hiding this comment.
Just a tiny comment, then I think this is good to go. Great work!
Reviewed 5 of 5 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @IAMJDA)
tests/Unit/Public/Set-SqlDscServerPermission.Tests.ps1 line 53 at r1 (raw file):
Describe 'Set-SqlDscServerPermission' -Tag 'Public' { Context 'When the principal does not exist' {
Why was this Context removed? 🤔 It still worked pretty well to keep it, to indicate that we test when neither role or login exist?
Code quote:
Context 'When the principal does not exist' {|
Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again. |
johlju
left a comment
There was a problem hiding this comment.
Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @IAMJDA)
|
@IAMJDA I took this one over the finish line. Looking forwards to more PRs. Thank you. |
|
@johlju Thanks for completing it. Didn't had the chance to fix it in the last weeks 😔 |
Pull Request (PR) description
Updated Set-SqlDscServerPermission to be able to set permission on server roles. Adapted unit tests so they should continue to work but missing support for the new logic.
This Pull Request (PR) fixes the following issues
Set-SqlDscServerPermission: Not possible to set server permissions for a server role #2059Task list
file CHANGELOG.md. Entry should say what was changed and how that
affects users (if applicable), and reference the issue being resolved
(if applicable).
This change is