Skip to content

DnsClientNrptGlobal-DnsClientNrptRule: New resources #533

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

Merged
merged 36 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d5384f9
Add DnsClientNrptGlobal and DnsClientNrptRule resources
webalexeu Mar 10, 2025
956ad45
Update documentation
webalexeu Mar 10, 2025
24b2073
Add DnsClientNrptGlobal unit testing
webalexeu Mar 10, 2025
550555f
Add DnsClientNrptRule integration tests
webalexeu Mar 11, 2025
0fa9796
Add DnsClientNrptRule unit testing
webalexeu Mar 11, 2025
cb8a4b3
Merge branch 'main' into feat/add_DnsClientNrpt
johlju Mar 16, 2025
2efc6e0
Moving to Pester 5 tests
webalexeu Mar 17, 2025
bf83cf2
Fixing tests
webalexeu Mar 17, 2025
dcd14ff
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
ee62220
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
c6477af
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
dadd413
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
060abf6
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
36ece96
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
24a291d
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
0b5c524
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
b4c94e1
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
8d5a0b0
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
d9ff741
Switch Nrpt Global tests to Pester 5
webalexeu Mar 17, 2025
a658a2f
Switch Nrpt integration tests to Pester 5
webalexeu Mar 17, 2025
3c1dae5
Switch Nrpt integration tests to Pester 5
webalexeu Mar 17, 2025
507b9d5
Switch Nrpt integration tests to Pester 5
webalexeu Mar 17, 2025
754aeb4
Switch Nrpt integration tests to Pester 5
webalexeu Mar 17, 2025
21b366d
Switch Nrpt integration tests to Pester 5
webalexeu Mar 17, 2025
fdb5f44
Switch Nrpt integration tests to Pester 5
webalexeu Mar 17, 2025
f058404
Switch Nrpt integration tests to Pester 5
webalexeu Mar 17, 2025
d771795
Switch Nrpt integration tests to Pester 5
webalexeu Mar 17, 2025
f516d86
Fix syntax statement
webalexeu Mar 17, 2025
fda08d2
Fix syntax statement
webalexeu Mar 17, 2025
1ea4094
Generate new GUID for examples
webalexeu Mar 17, 2025
d63e72b
Add ValidateSet for NRPT global
webalexeu Mar 17, 2025
9f051d2
Review documentation/syntax
webalexeu Mar 18, 2025
36e2b39
Improve code based on review
webalexeu Mar 24, 2025
e6819ed
Fix syntax
webalexeu Mar 24, 2025
d16f191
Fix syntax
webalexeu Mar 24, 2025
951dcaf
Syntax + documentation
webalexeu Apr 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Added the following resources:
- **DnsClientNrptGlobal**: Configure DNS Client global Name Resolution Policy Table (NRPT) settings.
- **DnsClientNrptRule**: Sets a DNS Client NRPT rule on a node.

- Updated CHANGELOG.md
- Renamed NetworkingDSc to NetworkingDsc in CHANGELOG.md - fixes [Issue #513](https://github.com/dsccommunity/NetworkingDsc/issues/513).
- CI Pipeline
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The **NetworkingDsc** module contains the following resources:

- **DefaultGatewayAddress**: Sets a node's default gateway address.
- **DnsClientGlobalSetting**: Configure DNS client global settings.
- **DnsClientNrptGlobal**: Configure DNS client global Name Resolution Policy Table (NRPT) settings.
- **DnsClientNrptRule**: Sets a DNS client NRPT rule on a node.
- **DnsConnectionSuffix**: Sets a node's network interface
connection-specific DNS suffix.
- **DnsServerAddress**: Sets a node's DNS server address(s).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@{
ParameterList = @(
@{
Name = 'EnableDAForAllNetworks'
Type = 'String'
},
@{
Name = 'QueryPolicy'
Type = 'String'
},
@{
Name = 'SecureNameQueryFallback'
Type = 'String'
}
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'

# Import the Networking Common Modules
Import-Module -Name (Join-Path -Path $modulePath `
-ChildPath (Join-Path -Path 'NetworkingDsc.Common' `
-ChildPath 'NetworkingDsc.Common.psm1'))

Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common')

# Import Localization Strings
$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'

<#
This is an array of all the parameters used by this resource.
#>
$resourceData = Import-LocalizedData `
-BaseDirectory $PSScriptRoot `
-FileName 'DSC_DnsClientNrptGlobal.data.psd1'

# This must be a script parameter so that it is accessible
$script:parameterList = $resourceData.ParameterList

<#
.SYNOPSIS
Returns the current DNS Client Nrpt Global Settings.

.PARAMETER IsSingleInstance
Specifies the resource is a single instance, the value must be 'Yes'.
#>
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[System.String]
$IsSingleInstance
)

Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($script:localizedData.GettingDnsClientNrptGlobalMessage)
) -join '' )

