Skip to content

Commit

Permalink
Revert "Do not enforce reserved URLs when not supplied."
Browse files Browse the repository at this point in the history
This reverts commit f2d7347.
  • Loading branch information
randomnote1 authored and johlju committed Mar 26, 2023
1 parent ceb9a9b commit 7638ef9
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 115 deletions.
195 changes: 95 additions & 100 deletions source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,12 @@ function Get-TargetResource
Report Manager/Report Web App virtual directory name. Optional.
.PARAMETER ReportServerReservedUrl
Report Server URL reservations. Optional.
Report Server URL reservations. Optional. If not specified,
'http://+:80' URL reservation will be used.
.PARAMETER ReportsReservedUrl
Report Manager/Report Web App URL reservations.
Report Manager/Report Web App URL reservations. Optional.
If not specified, 'http://+:80' URL reservation will be used.
.PARAMETER HttpsCertificateThumbprint
The thumbprint of the certificate used to secure SSL communication.
Expand Down Expand Up @@ -384,11 +386,11 @@ function Set-TargetResource

[Parameter()]
[System.String[]]
$ReportServerReservedUrl,
$ReportServerReservedUrl = @('http://+:80'),

[Parameter()]
[System.String[]]
$ReportsReservedUrl,
$ReportsReservedUrl = @('http://+:80'),

[Parameter()]
[System.String]
Expand Down Expand Up @@ -848,103 +850,97 @@ function Set-TargetResource
#endregion Virtual Directories

