-
Notifications
You must be signed in to change notification settings - Fork 88
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
Common: Added Test-IPAddress function #449
Common: Added Test-IPAddress function #449
Conversation
Hi @valainisgt - awesome stuff! Thank you for submitting this. Looks like there a few tests to fix up, nothing major:
Let me know if you need a hand looking into these. |
…sts to use necessary common localization strings.
…o use necessary common localization strings.
…ecessary common localization strings.
…sary common localization strings.
Thanks for fixing tests @valainisgt - I'll get onto the review tonight. This function may also be a candidate for moving out into the wider DscResource.Common module to share among multiple resources. Tagging @johlju. |
This is cool! I was just looking for a helper function just like this one. :) |
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.
Made a couple of comments.
Reviewable status: 0 of 16 files reviewed, 3 unresolved discussions (waiting on @PlagueHO and @valainisgt)
source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1, line 1423 at r3 (raw file):
Test-IPAddress
Since this function does not return anything, but throws an exception if the test fails I would suggest to rename this function to Assert-IPAddress
source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1, line 1431 at r3 (raw file):
$AddressFamily
Suggest that this property should not be mandatory. If it is passed the additional test can be done to validate the IP adress belongs to the correct family.
source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1, line 1438 at r3 (raw file):
TryParse($Address, [ref]0)))
We can instead use [System.Net.IPAddress]::TryParse($Address, [ref] $ipAddress)
. If the parse succeeds then the IP adress is assigned to $ipAddress
. We can then use the property $ipAddress.AddressFamily
to do the additional validation for address family below (might simplify the logic?).
IPv6:
AddressFamily : InterNetworkV6
ScopeId : 0
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
IsIPv6Teredo : False
IsIPv4MappedToIPv6 : False
Address :
IPAddressToString : ::1
IPv4:
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
IsIPv6Teredo : False
IsIPv4MappedToIPv6 : False
Address : 16843009
IPAddressToString : 1.1.1.1
@valainisgt would you like to submit the helper function |
@johlju absolutely. I will get a you a PR soon. |
…ed failing tests around this change
…ss. This parsed address can later be used for address family validation.
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.
@valainisgt awesome! Tag me when you sent in the PR in DscResource.Common and I will review as soon as I can. :)
Another tiny comment.
Reviewable status: 0 of 16 files reviewed, 2 unresolved discussions (waiting on @PlagueHO and @valainisgt)
source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1, line 1449 at r4 (raw file):
-and ($AddressFamily -ne 'IPv4')
Instead of this evaluation we could use switch ($AddressFamily)
so that we only evaluate the required address family and not both each time.
Would work with if ($AddressFamily -eq 'IPv4')
too.
source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1, line 1457 at r4 (raw file):
-and ($AddressFamily -ne 'IPv6'
Same as the previous comment.
Hi @valainisgt - It looks like the unit tests on WS2019 are failing. I'm not sure why however, so I'm kicking them off 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 1 of 8 files at r1, 8 of 9 files at r2, 6 of 7 files at r4, 1 of 1 files at r5.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @valainisgt)
source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1, line 1414 at r5 (raw file):
<# .SYNOPSIS Check the Address details are valid and do not conflict with Address family.
Nit pick: Can you indent this (and the ones following) - just for consistency.
E.g.
.SYSNOPSIS
Check the address...
.PARAMETER AddressFamily
IP Address....
source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1, line 1432 at r5 (raw file):
[System.String] $AddressFamily, [Parameter(Mandatory = $true)]
Can you add a blank line before this one.
source/Modules/NetworkingDsc.Common/NetworkingDsc.Common.psm1, line 1439 at r5 (raw file):
[System.Net.IPAddress] $ipAddress = $null if (-not ([System.Net.IPAddress]::TryParse($Address, [ref] $ipAddress)))
Can you add a blank line before this one?
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.
I havd resolved my comments, so I leave the rest of the PR to @PlagueHO. Great work @valainisgt !
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @valainisgt)
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 r6.
Reviewable status: complete! all files reviewed, all discussions resolved
@johlju - can you tick off your approval on this one? |
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 8 files at r1, 8 of 9 files at r2, 4 of 7 files at r4, 1 of 1 files at r6.
Reviewable status: complete! all files reviewed, all discussions resolved
@PlagueHO signed off and merged. @valainisgt Thank you for this! Awesome work on this as well, add again thanks for adding it to DscResource.Common. |
Pull Request (PR) description
Refactored code from DefaultGatewayAddress, DnsServerAddress, IPAddress, and Route resources to use a common function for validating an IP Address.
This Pull Request (PR) fixes the following issues
Fixes #408
Task list
Entry should say what was changed, and how that affects users (if applicable).
and comment-based help.
This change is