# Get the current DNS Client Global Settings
$DnsClientNrptGlobal = Get-DnsClientNrptGlobal `
-ErrorAction Stop

# Generate the return object.
$returnValue = @{
IsSingleInstance = 'Yes'
}

foreach ($parameter in $script:parameterList)
{
$returnValue += @{
$parameter.Name = $DnsClientNrptGlobal.$($parameter.name)
}
} # foreach

return $returnValue
} # Get-TargetResource

<#
.SYNOPSIS
Sets the DNS Client NRPT Global Settings.

.PARAMETER IsSingleInstance
Specifies the resource is a single instance, the value must be 'Yes'.

.PARAMETER EnableDAForAllNetworks
Specifies DirectAccess (DA) settings.

.PARAMETER QueryPolicy.
Specifies the DNS client query policy.

.PARAMETER SecureNameQueryFallback
Specifies the DNS client name resolution fallback policy.
#>
function Set-TargetResource
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[System.String]
$IsSingleInstance,

[Parameter()]
[ValidateSet('EnableOnNetworkID', 'EnableAlways', 'Disable', 'DisableDA')]
[System.String]
$EnableDAForAllNetworks,

[Parameter()]
[System.String]
[ValidateSet('Disable', 'QueryIPv6Only', 'QueryBoth')]
$QueryPolicy,

[Parameter()]
[System.String]
[ValidateSet('Disable', 'FallbackSecure', 'FallbackUnsecure', 'FallbackPrivate')]
$SecureNameQueryFallback
)

Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($script:localizedData.SettingDnsClientNrptGlobalMessage)
) -join '' )

# Get the current DNS Client Nrpt Global Settings
$DnsClientNrptGlobal = Get-DnsClientNrptGlobal `
-ErrorAction Stop

# Generate a list of parameters that will need to be changed.
$changeParameters = @{}

foreach ($parameter in $script:parameterList)
{
$parameterSourceValue = $DnsClientNrptGlobal.$($parameter.name)
$parameterNewValue = (Get-Variable -Name ($parameter.name)).Value

if ($PSBoundParameters.ContainsKey($parameter.Name) `
-and (Compare-Object -ReferenceObject $parameterSourceValue -DifferenceObject $parameterNewValue -SyncWindow 0))
{
$changeParameters += @{
$($parameter.name) = $parameterNewValue
}

Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($script:localizedData.DnsClientNrptGlobalUpdateParameterMessage) `
-f $parameter.Name,($parameterNewValue -join ',')
) -join '' )
} # if
} # foreach

if ($changeParameters.Count -gt 0)
{
# Update any parameters that were identified as different
$null = Set-DnsClientNrptGlobal `
@ChangeParameters `
-ErrorAction Stop

Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($script:localizedData.DnsClientNrptGlobalUpdatedMessage)
) -join '' )
} # if
} # Set-TargetResource

<#
.SYNOPSIS
Tests the state of DNS Client Nrpt Global Settings.

.PARAMETER IsSingleInstance
Specifies the resource is a single instance, the value must be 'Yes'.

