Skip to content

Commit

Permalink
Merge pull request #368 from PowerShell/dev
Browse files Browse the repository at this point in the history
Release of version 2.0.0.0 of xWebAdministration
  • Loading branch information
kwirkykat authored Jun 13, 2018
2 parents bc03ae5 + 0410206 commit 10f14a3
Show file tree
Hide file tree
Showing 24 changed files with 1,607 additions and 490 deletions.
3 changes: 3 additions & 0 deletions .MetaTestOptIn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"null"
]
File renamed without changes.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
DSCResource.Tests
*.vscode
*.vs
182 changes: 120 additions & 62 deletions DSCResources/MSFT_xIisFeatureDelegation/MSFT_xIisFeatureDelegation.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -6,97 +6,144 @@ data LocalizedData
{
# culture="en-US"
ConvertFrom-StringData -StringData @'
GetOverrideMode = Getting override mode for '{0}'.
NoWebAdministrationModule = Please ensure that WebAdministration module is installed.
UnableToGetConfig = Unable to get configuration data for '{0}'.
ChangedMessage = Changed overrideMode for '{0}' to '{1}'.
VerboseGetTargetResource = Get-TargetResource has been run.
VerboseSetTargetResource = Changed overrideMode for '{0}' to '{1}'.
'@
}

<#
.SYNOPSIS
This will return a hashtable of results
.PARAMETER Filter
Specifies the IIS configuration section to lock or unlock.
.PARAMETER Path
Specifies the configuration path. This can be either an IIS configuration path in the format
computer machine/webroot/apphost, or the IIS module path in this format IIS:\sites\Default Web Site.
.PARAMETER OverrideMode
Determines whether to lock or unlock the specified section.
#>
function Get-TargetResource
{
<#
.SYNOPSIS
This will return a hashtable of results
#>

[CmdletBinding()]
[OutputType([Hashtable])]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String] $SectionName,
[String]
$Filter,

[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[ValidateSet('Allow', 'Deny')]
[String] $OverrideMode
[String]
$OverrideMode,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Path
)

[String] $oMode = Get-OverrideMode -Section $SectionName
[String] $currentOverrideMode = Get-OverrideMode -Filter $Filter -Path $Path

Write-Verbose -Message $LocalizedData.VerboseGetTargetResource

return @{
SectionName = $SectionName
OverrideMode = $oMode
Path = $Path
Filter = $Filter
OverrideMode = $currentOverrideMode
}
}

<#
.SYNOPSIS
This will set the resource to the desired state.
.PARAMETER Filter
Specifies the IIS configuration section to lock or unlock.
.PARAMETER Path
Specifies the configuration path. This can be either an IIS configuration path in the format
computer machine/webroot/apphost, or the IIS module path in this format IIS:\sites\Default Web Site.
.PARAMETER OverrideMode
Determines whether to lock or unlock the specified section.
#>
function Set-TargetResource
{
<#
.SYNOPSIS
This will set the desired state
#>

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String] $SectionName,
[String]
$Filter,

[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[ValidateSet('Allow', 'Deny')]
[String] $OverrideMode
[String]
$OverrideMode,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Path
)

Write-Verbose($($LocalizedData.ChangedMessage) -f $SectionName, $OverrideMode)

Set-WebConfiguration -Location '' `
-Filter "/system.webServer/$SectionName" `
-PSPath 'machine/webroot/apphost' `
-Metadata 'overrideMode' `
-Value $OverrideMode
Write-Verbose -Message ( $LocalizedData.VerboseSetTargetResource -f $Filter, $OverrideMode )

Set-WebConfiguration -Filter $Filter -PsPath $Path -Metadata 'overrideMode' -Value $OverrideMode
}

<#
.SYNOPSIS
This will return whether the resource is in desired state.
.PARAMETER Filter
Specifies the IIS configuration section to lock or unlock.
.PARAMETER OverrideMode
Determines whether to lock or unlock the specified section.
.PARAMETER Path
Specifies the configuration path. This can be either an IIS configuration path in the format
computer machine/webroot/apphost, or the IIS module path in this format IIS:\sites\Default Web Site.
#>
function Test-TargetResource
{
<#
.SYNOPSIS
This tests the desired state. If the state is not correct it will return $false.
If the state is correct it will return $true
#>

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSDSCUseVerboseMessageInDSCResource", "")]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String] $SectionName,
[String]
$Filter,

[Parameter(Mandatory)]
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[ValidateSet('Allow', 'Deny')]
[String] $OverrideMode
[String]
$OverrideMode,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Path
)

[String] $oMode = Get-OverrideMode -Section $SectionName
[String] $currentOverrideMode = Get-OverrideMode -Filter $Filter -Path $Path

if ($oMode -eq $OverrideMode)
if ($currentOverrideMode -eq $OverrideMode)
{
return $true
}
Expand All @@ -105,42 +152,53 @@ function Test-TargetResource
}

#region Helper functions
<#
.SYNOPSIS
This will return the current override mode for the specified configsection.
.PARAMETER Filter
Specifies the IIS configuration section.
.PARAMETER Path
Specifies the configuration path. This can be either an IIS configuration path in the format
computer machine/webroot/apphost, or the IIS module path in this format IIS:\sites\Default Web Site.
#>
function Get-OverrideMode
{
<#
.NOTES
Check for a single value.
If $oMode is anything but Allow or Deny, we have a problem with our
Get-WebConfiguration call or the ApplicationHost.config file is corrupted.
#>

[CmdletBinding()]
[OutputType([System.String])]
param
(
[String] $Section
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Filter,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
$Path
)

Assert-Module

Write-Verbose -Message 'Getting override mode'

$webConfig = Get-WebConfiguration -Location '' `
-Filter /system.webServer/$Section `
-Metadata
Write-Verbose -Message ( $LocalizedData.GetOverrideMode -f $Filter )

$oMode = $webConfig.Metadata.effectiveOverrideMode
$webConfig = Get-WebConfiguration -PsPath $Path -Filter $Filter -Metadata

if ($oMode -notmatch "^(Allow|Deny)$")
$currentOverrideMode = $webConfig.Metadata.effectiveOverrideMode

if ($currentOverrideMode -notmatch "^(Allow|Deny)$")
{
$errorMessage = $($LocalizedData.UnableToGetConfig) -f $Section
$errorMessage = $($LocalizedData.UnableToGetConfig) -f $Filter
New-TerminatingError -ErrorId UnableToGetConfig `
-ErrorMessage $errorMessage `
-ErrorCategory:InvalidResult
}

return $oMode
return $currentOverrideMode
}


#endregion

Export-ModuleMember -function *-TargetResource
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ClassVersion("1.0.0"), FriendlyName("xIisFeatureDelegation")]
[ClassVersion("1.0.0"), FriendlyName("xIisFeatureDelegation")]
class MSFT_xIisFeatureDelegation : OMI_BaseResource
{
[Key] string SectionName;
[Key,ValueMap{"Allow", "Deny"},Values{"Allow", "Deny"}] string OverrideMode;
[Key, Description("Specifies the configuration path. This can be either an IIS configuration path in the format computer machine/webroot/apphost, or the IIS module path in this format IIS:\\sites\\Default Web Site.")] String Path;
[Key, Description("Specifies the IIS configuration section to lock or unlock.")] String Filter;
[Required, Description("Determines whether to lock or unlock the specified section."), ValueMap{"Allow", "Deny"}, Values{"Allow", "Deny"}] string OverrideMode;
};
Loading

0 comments on commit 10f14a3

Please sign in to comment.