-
Notifications
You must be signed in to change notification settings - Fork 20
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
Enhancing module #20
Enhancing module #20
Conversation
Add checks for null Access parameters and removed from collection if they were null.
Added checks to see if Access parameters were present in the collection but were null or empty. If they were null or empty, remove the variable from collection so when they are passed to New-SmbShare it wouldn't fail.
Review status: 0 of 1 files reviewed at latest revision, all discussions resolved. DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 189 at r1 (raw file):
Curious why we need to do this. If the parameter is not passed to Comments from Reviewable |
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. |
Holy cow, I did not see that anyone had looked at this! My apologies. If the parameters were empty or null, the setting was failing completely. If they weren't part of the parameters being passed in, then it safely applied what was being requested. |
Maybe we should use ValidateNotNullOrEmpty instead on the parameters? If we should not allow empty values, that should be changed on both the Set- and Test-TargetResource. Would that work for the intended behavior? |
Also, is there a scenario where any of the parameters need to be assigned an empty value? So we don't do a breaking change. |
The ValidateNotNullOrEmpty would prevent anyone passing in null or empty. The scenario that I am using is
In my data document, I may or may not have anything specified for ChangeAccess, for example, so that would be a null. I wanted the data document to be flexible enough so that you don't have to specify all of the different levels, only the ones you wanted to change. Does that make sense? |
Ah, I see what you are trying to do. I don't think this is the right approach. If a property should not be checked to be in a consistent state it should not be part of the configuration. This way if |
I think I understand, but I'm going to paraphrase to make sure we're on the same page. Given the scenario where User A has ChangeAccess and we set ChangeAccess to null, the configuration won't do anything with ChangeAccess and User A will retain the permission. Your point is that in this case, User A ChangeAccess should be removed, is that correct? |
I think User A's change access should be removed yes, because that is the desired state we want. Let say we add a share 'TestShare', and we say the |
Gotcha. You are correct, my solution does not currently handle that. The removing of the parameters is still necessary because the SMS Share cmdlets will fail otherwise. However, I need to change my solution so that users that have existing permissions that are not included in the specified desired state are added to the NoAccess collection, which will then remove their permissions. |
Refactored permissions section, moved removal of permissions outside of collection if statements so that permissions are always removed and then re-added if the collections are not null.
That is incorrect, adding them to the NoAccess list only sets them to an explicit Deny versus removing them from the list. I found that the original author checked to see if collection was null, if it wasn't, they removed all users with that access level and replaced it with the collection. I have moved the removal out of the if statement and have it removing and then adding if the collection has anything in it. This should ensure the correct desired state. |
Removed aliases ? and %, and replaced with spelled out operators.
Review status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @twerthi) a discussion (no related file): The unit tests should be added to Comments from Reviewable |
I've not done these before, so it might take a little while as I work it into my schedule. Thank you for providing the template that should help speed things up :) |
Not ready yet.
@johlju, I'm wondering if I can get a little guidance as I've not done this before. The template calls a function Initialize-TestEnvironment, which isn't included in the script, may I assume it's a known method that creates a test VM of some sort? If so, is there documentation that describes what this VM looks like in terms of drives so that I can perform the setup of a share to test with? |
@twerthi absolutely, happy too! 😃 Let me know if you have any further questions.. Tests are run using AppVeyor - AppVeyor provides build workers (VM's) and if not specified, by using Tests are started by appveyor.yml (AppVeyor control file) and tests is run under the test framework DscResources.Tests which is cloned on run-time (even when you run tests locally with For example, you can find the test run for your PR if you click 'Details' on this (just below here). In AppVeyor you could create a free account (using your GitHub account) and can connect your fork to AppVeyor (add your fork as a project under Projects in AppVeyor). That way you can test your working branches, and send in PR's when you see they are passing tests. There are two types of tests - unit test and integration tests. I will only expect you to write a unit test. But if you want to give an integration tests a go it would be much appreciated. Example of unit tests for a resource: https://github.com/PowerShell/SqlServerDsc/blob/dev/Tests/Unit/MSFT_SqlServerDatabaseMail.Tests.ps1 Example of integration tests for a resource: https://github.com/PowerShell/SqlServerDsc/blob/dev/Tests/Integration/MSFT_SqlServerDatabaseMail.Integration.Tests.ps1 and the accompanying configuration https://github.com/PowerShell/SqlServerDsc/blob/dev/Tests/Integration/MSFT_SqlServerDatabaseMail.config.ps1 I realized that we don't have that much information around this in DSC Resource Kit. But below is what I could find (created an issue to update the documentation). More information around AppVeyor: https://github.com/PowerShell/DscResources/blob/master/CONTRIBUTING.md#tests-in-appveyor Test guidelines: https://github.com/PowerShell/DscResources/blob/master/TestsGuidelines.md Test framework (just for reference, normally only necessary read for new resource modules): https://github.com/PowerShell/DscResource.Tests |
Ah!! Thank you, this helps tremendously! |
The pieces are finally fitting together in my head. I've only been able to work on this sporadically so it wasn't quite clicking. Spent some time on the 4th and I believe I understand now. Sorry it's taking so long. |
@twerthi No worries, take your time. 🙂 If you get stuck, or need pointers, ping me and I try to help the best I can. |
I understand, been trying not to bug you too much since I can see you cover quite a large range of PRs. Think I got all requested changes complete. |
Is this one acceptable? |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 2 of 2 files at r18.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @twerthi)
DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 402 at r18 (raw file):
Foreach
foreach
(lower-case 'f')
DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 408 at r18 (raw file):
if (($null -ne $differences) -and ($differences.Length -gt 0))
We should not need to enclose the evaluations in parenthesis?
This should do?
if ($null -ne $differences -and $differences.Length -gt 0)
DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 410 at r18 (raw file):
-Verbose
We should only output verbose messages when the user want it, when they do for example Start-DscConfiguration -Verbose
. So it should not default to print the verbose messages. I think we can remove -Verbose
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 1 of 2 files reviewed, 3 unresolved discussions (waiting on @johlju)
DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 402 at r18 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
Foreach
foreach
(lower-case 'f')
Done.
DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 408 at r18 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
if (($null -ne $differences) -and ($differences.Length -gt 0))
We should not need to enclose the evaluations in parenthesis?
This should do?
if ($null -ne $differences -and $differences.Length -gt 0)
I'm used to C# syntax, is this considered bad practice?
DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 410 at r18 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
-Verbose
We should only output verbose messages when the user want it, when they do for example
Start-DscConfiguration -Verbose
. So it should not default to print the verbose messages. I think we can remove-Verbose
here?
In a previous comment, you'd asked that the differences be displayed. I could not find another way to have the data be written to the DSC output from within a function call. If there is another/better way to do this, please let me know and I'll update :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r19.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @twerthi)
DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 408 at r18 (raw file):
Previously, twerthi (Shawn Sesna) wrote…
I'm used to C# syntax, is this considered bad practice?
It good as-is.
DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 410 at r18 (raw file):
Previously, twerthi (Shawn Sesna) wrote…
In a previous comment, you'd asked that the differences be displayed. I could not find another way to have the data be written to the DSC output from within a function call. If there is another/better way to do this, please let me know and I'll update :)
Sorry, let me explain better this time. It's correct to write out the differences with Write-Verbose
, but the parameter -Verbose
should not be used. The parameter -Verbose
forces the verbose output regardless if the user wants verbose output or not.
If we remove the parameter -Verbose
then the verbose output will be seen when the user asks for verbose output.
With my initial comment I meant that this should be written out, but only when the users asks for the output.
Also so now that it was missing the Message named parameter. SO if you change to this, then it's all good,
$differences | ForEach-Object { Write-Verbose -Message $_ }
Changed verbose to message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @johlju)
DscResources/MSFT_xSmbShare/MSFT_xSmbShare.psm1, line 410 at r18 (raw file):
Previously, johlju (Johan Ljunggren) wrote…
Sorry, let me explain better this time. It's correct to write out the differences with
Write-Verbose
, but the parameter-Verbose
should not be used. The parameter-Verbose
forces the verbose output regardless if the user wants verbose output or not.
If we remove the parameter-Verbose
then the verbose output will be seen when the user asks for verbose output.
With my initial comment I meant that this should be written out, but only when the users asks for the output.Also so now that it was missing the Message named parameter. SO if you change to this, then it's all good,
$differences | ForEach-Object { Write-Verbose -Message $_ }
Done.
I had the -Message backwards.
We all good now? |
Checking in, anything that I'm missing? |
On it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r20.
Reviewable status: complete! all files reviewed, all discussions resolved
@gaelcolas can you merge this one as I have no permission to merge. :) |
@twerthi can you add an entry in the changelog describing your change? In the unreleased section on the reader.md. I'll use it to merge the pr first thing tomorrow. |
This project doesn't appear to have a CHANGELOG.md file in the root, do I need to add one or is it located somewhere else? |
@twerthi some repos have not split the change log into a seperate file. Then you find the unreleased section under the header changelog in the file README.md. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @twerthi, I've made the update to the changelog and made some cosmetic changes (variable capitalization).
I'll merge this after the tests passes.
Thanks again for the PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r18, 2 of 2 files at r21.
Reviewable status: complete! all files reviewed, all discussions resolved
Oh! I had fully planned on making the updates as requested, but got busy at work and am prepping for an event. Thank you very much for taking care of that :) |
No worries. Given we're all in different timezone I thought it'd be nice to close it before the monthly release tomorrow. |
Added the ability to have all Access variables present, but allow for null or empty.
This change is