Skip to content

Commit

Permalink
WebConfigPropertyCollection - allow different property collection key…
Browse files Browse the repository at this point in the history
… types to be added, IisModule / IisMimeTypeMapping - set Ensure as default (#640)
  • Loading branch information
Borgquite authored Oct 23, 2024
1 parent 3db41e4 commit 04d3bd3
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 18 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)

## [Unreleased]

### Added

- WebConfigPropertyCollection
- Allowed different property collection key types to be added beyond the default.

### Changed

- IisModule
- Set default for Ensure property to Present.
- IisMimeTypeMapping
- Set default for Ensure property to Present.

## [4.2.0] - 2024-08-26

### Removed
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ This resource manages the IIS configuration section locking (overrideMode) to co
* **ConfigurationPath**: This can be either an IIS configuration path in the format computername/webroot/apphost, or the IIS module path in this format IIS:\sites\Default Web Site.
* **Extension**: The file extension to map such as **.html** or **.xml**
* **MimeType**: The MIME type to map that extension to such as **text/html**
* **Ensure**: Ensures that the MIME type mapping is **Present** or **Absent**.
* **Ensure**: Ensures that the MIME type mapping is **Present** or **Absent**. Defaults to **Present**.

### IisModule

Expand All @@ -153,21 +153,21 @@ This resource manages the IIS configuration section locking (overrideMode) to co
* **Verb**: An array of allowed verbs, such as get and post.
* **SiteName**: The name of the Site to register the module for. If empty, the resource will register the module with all of IIS.
* **ModuleType**: The type of the module. Currently, only FastCgiModule is supported.
* **Ensure**: Ensures that the module is **Present** or **Absent**.
* **Ensure**: Ensures that the module is **Present** or **Absent**. Defaults to **Present**.

### SslSettings

* **Name**: The Name of website in which to modify the SSL Settings
* **Bindings**: The SSL bindings to implement.
* **Ensure**: Ensures if the bindings are **Present** or **Absent**.
* **Ensure**: Ensures if the bindings are **Present** or **Absent**. Defaults to **Present**.

### WebApplication

* **Website**: Name of website with which the web application is associated.
* **Name**: The desired name of the web application.
* **WebAppPool**: Web application’s application pool.
* **PhysicalPath**: The path to the files that compose the web application.
* **Ensure**: Ensures that the web application is **Present** or **Absent**.
* **Ensure**: Ensures that the web application is **Present** or **Absent**. Defaults to **Present**.
* **PreloadEnabled**: When set to `$true` this will allow WebSite to automatically start without a request
* **ServiceAutoStartEnabled**: When set to `$true` this will enable Autostart on a Website
* **ServiceAutoStartProvider**: Adds a AutostartProvider
Expand Down Expand Up @@ -363,7 +363,7 @@ Ensures the value of an identified property collection item's property in the we
* **WebApplication**: The name of the containing web application or an empty string for the containing website
* **PhysicalPath**: The path to the files that compose the virtual directory
* **Name**: The name of the virtual directory
* **Ensure**: Ensures if the virtual directory is **Present** or **Absent**.
* **Ensure**: Ensures if the virtual directory is **Present** or **Absent**. Defaults to **Present**.

## Examples

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ function Get-TargetResource
[String]
$MimeType,

[Parameter(Mandatory = $true)]
[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure
$Ensure = 'Present'
)

# Check if WebAdministration module is present for IIS cmdlets
Expand Down Expand Up @@ -120,10 +120,10 @@ function Set-TargetResource
[String]
$MimeType,

[Parameter(Mandatory = $true)]
[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure
$Ensure = 'Present'
)

Assert-Module -ModuleName WebAdministration
Expand Down Expand Up @@ -194,10 +194,10 @@ function Test-TargetResource
[String]
$MimeType,

[Parameter(Mandatory = $true)]
[Parameter()]
[ValidateSet('Present', 'Absent')]
[String]
$Ensure
$Ensure = 'Present'
)