#region Reserved URLs
if ( $PSBoundParameters.ContainsKey('EncryptionKeyBackupPath') )
{
$compareParameters = @{
ReferenceObject = $currentConfig.ReportServerReservedUrl
DifferenceObject = $ReportServerReservedUrl
}
$compareParameters = @{
ReferenceObject = $currentConfig.ReportServerReservedUrl
DifferenceObject = $ReportServerReservedUrl
}

if ( ($null -ne $ReportServerReservedUrl) -and ($null -ne (Compare-Object @compareParameters)) )
{
$restartReportingService = $true
if ( ($null -ne $ReportServerReservedUrl) -and ($null -ne (Compare-Object @compareParameters)) )
{
$restartReportingService = $true

$currentConfig.ReportServerReservedUrl | ForEach-Object -Process {
$invokeRsCimMethodParameters = @{
CimInstance = $reportingServicesData.Configuration
MethodName = 'RemoveURL'
Arguments = @{
Application = 'ReportServerWebService'
UrlString = $_
Lcid = $language
}
$currentConfig.ReportServerReservedUrl | ForEach-Object -Process {
$invokeRsCimMethodParameters = @{
CimInstance = $reportingServicesData.Configuration
MethodName = 'RemoveURL'
Arguments = @{
Application = 'ReportServerWebService'
UrlString = $_
Lcid = $language
}

Invoke-RsCimMethod @invokeRsCimMethodParameters
}

$ReportServerReservedUrl | ForEach-Object -Process {
Write-Verbose -Message "Adding report server URL reservation on $DatabaseServerName\$DatabaseInstanceName`: $_."
$invokeRsCimMethodParameters = @{
CimInstance = $reportingServicesData.Configuration
MethodName = 'ReserveUrl'
Arguments = @{
Application = 'ReportServerWebService'
UrlString = $_
Lcid = $language
}
}
Invoke-RsCimMethod @invokeRsCimMethodParameters
}

Invoke-RsCimMethod @invokeRsCimMethodParameters
$ReportServerReservedUrl | ForEach-Object -Process {
Write-Verbose -Message "Adding report server URL reservation on $DatabaseServerName\$DatabaseInstanceName`: $_."
$invokeRsCimMethodParameters = @{
CimInstance = $reportingServicesData.Configuration
MethodName = 'ReserveUrl'
Arguments = @{
Application = 'ReportServerWebService'
UrlString = $_
Lcid = $language
}
}

# Get the current configuration
$currentConfig = Get-TargetResource @getTargetResourceParameters
Write-Verbose -Message ( $script:localizedData.ReportingServicesIsInitialized -f $DatabaseServerName, $DatabaseInstanceName, $currentConfig.IsInitialized ) -Verbose
Invoke-RsCimMethod @invokeRsCimMethodParameters
}

# Get the current configuration
$currentConfig = Get-TargetResource @getTargetResourceParameters
Write-Verbose -Message ( $script:localizedData.ReportingServicesIsInitialized -f $DatabaseServerName, $DatabaseInstanceName, $currentConfig.IsInitialized ) -Verbose
}

if ( $PSBoundParameters.ContainsKey('ReportsReservedUrl') )
{
$compareParameters = @{
ReferenceObject = $currentConfig.ReportsReservedUrl
DifferenceObject = $ReportsReservedUrl
}
$compareParameters = @{
ReferenceObject = $currentConfig.ReportsReservedUrl
DifferenceObject = $ReportsReservedUrl
}

if ( ($null -ne $ReportsReservedUrl) -and ($null -ne (Compare-Object @compareParameters)) )
{
$restartReportingService = $true
if ( ($null -ne $ReportsReservedUrl) -and ($null -ne (Compare-Object @compareParameters)) )
{
$restartReportingService = $true

$currentConfig.ReportsReservedUrl | ForEach-Object -Process {
$invokeRsCimMethodParameters = @{
CimInstance = $reportingServicesData.Configuration
MethodName = 'RemoveURL'
Arguments = @{
Application = $reportingServicesData.ReportsApplicationName
UrlString = $_
Lcid = $language
}
$currentConfig.ReportsReservedUrl | ForEach-Object -Process {
$invokeRsCimMethodParameters = @{
CimInstance = $reportingServicesData.Configuration
MethodName = 'RemoveURL'
Arguments = @{
Application = $reportingServicesData.ReportsApplicationName
UrlString = $_
Lcid = $language
}

Invoke-RsCimMethod @invokeRsCimMethodParameters
}

$ReportsReservedUrl | ForEach-Object -Process {
Write-Verbose -Message (
$script:localizedData.AddReportsUrlReservation -f @(
$DatabaseServerName
$DatabaseInstanceName
$_
)
Invoke-RsCimMethod @invokeRsCimMethodParameters
}

$ReportsReservedUrl | ForEach-Object -Process {
Write-Verbose -Message (
$script:localizedData.AddReportsUrlReservation -f @(
$DatabaseServerName
$DatabaseInstanceName
$_
)
)

$invokeRsCimMethodParameters = @{
CimInstance = $reportingServicesData.Configuration
MethodName = 'ReserveUrl'
Arguments = @{
Application = $reportingServicesData.ReportsApplicationName
UrlString = $_
Lcid = $language
}
$invokeRsCimMethodParameters = @{
CimInstance = $reportingServicesData.Configuration
MethodName = 'ReserveUrl'
Arguments = @{
Application = $reportingServicesData.ReportsApplicationName
UrlString = $_
Lcid = $language
}

Invoke-RsCimMethod @invokeRsCimMethodParameters
}

# Get the current configuration
$currentConfig = Get-TargetResource @getTargetResourceParameters
Write-Verbose -Message ( $script:localizedData.ReportingServicesIsInitialized -f $DatabaseServerName, $DatabaseInstanceName, $currentConfig.IsInitialized ) -Verbose
Invoke-RsCimMethod @invokeRsCimMethodParameters
}

# Get the current configuration
$currentConfig = Get-TargetResource @getTargetResourceParameters
Write-Verbose -Message ( $script:localizedData.ReportingServicesIsInitialized -f $DatabaseServerName, $DatabaseInstanceName, $currentConfig.IsInitialized ) -Verbose
}
#endregion Reserved URLs

Expand Down Expand Up @@ -1254,10 +1250,12 @@ function Set-TargetResource
Report Manager/Report Web App virtual directory name. Optional.
.PARAMETER ReportServerReservedUrl
Report Server URL reservations. Optional.
Report Server URL reservations. Optional. If not specified,
'http://+:80' URL reservation will be used.
.PARAMETER ReportsReservedUrl
Report Manager/Report Web App URL reservations. Optional.
If not specified, 'http://+:80' URL reservation will be used.
.PARAMETER HttpsCertificateThumbprint
The thumbprint of the certificate used to secure SSL communication.
Expand Down Expand Up @@ -1348,11 +1346,11 @@ function Test-TargetResource

[Parameter()]
[System.String[]]
$ReportServerReservedUrl,
$ReportServerReservedUrl = @('http://+:80'),

[Parameter()]
[System.String[]]
$ReportsReservedUrl,
$ReportsReservedUrl = @('http://+:80'),

[Parameter()]
[System.String]
Expand Down Expand Up @@ -1528,30 +1526,27 @@ function Test-TargetResource
}
}

if ( $PSBoundParameters.ContainsKey('ReportsReservedUrl') )
if ( $null -eq $currentConfig.ReportsReservedUrl )
{
Write-Verbose -Message (
$script:localizedData.ReportsReservedUrlNotInDesiredState -f $DatabaseServerName, $DatabaseInstanceName, '', ( $ReportsReservedUrl -join ', ' )
) -Verbose
$result = $false
}
else
{
if ( $null -eq $currentConfig.ReportsReservedUrl )
$compareParameters = @{
ReferenceObject = $currentConfig.ReportsReservedUrl
DifferenceObject = $ReportsReservedUrl
}

if ( $null -ne ( Compare-Object @compareParameters ) )
{
Write-Verbose -Message (
$script:localizedData.ReportsReservedUrlNotInDesiredState -f $DatabaseServerName, $DatabaseInstanceName, '', ( $ReportsReservedUrl -join ', ' )
$script:localizedData.ReportsReservedUrlNotInDesiredState -f $DatabaseServerName, $DatabaseInstanceName, ( $currentConfig.ReportsReservedUrl -join ', ' ), ( $ReportsReservedUrl -join ', ' )
) -Verbose
$result = $false
}
else
{
$compareParameters = @{
ReferenceObject = $currentConfig.ReportsReservedUrl
DifferenceObject = $ReportsReservedUrl
}

if ( $null -ne ( Compare-Object @compareParameters ) )
{
Write-Verbose -Message (
$script:localizedData.ReportsReservedUrlNotInDesiredState -f $DatabaseServerName, $DatabaseInstanceName, ( $currentConfig.ReportsReservedUrl -join ', ' ), ( $ReportsReservedUrl -join ', ' )
) -Verbose
$result = $false
}
}
}

if ($PSBoundParameters.ContainsKey('UseSsl') -and $UseSsl -ne $currentConfig.UseSsl)
Expand Down
4 changes: 2 additions & 2 deletions source/DSCResources/DSC_SqlRS/DSC_SqlRS.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class DSC_SqlRS : OMI_BaseResource
[Write, EmbeddedInstance("MSFT_Credential"), Description("The service account that should be used when running the _Windows_ service.")] String ServiceAccount;
[Write, Description("_Report Server Web Service_ virtual directory. Optional.")] String ReportServerVirtualDirectory;
[Write, Description("_Report Manager_ or _Report Web App_ virtual directory name. Optional.")] String ReportsVirtualDirectory;
[Write, Description("_Report Server_ URL reservations. Optional.")] String ReportServerReservedUrl[];
[Write, Description("_Report Manager_ or _Report Web App_ URL reservations. Optional.")] String ReportsReservedUrl[];
[Write, Description("_Report Server_ URL reservations. Optional. If not specified, `'http://+:80'` URL reservation will be used.")] String ReportServerReservedUrl[];
[Write, Description("_Report Manager_ or _Report Web App_ URL reservations. Optional. If not specified, `'http://+:80'` URL reservation will be used.")] String ReportsReservedUrl[];
[Write, Description("The thumbprint of the certificate used to secure SSL communication.")] String HttpsCertificateThumbprint;
[Write, Description("The IP address to bind the certificate specified in the _CertificateThumbprint_ parameter to. Default is `0.0.0.0` which binds to all IP addresses.")] String HttpsIPAddress;
[Write, Description("The port used for SSL communication. Default is `443`.")] SInt32 HttpsPort;
Expand Down
26 changes: 13 additions & 13 deletions tests/Unit/DSC_SqlRS.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -881,15 +881,15 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 0 -Scope It
} -Exactly -Times 1 -Scope It

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName
} -Exactly -Times 0 -Scope It
} -Exactly -Times 1 -Scope It

Should -Invoke -CommandName Get-CimInstance -ParameterFilter {
$ClassName -eq 'Win32_OperatingSystem'
} -Exactly -Times 8 -Scope It
} -Exactly -Times 10 -Scope It

Should -Invoke -CommandName Invoke-SqlCmd -Exactly -Times 2 -Scope It
Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 2 -Scope It
Expand Down Expand Up @@ -1211,7 +1211,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 1 -Scope It
} -Exactly -Times 2 -Scope It

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportsApplicationName
Expand Down Expand Up @@ -1252,7 +1252,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 0 -Scope It
} -Exactly -Times 1 -Scope It

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName
Expand Down Expand Up @@ -1349,13 +1349,13 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 0 -Scope It
} -Exactly -Times 1 -Scope It

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationNameLegacy
} -Exactly -Times 0 -Scope It
} -Exactly -Times 1 -Scope It

Should -Invoke -CommandName Get-CimInstance -Exactly -Times 8 -Scope It
Should -Invoke -CommandName Get-CimInstance -Exactly -Times 10 -Scope It
Should -Invoke -CommandName Invoke-SqlCmd -Exactly -Times 2 -Scope It
Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 2 -Scope It

Expand Down Expand Up @@ -1433,13 +1433,13 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 0 -Scope It
} -Exactly -Times 1 -Scope It

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName
} -Exactly -Times 0 -Scope It
} -Exactly -Times 1 -Scope It

Should -Invoke -CommandName Get-CimInstance -Exactly -Times 8 -Scope It
Should -Invoke -CommandName Get-CimInstance -Exactly -Times 10 -Scope It
Should -Invoke -CommandName Invoke-Sqlcmd -Exactly -Times 2 -Scope It
Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 2 -Scope It
}
Expand Down Expand Up @@ -1503,7 +1503,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 1 -Scope It
} -Exactly -Times 2 -Scope It

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportsApplicationName
Expand Down Expand Up @@ -1535,7 +1535,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName
} -Exactly -Times 0 -Scope It
} -Exactly -Times 1 -Scope It

Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
$MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName
Expand Down

0 comments on commit 7638ef9

Please sign in to comment.