Skip to content
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

xIisMimeTypeMapping: Make ConfigurationPath a non-mandatory parameter #577

Open
sk82jack opened this issue May 15, 2020 · 4 comments
Open
Labels
needs investigation The issue needs to be investigated by the maintainers or/and the community.

Comments

@sk82jack
Copy link

Details of the scenario you tried and the problem that is occurring

I tried to use the xIisMimeTypeMapping resource without specifying the ConfigurationPath parameter as it wasn't listed as a property in the repository readme.md file. I then got an error saying that I was missing a mandatory parameter ConfigurationPath. After looking at the source code there is already a default value defined for this parameter if it's not specified here so it's unnecessary for the parameter to be mandatory.

Verbose logs showing the problem

N/A

Suggested solution to the issue

In the MSFT_xIisMimeTypeMapping.psm1 file change lines 35, 107 and 181 from [Parameter(Mandatory = $true)] to [Parameter()] so that the parameter is not mandatory and will use the MACHINE/WEBROOT/APPHOST default value if not specified.

There should also be an update to the readme.md file to reference this parameter.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

N/A

The operating system the target node is running

N/A

Version and build of PowerShell the target node is running

N/A

Version of the DSC module that was used

3.1.1

@johlju
Copy link
Member

johlju commented May 15, 2020

This property needs to be mandatory and a key in the schema, otherwise it wouldn't be possible to have this configuration.

        xIisMimeTypeMapping Mpeg
        {
            Ensure            = 'Present'
            Extension         = '.mpeg'
            MimeType          = 'video/mpeg'
            ConfigurationPath = "IIS:\sites\Site1"
        }

        xIisMimeTypeMapping Mpeg
        {
            Ensure            = 'Present'
            Extension         = '.mpeg'
            MimeType          = 'video/mpeg'
            ConfigurationPath = "IIS:\sites\Site2"
        }

I think instead the default values (the constants) should be removed. 🤔

@johlju johlju added the needs investigation The issue needs to be investigated by the maintainers or/and the community. label May 15, 2020
@sk82jack
Copy link
Author

I'm not saying to remove the value or parameter as I know you need to pass something to the backend functions but making the parameter non-mandatory would allow you to pick up the default server-wide ConfigurationPath and still allow you to override using the config you posted. But yeah I guess you could go the other direction and keep it mandatory and then remove the unnecessary checks for a empty variables.

I'm not too sure what the best practices are in terms of DSC resources and default values (in normal modules it's widely accepted to set default values in the param blocks) but for me, I didn't know what I needed to pass in to the ConfigurationPath to add a mime type mapping at the server level until I checked the source code and saw that default value. I guess as long as it's documented somewhere or another example is added on how to add a mime type mapping at the server level then I'm not too fussed either way :)

@sk82jack
Copy link
Author

sk82jack commented May 15, 2020

Ah I just realised I glossed over your point and a key in the schema

I'm pretty new to DSC so I'm not too sure about how DSC schemas are implemented and used and didn't even look in the schema file until you mentioned it lol

So I guess those keys are what define the uniqueness of the DSC resources for want of a better phrase? In that case I understand why it would be a required property.

@johlju
Copy link
Member

johlju commented May 16, 2020

Yes exactly. You are correct that the properties that have the type Key define uniqueness. It cannot exist two resource instances with the same values for those parameters in the same configuration to be able to enforce the desired state. Mandatory parameter can for that reason not have default values.

There are four possible types of type qualifiers in the schema; Key, Required, Write, and Read.
For each schema property that has Key or Required the corresponding parameter in the PowerShell module script must mandatory. But only Key properties define uniqueness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation The issue needs to be investigated by the maintainers or/and the community.
Projects
None yet
Development

No branches or pull requests

2 participants