Assert-Module -ModuleName WebAdministration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ class DSC_IisMimeTypeMapping : OMI_BaseResource
[Key, Description("This can be either an IIS configuration path in the format computername/webroot/apphost, or the IIS module path in this format IIS:\\sites\\Default Web Site.")] String ConfigurationPath;
[Key, Description("The file extension to map such as .html or .xml.")] string Extension;
[Key, Description("The MIME type to map that extension to such as text/html.")] string MimeType;
[Required, Description("Ensures that the MIME type mapping is Present or Absent."),ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
[Write, Description("Ensures that the MIME type mapping is Present or Absent."),ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
};
6 changes: 3 additions & 3 deletions source/DSCResources/DSC_IisModule/DSC_IisModule.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function Set-TargetResource
(
[Parameter()]
[ValidateSet('Present','Absent')]
[String] $Ensure,
[String] $Ensure = 'Present',

[Parameter(Mandatory = $true)]
[String] $Path,
Expand Down Expand Up @@ -183,7 +183,7 @@ function Test-TargetResource
(
[Parameter()]
[ValidateSet('Present','Absent')]
[String] $Ensure,
[String] $Ensure = 'Present',

[Parameter(Mandatory = $true)]
[String] $Path,
Expand Down Expand Up @@ -337,7 +337,7 @@ function Test-TargetResourceImpl

[Parameter()]
[ValidateSet('Present','Absent')]
[String] $Ensure,
[String] $Ensure = 'Present',

[Parameter(Mandatory = $true)]
[HashTable] $resourceStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ function Set-TargetResource
-PSPath $WebsitePath `
-Filter $filter `
-Name '.' `
-Type $ItemName `
-Value @{
$ItemKeyName = $ItemKeyValue
$ItemPropertyName = $setItemPropertyValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ configuration Sample_IisMimeTypeMapping_RemoveVideo
DependsOn = '[WindowsFeature]IIS'
}

# we only allow the mpg Video extension on our server
# we only allow the mpg and mpe Video extensions on our server
IisMimeTypeMapping Mpg
{
Ensure = 'Present'
Expand All @@ -60,5 +60,14 @@ configuration Sample_IisMimeTypeMapping_RemoveVideo
ConfigurationPath = "IIS:\sites\$WebSiteName"
DependsOn = '[WindowsFeature]IIS'
}

IisMimeTypeMapping Mpe
{
# Ensure defaults to 'Present'
Extension = '.mpe'
MimeType = 'video/mpeg'
ConfigurationPath = "IIS:\sites\$WebSiteName"
DependsOn = '[WindowsFeature]IIS'
}
}
}
2 changes: 0 additions & 2 deletions tests/Integration/DSC_IISMimeTypeMapping.config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ configuration DSC_IisMimeTypeMapping_AddMimeType
ConfigurationPath = ''
Extension = $ConfigurationData.NonNodeData.FileExtension
MimeType = $ConfigurationData.NonNodeData.MimeType
Ensure = 'Present'
}
}

Expand All @@ -33,7 +32,6 @@ Configuration DSC_IisMimeTypeMapping_AddMimeTypeNestedPath
ConfigurationPath = $ConfigurationData.NonNodeData.VirtualConfigurationPath
Extension = $ConfigurationData.NonNodeData.FileExtension
MimeType = $ConfigurationData.NonNodeData.MimeType
Ensure = 'Present'
}
}

Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/DSC_WebConfigPropertyCollection.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ try
Context 'Ensure is present and collection item and property do not exist - String ItemPropertyValue' {
Mock -CommandName Get-ItemValues -ModuleName $script:dscResourceName
Mock -CommandName Add-WebConfigurationProperty
Mock -CommandName Set-WebConfigurationProperty
Mock -CommandName Get-CollectionItemPropertyType -MockWith { return 'String' }
Mock -CommandName Convert-PropertyValue

Expand All @@ -253,6 +254,7 @@ try

Assert-MockCalled -CommandName Get-ItemValues -Times 1 -Exactly
Assert-MockCalled -CommandName Add-WebConfigurationProperty -Times 1 -Exactly
Assert-MockCalled -CommandName Set-WebConfigurationProperty -Times 0 -Exactly
Assert-MockCalled -CommandName Get-CollectionItemPropertyType -Times 1 -Exactly
Assert-MockCalled -CommandName Convert-PropertyValue -Times 0 -Exactly
}
Expand All @@ -261,6 +263,7 @@ try
Context 'Ensure is present and collection item and property do not exist - Integer ItemPropertyValue' {
Mock -CommandName Get-ItemValues -ModuleName $script:dscResourceName
Mock -CommandName Add-WebConfigurationProperty
Mock -CommandName Set-WebConfigurationProperty
Mock -CommandName Get-CollectionItemPropertyType -MockWith { return 'Int64' }
Mock -CommandName Convert-PropertyValue

Expand All @@ -269,6 +272,7 @@ try

Assert-MockCalled -CommandName Get-ItemValues -Times 1 -Exactly
Assert-MockCalled -CommandName Add-WebConfigurationProperty -Times 1 -Exactly
Assert-MockCalled -CommandName Set-WebConfigurationProperty -Times 0 -Exactly
Assert-MockCalled -CommandName Get-CollectionItemPropertyType -Times 1 -Exactly
Assert-MockCalled -CommandName Convert-PropertyValue -Times 1 -Exactly
}
Expand All @@ -281,6 +285,7 @@ try
allowed = 'false'
}
}
Mock -CommandName Add-WebConfigurationProperty
Mock -CommandName Set-WebConfigurationProperty -MockWith {}
Mock -CommandName Get-CollectionItemPropertyType -MockWith { return 'String' }
Mock -CommandName Convert-PropertyValue
Expand All @@ -289,6 +294,7 @@ try
Set-TargetResource @script:presentParameters

Assert-MockCalled -CommandName Get-ItemValues -Times 1 -Exactly
Assert-MockCalled -CommandName Add-WebConfigurationProperty -Times 0 -Exactly
Assert-MockCalled -CommandName Set-WebConfigurationProperty -Times 1 -Exactly
Assert-MockCalled -CommandName Get-CollectionItemPropertyType -Times 1 -Exactly
Assert-MockCalled -CommandName Convert-PropertyValue -Times 0 -Exactly
Expand Down

0 comments on commit 04d3bd3

Please sign in to comment.