.PARAMETER EnableDAForAllNetworks
Specifies DirectAccess (DA) settings.

.PARAMETER QueryPolicy.
Specifies the DNS client query policy.

.PARAMETER SecureNameQueryFallback
Specifies the DNS client name resolution fallback policy.
#>
function Test-TargetResource
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory = $true)]
[ValidateSet('Yes')]
[System.String]
$IsSingleInstance,

[Parameter()]
[ValidateSet('EnableOnNetworkID', 'EnableAlways', 'Disable', 'DisableDA')]
[System.String]
$EnableDAForAllNetworks,

[Parameter()]
[System.String]
[ValidateSet('Disable', 'QueryIPv6Only', 'QueryBoth')]
$QueryPolicy,

[Parameter()]
[System.String]
[ValidateSet('Disable', 'FallbackSecure', 'FallbackUnsecure', 'FallbackPrivate')]
$SecureNameQueryFallback
)

Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
$($script:localizedData.TestingDnsClientNrptGlobalMessage)
) -join '' )

# Flag to signal whether settings are correct
$desiredConfigurationMatch = $true

# Get the current DNS Client Nrpt Global Settings
$DnsClientNrptGlobal = Get-DnsClientNrptGlobal `
-ErrorAction Stop

# Check each parameter
foreach ($parameter in $script:parameterList)
{
$parameterSourceValue = $DnsClientNrptGlobal.$($parameter.name)
$parameterNewValue = (Get-Variable -Name ($parameter.name)).Value

if ($parameterNewValue -ne $parameterSourceValue)
{
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
$($script:localizedData.DnsClientNrptGlobalParameterNeedsUpdateMessage) `
-f $parameter.Name, ($parameterSourceValue -join ','), ($parameterNewValue -join ',')
) -join '')
$desiredConfigurationMatch = $false
}

} # foreach

return $desiredConfigurationMatch
} # Test-TargetResource

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[ClassVersion("1.0.0.0"), FriendlyName("DnsClientNrptGlobal")]
class DSC_DnsClientNrptGlobal : OMI_BaseResource
{
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
[Write, Description("Specifies DirectAccess (DA) settings."), ValueMap{"EnableOnNetworkID", "EnableAlways", "Disable", "DisableDA"},Values{"EnableOnNetworkID", "EnableAlways", "Disable", "DisableDA"}] string EnableDAForAllNetworks;
[Write, Description("Specifies the DNS client query policy."), ValueMap{"Disable", "QueryIPv6Only", "QueryBoth"},Values{"Disable", "QueryIPv6Only", "QueryBoth"}] string QueryPolicy;
[Write, Description("SecureNameQueryFallback."), ValueMap{"Disable", "FallbackSecure", "FallbackUnsecure", "FallbackPrivate"},Values{"Disable", "FallbackSecure", "FallbackUnsecure", "FallbackPrivate"}] string SecureNameQueryFallback;
};
3 changes: 3 additions & 0 deletions source/DSCResources/DSC_DnsClientNrptGlobal/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Description

This resource is used to control DNS Client NRPT Global Settings for a node.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Localized resources for DSC_DnsClientNrptGlobal

ConvertFrom-StringData @'
GettingDnsClientNrptGlobalMessage = Getting DNS Client NRPT Global Settings.
SettingDnsClientNrptGlobalMessage = Setting DNS Client NRPT Global Settings.
DnsClientNrptGlobalUpdateParameterMessage = Setting DNS Client NRPT Global Settings parameter {0} to "{1}".
DnsClientNrptGlobalUpdatedMessage = Setting DNS Client NRPT Global Settings updated.
TestingDnsClientNrptGlobalMessage = Testing DNS Client NRPT Global Settings.
DnsClientNrptGlobalParameterNeedsUpdateMessage = DNS Client NRPT Global Setting "{0}" is "{1}" but should be "{2}". Change required.
'@
Loading
Loading