Skip to content

Commit 3cacd0c

Browse files
webalexeujohlju
andauthored
DnsClientNrptGlobal-DnsClientNrptRule: New resources (#533)
* Add DnsClientNrptGlobal and DnsClientNrptRule resources * Update documentation * Add DnsClientNrptGlobal unit testing * Add DnsClientNrptRule integration tests * Add DnsClientNrptRule unit testing * Merge branch 'main' into feat/add_DnsClientNrpt * Moving to Pester 5 tests * Fixing tests * Switch Nrpt Global tests to Pester 5 * Switch Nrpt Global tests to Pester 5 * Switch Nrpt Global tests to Pester 5 * Switch Nrpt Global tests to Pester 5 * Switch Nrpt Global tests to Pester 5 * Switch Nrpt Global tests to Pester 5 * Switch Nrpt Global tests to Pester 5 * Switch Nrpt Global tests to Pester 5 * Switch Nrpt Global tests to Pester 5 * Switch Nrpt Global tests to Pester 5 * Switch Nrpt Global tests to Pester 5 * Switch Nrpt integration tests to Pester 5 * Switch Nrpt integration tests to Pester 5 * Switch Nrpt integration tests to Pester 5 * Switch Nrpt integration tests to Pester 5 * Switch Nrpt integration tests to Pester 5 * Switch Nrpt integration tests to Pester 5 * Switch Nrpt integration tests to Pester 5 * Switch Nrpt integration tests to Pester 5 * Fix syntax statement * Fix syntax statement * Generate new GUID for examples * Add ValidateSet for NRPT global * Review documentation/syntax * Improve code based on review * Fix syntax * Fix syntax * Syntax + documentation Co-Authored-By: Johan Ljunggren <johlju@users.noreply.github.com>
1 parent c165bcc commit 3cacd0c

21 files changed

Lines changed: 2309 additions & 0 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
### Changed
99

10+
- Added the following resources:
11+
- **DnsClientNrptGlobal**: Configure DNS Client global Name Resolution Policy Table (NRPT) settings.
12+
- **DnsClientNrptRule**: Sets a DNS Client NRPT rule on a node.
13+
1014
- Updated CHANGELOG.md
1115
- Renamed NetworkingDSc to NetworkingDsc in CHANGELOG.md - fixes [Issue #513](https://github.com/dsccommunity/NetworkingDsc/issues/513).
1216
- CI Pipeline

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ The **NetworkingDsc** module contains the following resources:
3232

3333
- **DefaultGatewayAddress**: Sets a node's default gateway address.
3434
- **DnsClientGlobalSetting**: Configure DNS client global settings.
35+
- **DnsClientNrptGlobal**: Configure DNS client global Name Resolution Policy Table (NRPT) settings.
36+
- **DnsClientNrptRule**: Sets a DNS client NRPT rule on a node.
3537
- **DnsConnectionSuffix**: Sets a node's network interface
3638
connection-specific DNS suffix.
3739
- **DnsServerAddress**: Sets a node's DNS server address(s).
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@{
2+
ParameterList = @(
3+
@{
4+
Name = 'EnableDAForAllNetworks'
5+
Type = 'String'
6+
},
7+
@{
8+
Name = 'QueryPolicy'
9+
Type = 'String'
10+
},
11+
@{
12+
Name = 'SecureNameQueryFallback'
13+
Type = 'String'
14+
}
15+
)
16+
}
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'
2+
3+
# Import the Networking Common Modules
4+
Import-Module -Name (Join-Path -Path $modulePath `
5+
-ChildPath (Join-Path -Path 'NetworkingDsc.Common' `
6+
-ChildPath 'NetworkingDsc.Common.psm1'))
7+
8+
Import-Module -Name (Join-Path -Path $modulePath -ChildPath 'DscResource.Common')
9+
10+
# Import Localization Strings
11+
$script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
12+
13+
<#
14+
This is an array of all the parameters used by this resource.
15+
#>
16+
$resourceData = Import-LocalizedData `
17+
-BaseDirectory $PSScriptRoot `
18+
-FileName 'DSC_DnsClientNrptGlobal.data.psd1'
19+
20+
# This must be a script parameter so that it is accessible
21+
$script:parameterList = $resourceData.ParameterList
22+
23+
<#
24+
.SYNOPSIS
25+
Returns the current DNS Client Nrpt Global Settings.
26+
27+
.PARAMETER IsSingleInstance
28+
Specifies the resource is a single instance, the value must be 'Yes'.
29+
#>
30+
function Get-TargetResource
31+
{
32+
[CmdletBinding()]
33+
[OutputType([System.Collections.Hashtable])]
34+
param
35+
(
36+
[Parameter(Mandatory = $true)]
37+
[ValidateSet('Yes')]
38+
[System.String]
39+
$IsSingleInstance
40+
)
41+
42+
Write-Verbose -Message ( @(
43+
"$($MyInvocation.MyCommand): "
44+
$($script:localizedData.GettingDnsClientNrptGlobalMessage)
45+
) -join '' )
46+
47+
# Get the current DNS Client Global Settings
48+
$DnsClientNrptGlobal = Get-DnsClientNrptGlobal `
49+
-ErrorAction Stop
50+
51+
# Generate the return object.
52+
$returnValue = @{
53+
IsSingleInstance = 'Yes'
54+
}
55+
56+
foreach ($parameter in $script:parameterList)
57+
{
58+
$returnValue += @{
59+
$parameter.Name = $DnsClientNrptGlobal.$($parameter.name)
60+
}
61+
} # foreach
62+
63+
return $returnValue
64+
} # Get-TargetResource
65+
66+
<#
67+
.SYNOPSIS
68+
Sets the DNS Client NRPT Global Settings.
69+
70+
.PARAMETER IsSingleInstance
71+
Specifies the resource is a single instance, the value must be 'Yes'.
72+
73+
.PARAMETER EnableDAForAllNetworks
74+
Specifies DirectAccess (DA) settings.
75+
76+
.PARAMETER QueryPolicy.
77+
Specifies the DNS client query policy.
78+
79+
.PARAMETER SecureNameQueryFallback
80+
Specifies the DNS client name resolution fallback policy.
81+
#>
82+
function Set-TargetResource
83+
{
84+
[CmdletBinding()]
85+
param
86+
(
87+
[Parameter(Mandatory = $true)]
88+
[ValidateSet('Yes')]
89+
[System.String]
90+
$IsSingleInstance,
91+
92+
[Parameter()]
93+
[ValidateSet('EnableOnNetworkID', 'EnableAlways', 'Disable', 'DisableDA')]
94+
[System.String]
95+
$EnableDAForAllNetworks,
96+
97+
[Parameter()]
98+
[System.String]
99+
[ValidateSet('Disable', 'QueryIPv6Only', 'QueryBoth')]
100+
$QueryPolicy,
101+
102+
[Parameter()]
103+
[System.String]
104+
[ValidateSet('Disable', 'FallbackSecure', 'FallbackUnsecure', 'FallbackPrivate')]
105+
$SecureNameQueryFallback
106+
)
107+
108+
Write-Verbose -Message ( @(
109+
"$($MyInvocation.MyCommand): "
110+
$($script:localizedData.SettingDnsClientNrptGlobalMessage)
111+
) -join '' )
112+
113+
# Get the current DNS Client Nrpt Global Settings
114+
$DnsClientNrptGlobal = Get-DnsClientNrptGlobal `
115+
-ErrorAction Stop
116+
117+
# Generate a list of parameters that will need to be changed.
118+
$changeParameters = @{}
119+
120+
foreach ($parameter in $script:parameterList)
121+
{
122+
$parameterSourceValue = $DnsClientNrptGlobal.$($parameter.name)
123+
$parameterNewValue = (Get-Variable -Name ($parameter.name)).Value
124+
125+
if ($PSBoundParameters.ContainsKey($parameter.Name) `
126+
-and (Compare-Object -ReferenceObject $parameterSourceValue -DifferenceObject $parameterNewValue -SyncWindow 0))
127+
{
128+
$changeParameters += @{
129+
$($parameter.name) = $parameterNewValue
130+
}
131+
132+
Write-Verbose -Message ( @(
133+
"$($MyInvocation.MyCommand): "
134+
$($script:localizedData.DnsClientNrptGlobalUpdateParameterMessage) `
135+
-f $parameter.Name,($parameterNewValue -join ',')
136+
) -join '' )
137+
} # if
138+
} # foreach
139+
140+
if ($changeParameters.Count -gt 0)
141+
{
142+
# Update any parameters that were identified as different
143+
$null = Set-DnsClientNrptGlobal `
144+
@ChangeParameters `
145+
-ErrorAction Stop
146+
147+
Write-Verbose -Message ( @(
148+
"$($MyInvocation.MyCommand): "
149+
$($script:localizedData.DnsClientNrptGlobalUpdatedMessage)
150+
) -join '' )
151+
} # if
152+
} # Set-TargetResource
153+
154+
<#
155+
.SYNOPSIS
156+
Tests the state of DNS Client Nrpt Global Settings.
157+
158+
.PARAMETER IsSingleInstance
159+
Specifies the resource is a single instance, the value must be 'Yes'.
160+
161+
.PARAMETER EnableDAForAllNetworks
162+
Specifies DirectAccess (DA) settings.
163+
164+
.PARAMETER QueryPolicy.
165+
Specifies the DNS client query policy.
166+
167+
.PARAMETER SecureNameQueryFallback
168+
Specifies the DNS client name resolution fallback policy.
169+
#>
170+
function Test-TargetResource
171+
{
172+
[CmdletBinding()]
173+
[OutputType([System.Boolean])]
174+
param
175+
(
176+
[Parameter(Mandatory = $true)]
177+
[ValidateSet('Yes')]
178+
[System.String]
179+
$IsSingleInstance,
180+
181+
[Parameter()]
182+
[ValidateSet('EnableOnNetworkID', 'EnableAlways', 'Disable', 'DisableDA')]
183+
[System.String]
184+
$EnableDAForAllNetworks,
185+
186+
[Parameter()]
187+
[System.String]
188+
[ValidateSet('Disable', 'QueryIPv6Only', 'QueryBoth')]
189+
$QueryPolicy,
190+
191+
[Parameter()]
192+
[System.String]
193+
[ValidateSet('Disable', 'FallbackSecure', 'FallbackUnsecure', 'FallbackPrivate')]
194+
$SecureNameQueryFallback
195+
)
196+
197+
Write-Verbose -Message ( @(
198+
"$($MyInvocation.MyCommand): "
199+
$($script:localizedData.TestingDnsClientNrptGlobalMessage)
200+
) -join '' )
201+
202+
# Flag to signal whether settings are correct
203+
$desiredConfigurationMatch = $true
204+
205+
# Get the current DNS Client Nrpt Global Settings
206+
$DnsClientNrptGlobal = Get-DnsClientNrptGlobal `
207+
-ErrorAction Stop
208+
209+
# Check each parameter
210+
foreach ($parameter in $script:parameterList)
211+
{
212+
$parameterSourceValue = $DnsClientNrptGlobal.$($parameter.name)
213+
$parameterNewValue = (Get-Variable -Name ($parameter.name)).Value
214+
215+
if ($parameterNewValue -ne $parameterSourceValue)
216+
{
217+
Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): "
218+
$($script:localizedData.DnsClientNrptGlobalParameterNeedsUpdateMessage) `
219+
-f $parameter.Name, ($parameterSourceValue -join ','), ($parameterNewValue -join ',')
220+
) -join '')
221+
$desiredConfigurationMatch = $false
222+
}
223+
224+
} # foreach
225+
226+
return $desiredConfigurationMatch
227+
} # Test-TargetResource
228+
229+
Export-ModuleMember -Function *-TargetResource
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[ClassVersion("1.0.0.0"), FriendlyName("DnsClientNrptGlobal")]
2+
class DSC_DnsClientNrptGlobal : OMI_BaseResource
3+
{
4+
[Key, Description("Specifies the resource is a single instance, the value must be 'Yes'."), ValueMap{"Yes"}, Values{"Yes"}] String IsSingleInstance;
5+
[Write, Description("Specifies DirectAccess (DA) settings."), ValueMap{"EnableOnNetworkID", "EnableAlways", "Disable", "DisableDA"},Values{"EnableOnNetworkID", "EnableAlways", "Disable", "DisableDA"}] string EnableDAForAllNetworks;
6+
[Write, Description("Specifies the DNS client query policy."), ValueMap{"Disable", "QueryIPv6Only", "QueryBoth"},Values{"Disable", "QueryIPv6Only", "QueryBoth"}] string QueryPolicy;
7+
[Write, Description("SecureNameQueryFallback."), ValueMap{"Disable", "FallbackSecure", "FallbackUnsecure", "FallbackPrivate"},Values{"Disable", "FallbackSecure", "FallbackUnsecure", "FallbackPrivate"}] string SecureNameQueryFallback;
8+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Description
2+
3+
This resource is used to control DNS Client NRPT Global Settings for a node.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Localized resources for DSC_DnsClientNrptGlobal
2+
3+
ConvertFrom-StringData @'
4+
GettingDnsClientNrptGlobalMessage = Getting DNS Client NRPT Global Settings.
5+
SettingDnsClientNrptGlobalMessage = Setting DNS Client NRPT Global Settings.
6+
DnsClientNrptGlobalUpdateParameterMessage = Setting DNS Client NRPT Global Settings parameter {0} to "{1}".
7+
DnsClientNrptGlobalUpdatedMessage = Setting DNS Client NRPT Global Settings updated.
8+
TestingDnsClientNrptGlobalMessage = Testing DNS Client NRPT Global Settings.
9+
DnsClientNrptGlobalParameterNeedsUpdateMessage = DNS Client NRPT Global Setting "{0}" is "{1}" but should be "{2}". Change required.
10+
'@

0 commit comments

Comments
 (0)