diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..60ac127 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,30 @@ +# Changelog for xoap-application-packaging-dsc + +The format is based on and uses the types of changes according to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +- None + +### Changed + +- None + +### Deprecated + +- None + +### Removed + +- None + +### Fixed + +- None + +### Security + +- None diff --git a/CODEOWNERS.md b/CODEOWNERS.md index 793d704..78db56b 100644 --- a/CODEOWNERS.md +++ b/CODEOWNERS.md @@ -1,2 +1,2 @@ -@ssokolic +@ssokolic @xoap_io \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index a691bfd..09695ea 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,132 +1,132 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -We as members, contributors, and leaders pledge to make participation in our -community a harassment-free experience for everyone, regardless of age, body -size, visible or invisible disability, ethnicity, sex characteristics, gender -identity and expression, level of experience, education, socio-economic status, -nationality, personal appearance, race, caste, color, religion, or sexual -identity and orientation. - -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our -community include: - -- Demonstrating empathy and kindness toward other people -- Being respectful of differing opinions, viewpoints, and experiences -- Giving and gracefully accepting constructive feedback -- Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -- Focusing on what is best not just for us as individuals, but for the overall - community - -Examples of unacceptable behavior include: - -- The use of sexualized language or imagery, and sexual attention or advances of - any kind -- Trolling, insulting or derogatory comments, and personal or political attacks -- Public or private harassment -- Publishing others' private information, such as a physical or email address, - without their explicit permission -- Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Enforcement Responsibilities - -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. - -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. - -## Scope - -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at -[INSERT CONTACT METHOD]. -All complaints will be reviewed and investigated promptly and fairly. - -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. - -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series of -actions. - -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or permanent -ban. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. - -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. - -### 4. Permanent Ban - -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. - -**Consequence**: A permanent ban from any sort of public interaction within the -community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], -version 2.1, available at -[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. - -Community Impact Guidelines were inspired by -[Mozilla's code of conduct enforcement ladder][mozilla coc]. - -For answers to common questions about this code of conduct, see the FAQ at -[https://www.contributor-covenant.org/faq][faq]. Translations are available at -[https://www.contributor-covenant.org/translations][translations]. - -[homepage]: https://www.contributor-covenant.org -[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html -[mozilla coc]: https://github.com/mozilla/diversity -[faq]: https://www.contributor-covenant.org/faq +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +- Demonstrating empathy and kindness toward other people +- Being respectful of differing opinions, viewpoints, and experiences +- Giving and gracefully accepting constructive feedback +- Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +- Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +- The use of sexualized language or imagery, and sexual attention or advances of + any kind +- Trolling, insulting or derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or email address, + without their explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[INSERT CONTACT METHOD]. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][mozilla coc]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][faq]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[mozilla coc]: https://github.com/mozilla/diversity +[faq]: https://www.contributor-covenant.org/faq [translations]: https://www.contributor-covenant.org/translations \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 860470a..1960dc9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ -# Contributing - -tbd - -## Running the Tests - -tbd +# Contributing + +tbd + +## Running the Tests + +tbd diff --git a/DSCResources/Services/Services.psd1 b/DSCResources/Services/Services.psd1 new file mode 100644 index 0000000..d483281 --- /dev/null +++ b/DSCResources/Services/Services.psd1 @@ -0,0 +1,124 @@ +# +# Module manifest for module 'Services' +# +# Generated by: Sinisa Sokolic +# +# Generated on: 7/25/2023 +# + +@{ + +# Script module or binary module file associated with this manifest. +RootModule = 'Services.schema.psm1' + +# Version number of this module. +ModuleVersion = '0.0.1' + +# Supported PSEditions +# CompatiblePSEditions = @() + +# ID used to uniquely identify this module +GUID = '09a6295a-d863-47d9-b8ac-22fedaf9fcfc' + +# Author of this module +Author = 'Sinisa Sokolic' + +# Company or vendor of this module +CompanyName = 'RIS AG' + +# Copyright statement for this module +Copyright = '(c) 2023 XOAP. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'Configure Windows Services for Azure Virtual Desktop VMs based on Windows 11.' + +# Minimum version of the Windows PowerShell engine required by this module +PowerShellVersion = '5.1' + +# Name of the Windows PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the Windows PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# CLRVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +# RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = '*' + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = '*' + +# Variables to export from this module +VariablesToExport = '*' + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = '*' + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +} + + diff --git a/DSCResources/Services/Services.schema.psm1 b/DSCResources/Services/Services.schema.psm1 new file mode 100644 index 0000000..e4ec3b3 --- /dev/null +++ b/DSCResources/Services/Services.schema.psm1 @@ -0,0 +1,53 @@ +<# +.SYNOPSIS​ +Please fill me. +​ +.DESCRIPTION​ +Please fill me. + +.COMPONENT​ +Information about PowerShell Modules to be required. ​ +Powershell Module: PSDesiredStateConfiguration​ +Powershell Module: AuditPolicyDSC​ +Powershell Module: SecurityPolicyDSC​ +Powershell Module: PowerShellAccessControl​ +​Powershell Module: WindowsDefender + +.EXAMPLE +Get-DscResource -Module XOAP* + +.NOTES +For more information about advanced functions, call Get-Help with any +of the topics in the links listed below. +Module Name : XOAPModuleTemplateDSC +Resource Name : Services.schema.psm1 +Author : info@XOAP.io +​ +.LINK​ +https://www.microsoft.com/en-us/download/details.aspx?id=55319​ +​ +.LINK​ +https://www.powershellgallery.com/packages/BaselineManagement/2.9.0​ +​ +.LINK​ +https://gallery.technet.microsoft.com/scriptcenter/PowerShellAccessControl-d3be7b83​ + +.LINK +https://www.powershellgallery.com/packages/WindowsDefender/1.0.0.4 +#> +configuration Services +{ + + #Import-DSCResource -ModuleName xPSDesiredStateConfiguration + # + #xRegistry disableInsecureCipher_a + #{ + # Key = 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\DES 56/56' + # ValueName = 'Enabled' + # ValueData = '0' + # ValueType = 'Dword' + # Ensure = 'Present' + # Force = $true + #} + +} diff --git a/Examples/Resources/_dummy b/Examples/Resources/_dummy new file mode 100644 index 0000000..e69de29 diff --git a/Examples/XOAPModuleTemplateDSC.ps1 b/Examples/XOAPModuleTemplateDSC.ps1 index 20db649..f3762b3 100644 --- a/Examples/XOAPModuleTemplateDSC.ps1 +++ b/Examples/XOAPModuleTemplateDSC.ps1 @@ -1,19 +1,27 @@ -Configuration 'XOAPModuleTemplateDSC' -{ - Import-DSCResource -Module 'XOAPModuleTemplateDSC' -Name 'XOAP_DSCResource' -ModuleVersion '0.0.1' - - param - ( - # Target nodes to apply the configuration - [string[]]$NodeName = 'localhost' - ) - - Node 'XOAPModuleTemplateDSC' - { - XOAP_DSCResource 'XOAP_DSCResource' - { - } - - } -} -XOAPModuleTemplateDSC -OutputPath 'C:\XOAPModuleTemplateDSC' +configuration XOAPModuleTemplateDSC +{ + param + ( + # Target nodes to apply the configuration + [string[]]$NodeName = 'localhost' + ) + + Import-Module XOAPModuleTemplateDSC + Import-DSCResource -ModuleName XOAPModuleTemplateDSC + + Node $NodeName + { + + $moduleRoot = [io.path]::GetDirectoryName((Get-Module XOAPModuleTemplateDSC).Path) + #$examples = "$moduleRoot\Examples" + + # Install the IIS role + WindowsFeature IIS + { + Ensure = "Present" + Name = "Web-Server" + } + + } +} + diff --git a/LICENSE b/LICENSE index 3ebd87e..6d8e98f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,21 @@ -MIT License - -Copyright (c) 2023 XOAP.io - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +MIT License + +Copyright (c) 2023 XOAP.io + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/New-CompositeResource.ps1 b/New-CompositeResource.ps1 index 75ce43d..5028548 100755 --- a/New-CompositeResource.ps1 +++ b/New-CompositeResource.ps1 @@ -1,75 +1,75 @@ -#Requires -Modules @{ ModuleName="Plaster"; ModuleVersion="1.1.3" } - -[CmdletBinding()] -param ( - [Parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()] - [string] - $Module, - [Parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()] - [string] - $Version, - [Parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()] - [string] - $Ressource, - [Parameter()] - [ValidateNotNullOrEmpty()] - [string] - $Company = "RIS AG" -) - -$globalPrefix = "XOAP" -$curDirectory = Resolve-Path .\ -$templatePath = Join-Path $curDirectory "templates" -$rootModulePath = Resolve-Path .\source -$Module = "${globalPrefix}${Module}DSC" -$modulePath = Join-Path $rootModulePath "$Module" -$moduleVersionPath = Join-Path $modulePath $Version -$moduleRessources = Join-Path $moduleVersionPath "DSCResources" -$ressourcePath = Join-Path $moduleRessources $Ressource - - -Write-Output "Checking if module $Module already exists under $moduleVersionPath" - -if(Test-Path "$moduleVersionPath") -{ - Write-Output "Module $Module with version $Version already exists. Continuing." -} -else -{ - Write-Warning "Module $Module with version $Version does not exist. Creating new module. Please provide missing data." - $template = Join-Path $templatePath "shared_module" - $moduleData = @{ - project_name = $Module - version = $Version - company = $Company - TemplatePath = "$template" - DestinationPath = "$moduleVersionPath" - } - - Invoke-Plaster @moduleData -} - - -Write-Output "Going to check if ressource $Ressource exists under $ressourcePath" - -if(Test-Path "$ressourcePath") -{ - Write-Error "Ressource $Ressource already exists. Aborting" -} -else -{ - Write-Output "Creating new ressource $Ressource for module $Module" - $template = Join-Path $templatePath "composite_resource" - $moduleData = @{ - project_name = "${Ressource}" - version = "0.0.1" - company = $Company - TemplatePath = "$template" - DestinationPath = "$ressourcePath" - } - - Invoke-Plaster @moduleData -} +#Requires -Modules @{ ModuleName="Plaster"; ModuleVersion="1.1.3" } + +[CmdletBinding()] +param ( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + $Module, + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + $Version, + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string] + $Ressource, + [Parameter()] + [ValidateNotNullOrEmpty()] + [string] + $Company = "RIS AG" +) + +$globalPrefix = "XOAP" +$curDirectory = Resolve-Path .\ +$templatePath = Join-Path $curDirectory "templates" +$rootModulePath = Resolve-Path .\source +$Module = "${globalPrefix}${Module}DSC" +$modulePath = Join-Path $rootModulePath "$Module" +$moduleVersionPath = Join-Path $modulePath $Version +$moduleRessources = Join-Path $moduleVersionPath "DSCResources" +$ressourcePath = Join-Path $moduleRessources $Ressource + + +Write-Output "Checking if module $Module already exists under $moduleVersionPath" + +if(Test-Path "$moduleVersionPath") +{ + Write-Output "Module $Module with version $Version already exists. Continuing." +} +else +{ + Write-Warning "Module $Module with version $Version does not exist. Creating new module. Please provide missing data." + $template = Join-Path $templatePath "shared_module" + $moduleData = @{ + project_name = $Module + version = $Version + company = $Company + TemplatePath = "$template" + DestinationPath = "$moduleVersionPath" + } + + Invoke-Plaster @moduleData +} + + +Write-Output "Going to check if ressource $Ressource exists under $ressourcePath" + +if(Test-Path "$ressourcePath") +{ + Write-Error "Ressource $Ressource already exists. Aborting" +} +else +{ + Write-Output "Creating new ressource $Ressource for module $Module" + $template = Join-Path $templatePath "composite_resource" + $moduleData = @{ + project_name = "${Ressource}" + version = "0.0.1" + company = $Company + TemplatePath = "$template" + DestinationPath = "$ressourcePath" + } + + Invoke-Plaster @moduleData +} diff --git a/Readme.md b/Readme.md index 1e2f3c5..ef41073 100644 --- a/Readme.md +++ b/Readme.md @@ -1,74 +1,59 @@ -# XOAPModuleTemplateDSC - -This repository is a template that can be used as a starting point for creating new DSC modules and resources. - -## Code of Conduct - -This project has adopted this [Code of Conduct](CODE_OF_CONDUCT.md). - -## Contributing - -Please check out common DSC Community [contributing guidelines](https://dsccommunity.org/guidelines/contributing). - -## Change log - -A full list of changes in each version can be found in the [Releases](https://github.com/xoap-io/XOAPModuleTemplateDSC/releases). - -## Documentation - -This script is used to easily create new DSC modules and resources. - -## Prerequisites - -Be sure that the following DSC modules are installed on your system: - -- ModuleName (x.x.x) - -## DSC Resources and syntax - -### XOAP_AddServerToCollection - -```PowerShell -XOAP_DSCResource [String] #ResourceName - { - [DependsOn = [String[]]] - [PsDscRunAsCredential = [PSCredential]] - } -``` - -## Configuration examples for each resource - -You can review the [Examples](/Examples/Resources) directory in the **XOAPModuleTemplateDSC** module -for some general usage scenarios for all the resources that are in the module. - -To implement the Module Template DSC module, add the following resources to your DSC configuration and adjust the parameters accordingly: - -### Add server to a collection - -```PowerShell -configuration 'XOAP_DSCResource' -{ - Import-DscResource -ModuleName 'XOAPModuleTemplateDSC' -Name 'XOAP_DSCResource' -ModuleVersion '0.0.1' - - XOAP_DSCResource 'Example' - { - DependsOn = @('[String[]]') - PsDscRunAsCredential = [PSCredential] - } -} -XOAP_DSCResource -``` - -## Create new DSC resource - -DSC resources can easily be deployed via the invocation of - -```powershell -.\New-CompositeResource.ps1 -``` - -with parameters - -```powershell -.\New-CompositeResource.ps1 -Module 'XOAPModuleTemplateDSC' -Version '0.0.1' -Resource 'DSCResource' -``` +# XOAPModuleTemplateDSC + +This repository is a template that can be used as a starting point for creating new DSC modules and resources. + +## Code of Conduct + +This project has adopted this [Code of Conduct](CODE_OF_CONDUCT.md). + +## Contributing + +Please check out common DSC Community [contributing guidelines](https://dsccommunity.org/guidelines/contributing). + +## Change log + +A full list of changes in each version can be found in the [change log](CHANGELOG.md). + +## Documentation + +This script is used to easily create new DSC modules and resources. + +## Prerequisites + +Please install Plaster first and make sure it's present. + +```powershell +Install-Module Plaster +Import-Module Plaster +``` + +## Create new DSC modules + +Modules will be automatically created once you are creating a new DSC resource. + +## Create new DSC resources + +DSC resources can easily be deployed via the invocation of + +```powershell +.\New-CompositeResource.ps1 +``` + +with parameters + +```powershell +.\New-CompositeResource.ps1 -Module XOAPModuleTemplateDSC -Version 0.0.1 -Resource ScheduledTasks +``` + +The parameter list is as followed: + +| Parameter | Description | Note | +|-----------|----------------------------------------|------| +| Module | Name of the outer module part | - | +| Version | Target version of the module | - | +| Ressource | The name of the ressource /config part | - | + +### Examples + +You can review the [Examples](/Examples/Resources) directory in the **XOAPModuleTemplateDSC** module +for some general use scenarios for all the resources that are in the module. diff --git a/SECURITY.md b/SECURITY.md index 2cfe789..10ee4c6 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,30 +1,30 @@ -## Security - -XOAP takes the security of our modules seriously, which includes all source code repositories managed through our GitHub organization. - -If you believe you have found a security vulnerability in any XOAP owned repository, please report it to us as described below. - -## Reporting Security Issues - -**Please do not report security vulnerabilities through public GitHub issues.** - -Instead, please report them to one or several members of the XOAP organization. -The easiest way to do so is to send us a direct message via Twitter. - -You should receive a response within 48 hours. If for some reason you do not, please follow up to other members of the community. - -Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: - -- Type of issue -- Full paths of source file(s) related to the manifestation of the issue -- The location of the affected source code (tag/branch/commit or direct URL) -- Any special configuration required to reproduce the issue -- Step-by-step instructions to reproduce the issue -- Proof-of-concept or exploit code (if possible) -- Impact of the issue, including how an attacker might exploit the issue - -This information will help us triage your report more quickly. - -## Preferred Languages - -We prefer all communications to be in English. +## Security + +XOAP takes the security of our modules seriously, which includes all source code repositories managed through our GitHub organization. + +If you believe you have found a security vulnerability in any XOAP owned repository, please report it to us as described below. + +## Reporting Security Issues + +**Please do not report security vulnerabilities through public GitHub issues.** + +Instead, please report them to one or several members of the XOAP organization. +The easiest way to do so is to send us a direct message via Twitter. + +You should receive a response within 48 hours. If for some reason you do not, please follow up to other members of the community. + +Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: + +- Type of issue +- Full paths of source file(s) related to the manifestation of the issue +- The location of the affected source code (tag/branch/commit or direct URL) +- Any special configuration required to reproduce the issue +- Step-by-step instructions to reproduce the issue +- Proof-of-concept or exploit code (if possible) +- Impact of the issue, including how an attacker might exploit the issue + +This information will help us triage your report more quickly. + +## Preferred Languages + +We prefer all communications to be in English. diff --git a/XOAPModuleTemplateDSC.psd1 b/XOAPModuleTemplateDSC.psd1 index 63341ac..ce78ae3 100644 --- a/XOAPModuleTemplateDSC.psd1 +++ b/XOAPModuleTemplateDSC.psd1 @@ -1,121 +1,124 @@ -# -# Module manifest for module 'XOAPAModuleTemplate1DSC' -# -# Generated by: XOAP.io -# -# Generated on: 10/10/2023 -# - -@{ - -# Script module or binary module file associated with this manifest. -# RootModule = '' - -# Version number of this module. -ModuleVersion = '0.0.1' - -# Supported PSEditions -# CompatiblePSEditions = @() - -# ID used to uniquely identify this module -GUID = '9300a1eb-8865-4cf3-abf2-bd2f8f7d861d' - -# Author of this module -Author = 'XOAP.io' - -# Company or vendor of this module -CompanyName = 'RIS AG' - -# Copyright statement for this module -Copyright = '(c) XOAP.io. All rights reserved.' - -# Description of the functionality provided by this module -Description = 'Module template for XOAP.io DSC modules.' - -# Minimum version of the Windows PowerShell engine required by this module -PowerShellVersion = '5.1' - -# Name of the Windows PowerShell host required by this module -# PowerShellHostName = '' - -# Minimum version of the Windows PowerShell host required by this module -# PowerShellHostVersion = '' - -# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# DotNetFrameworkVersion = '' - -# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# CLRVersion = '' - -# Processor architecture (None, X86, Amd64) required by this module -# ProcessorArchitecture = '' - -# Modules that must be imported into the global environment prior to importing this module -# RequiredModules = @() - -# Assemblies that must be loaded prior to importing this module -# RequiredAssemblies = @() - -# Script files (.ps1) that are run in the caller's environment prior to importing this module. -# ScriptsToProcess = @() - -# Type files (.ps1xml) to be loaded when importing this module -# TypesToProcess = @() - -# Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() - -# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess -# NestedModules = @() - -# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. -FunctionsToExport = @() - -# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. -CmdletsToExport = @() - -# Variables to export from this module -VariablesToExport = '*' - -# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. -AliasesToExport = @() - -# DSC resources to export from this module -# DscResourcesToExport = @() - -# List of all modules packaged with this module -# ModuleList = @() - -# List of all files packaged with this module -# FileList = @() - -# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. -PrivateData = @{ - - PSData = @{ - - # Tags applied to this module. These help with module discovery in online galleries. - # Tags = @() - - # A URL to the license for this module. - # LicenseUri = '' - - # A URL to the main website for this project. - # ProjectUri = '' - - # A URL to an icon representing this module. - # IconUri = '' - - # ReleaseNotes of this module - # ReleaseNotes = '' - - } # End of PSData hashtable - -} # End of PrivateData hashtable - -# HelpInfo URI of this module -# HelpInfoURI = '' - -# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. -# DefaultCommandPrefix = '' -} +# +# Module manifest for module 'XOAPAModuleTemplate1DSC' +# +# Generated by: Sinisa Sokolic +# +# Generated on: 7/25/2023 +# + +@{ + +# Script module or binary module file associated with this manifest. +# RootModule = '' + +# Version number of this module. +ModuleVersion = '0.0.1' + +# Supported PSEditions +# CompatiblePSEditions = @() + +# ID used to uniquely identify this module +GUID = '9300a1eb-8865-4cf3-abf2-bd2f8f7d861d' + +# Author of this module +Author = 'Sinisa Sokolic' + +# Company or vendor of this module +CompanyName = 'RIS AG' + +# Copyright statement for this module +Copyright = '(c) 2023 XOAP.io. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'Module to configure Azure Virtual Desktop Optimizations on Windows 11. ' + +# Minimum version of the Windows PowerShell engine required by this module +PowerShellVersion = '5.1' + +# Name of the Windows PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the Windows PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# CLRVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +# RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = @() + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = @() + +# Variables to export from this module +VariablesToExport = '*' + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = @() + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +} + + diff --git a/source/readme.txt b/source/readme.txt new file mode 100644 index 0000000..f23a437 --- /dev/null +++ b/source/readme.txt @@ -0,0 +1 @@ +Location for created modules \ No newline at end of file diff --git a/templates/composite_resource/plasterManifest.xml b/templates/composite_resource/plasterManifest.xml index a093cfd..d22610d 100755 --- a/templates/composite_resource/plasterManifest.xml +++ b/templates/composite_resource/plasterManifest.xml @@ -1,30 +1,32 @@ - - - - PowershellDSCResource - 14f99429-b25c-45e0-be57-e43666652ab5 - 0.0.1 - PowershellDSCResource - - XOAP.io - - - - - - - - - - - Creating new module manifest for ${PLASTER_PARAM_project_name} - - - + + + + PowershellDSCResource + 14f99429-b25c-45e0-be57-e43666652ab5 + 1.0.0 + PowershellDSCResource + + XOAP + + + + + + + + + + + Creating new module manifest for ${PLASTER_PARAM_project_name} + + Copying schema template + + + diff --git a/templates/composite_resource/resource.schema.psm1.template b/templates/composite_resource/resource.schema.psm1.template new file mode 100644 index 0000000..5c0788d --- /dev/null +++ b/templates/composite_resource/resource.schema.psm1.template @@ -0,0 +1,7 @@ +configuration <%=${PLASTER_PARAM_project_name}%> +{ +Import-DSCResource -ModuleName xPSDesiredStateConfiguration + + + +} diff --git a/templates/shared_module/1-ConfigureScheduledTask.template b/templates/shared_module/1-ConfigureScheduledTask.template new file mode 100644 index 0000000..7037be7 --- /dev/null +++ b/templates/shared_module/1-ConfigureScheduledTask.template @@ -0,0 +1,15 @@ +configuration Example +{ + param + ( + [string[]]$NodeName = 'localhost' + ) + + Import-DSCResource -ModuleName XOAPModuleTemplateDSC + + WindowsFeature IIS + { + Ensure = "Present" + Name = "Web-Server" + } +} diff --git a/templates/shared_module/CHANGELOG.md b/templates/shared_module/CHANGELOG.md new file mode 100644 index 0000000..74fea6f --- /dev/null +++ b/templates/shared_module/CHANGELOG.md @@ -0,0 +1,32 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [unreleased] + +- tbd + +## [0.0.1] - 2022-06-26 + +### Changed + +- tdb + +### Added + +- tdb + +### Fixed + +- tbd + +### Removed + +- tbd + +### Security + +- tbd diff --git a/templates/shared_module/README.md b/templates/shared_module/README.md new file mode 100644 index 0000000..1a8d303 --- /dev/null +++ b/templates/shared_module/README.md @@ -0,0 +1,38 @@ +# <%=${PLASTER_PARAM_project_name}%> + +The <%=${PLASTER_PARAM_project_name}%> PowerShell module provides +DSC resources that can be used to ... (explain what functionality the resources are meant to provide) + +## Installation + +To manually install the module, download the source code and unzip the contents +of the \Modules\<%=${PLASTER_PARAM_project_name}%> directory to the +$env:ProgramFiles\WindowsPowerShell\Modules folder + +To install from the PowerShell gallery using PowerShellGet (in PowerShell 5.0) +run the following command: + + Find-Module -Name <%=${PLASTER_PARAM_project_name}%> -Repository PSGallery | Install-Module + +To confirm installation, run the below command and ensure you see the +<%=${PLASTER_PARAM_project_name}%> DSC resources available: + + Get-DscResource -Module <%=${PLASTER_PARAM_project_name}%> + +## Usage + +Include the following in your DSC configuration + + Import-DSCResource -ModuleName <%=${PLASTER_PARAM_project_name}%> + +### MyResource + + MyResource resourceName { + Ensure = "Present" + } + +## Requirements + +The minimum PowerShell version required is 4.0, which ships in Windows 8.1 +or Windows Server 2012R2 (or higher versions). The preferred version is +PowerShell 5.0 or higher, which ships with Windows 10 or Windows Server 2016. diff --git a/templates/shared_module/_dummy b/templates/shared_module/_dummy new file mode 100644 index 0000000..e69de29 diff --git a/templates/shared_module/_gitignore b/templates/shared_module/_gitignore new file mode 100644 index 0000000..6c99b45 --- /dev/null +++ b/templates/shared_module/_gitignore @@ -0,0 +1,148 @@ +# JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +# VSCode ----------------------------------------------------------- + +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +# Windows ----------------------------------------------------------- + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# macOS ----------------------------------------------------------- + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk \ No newline at end of file diff --git a/templates/shared_module/plasterManifest.xml b/templates/shared_module/plasterManifest.xml index 58d3e2c..b6aa606 100755 --- a/templates/shared_module/plasterManifest.xml +++ b/templates/shared_module/plasterManifest.xml @@ -1,32 +1,37 @@ - - - - PowershellDSCModule - 76d2fef8-679c-44d8-8d99-1d35c77f9c0d - 0.0.1 - PowershellDSCModule - - XOAP.io - - - - - - - - - - - - Scaffold a PowerShell Module with the files required to run Pester tests. - - - - - + + + + PowershellDSCModule + 76d2fef8-679c-44d8-8d99-1d35c77f9c0d + 1.0.0 + PowershellDSCModule + + XOAP + + + + + + + + + + + + Scaffold a PowerShell Module with the files required to run Pester tests. + + + + + + + + + + diff --git a/test/Boilerplate.Tests.ps1 b/test/Boilerplate.Tests.ps1 index 55b9675..de23448 100644 --- a/test/Boilerplate.Tests.ps1 +++ b/test/Boilerplate.Tests.ps1 @@ -1,71 +1,71 @@ -$Global:DSCResourceName = 'My_DSCResource' #<----- Just change this - -Import-Module "$($PSScriptRoot)\..\..\DSCResources\$($Global:DSCResourceName)\$($Global:DSCResourceName).psm1" -Force - -# Helper function to list the names of mandatory parameters of *-TargetResource functions -Function Get-MandatoryParameter { - [CmdletBinding()] - Param( - [Parameter(Mandatory=$True)] - [string]$CommandName - ) - $GetCommandData = Get-Command "$($Global:DSCResourceName)\$CommandName" - $MandatoryParameters = $GetCommandData.Parameters.Values | Where-Object { $_.Attributes.Mandatory -eq $True } - return $MandatoryParameters.Name -} - -# Getting the names of mandatory parameters for each *-TargetResource function -$GetMandatoryParameter = Get-MandatoryParameter -CommandName "Get-TargetResource" -$TestMandatoryParameter = Get-MandatoryParameter -CommandName "Test-TargetResource" -$SetMandatoryParameter = Get-MandatoryParameter -CommandName "Set-TargetResource" - -# Splatting parameters values for Get, Test and Set-TargetResource functions -$GetParams = @{ - -} -$TestParams = @{ - -} -$SetParams = @{ - -} - -Describe "$($Global:DSCResourceName)\Get-TargetResource" { - - $GetReturn = & "$($Global:DSCResourceName)\Get-TargetResource" @GetParams - - It "Should return a hashtable" { - $GetReturn | Should BeOfType System.Collections.Hashtable - } - Foreach ($MandatoryParameter in $GetMandatoryParameter) { - - It "Should return a hashtable with key named $MandatoryParameter" { - $GetReturn.ContainsKey($MandatoryParameter) | Should Be $True - } - } -} - -Describe "$($Global:DSCResourceName)\Test-TargetResource" { - - $TestReturn = & "$($Global:DSCResourceName)\Test-TargetResource" @TestParams - - It "Should have the same mandatory parameters as Get-TargetResource" { - # Does not check for $True or $False but uses the output of Compare-Object. - # That way, if this test fails Pester will show us the actual difference(s). - (Compare-Object $GetMandatoryParameter $TestMandatoryParameter).InputObject | Should Be $Null - } - It "Should return a boolean" { - $TestReturn | Should BeOfType System.Boolean - } -} - -Describe "$($Global:DSCResourceName)\Set-TargetResource" { - -$SetReturn = & "$($Global:DSCResourceName)\Set-TargetResource" @SetParams - -It "Should have the same mandatory parameters as Test-TargetResource" { -(Compare-Object $TestMandatoryParameter $SetMandatoryParameter).InputObject | Should Be $Null -} -It "Should not return anything" { -$SetReturn | Should Be $Null -} +$Global:DSCResourceName = 'My_DSCResource' #<----- Just change this + +Import-Module "$($PSScriptRoot)\..\..\DSCResources\$($Global:DSCResourceName)\$($Global:DSCResourceName).psm1" -Force + +# Helper function to list the names of mandatory parameters of *-TargetResource functions +Function Get-MandatoryParameter { + [CmdletBinding()] + Param( + [Parameter(Mandatory=$True)] + [string]$CommandName + ) + $GetCommandData = Get-Command "$($Global:DSCResourceName)\$CommandName" + $MandatoryParameters = $GetCommandData.Parameters.Values | Where-Object { $_.Attributes.Mandatory -eq $True } + return $MandatoryParameters.Name +} + +# Getting the names of mandatory parameters for each *-TargetResource function +$GetMandatoryParameter = Get-MandatoryParameter -CommandName "Get-TargetResource" +$TestMandatoryParameter = Get-MandatoryParameter -CommandName "Test-TargetResource" +$SetMandatoryParameter = Get-MandatoryParameter -CommandName "Set-TargetResource" + +# Splatting parameters values for Get, Test and Set-TargetResource functions +$GetParams = @{ + +} +$TestParams = @{ + +} +$SetParams = @{ + +} + +Describe "$($Global:DSCResourceName)\Get-TargetResource" { + + $GetReturn = & "$($Global:DSCResourceName)\Get-TargetResource" @GetParams + + It "Should return a hashtable" { + $GetReturn | Should BeOfType System.Collections.Hashtable + } + Foreach ($MandatoryParameter in $GetMandatoryParameter) { + + It "Should return a hashtable with key named $MandatoryParameter" { + $GetReturn.ContainsKey($MandatoryParameter) | Should Be $True + } + } +} + +Describe "$($Global:DSCResourceName)\Test-TargetResource" { + + $TestReturn = & "$($Global:DSCResourceName)\Test-TargetResource" @TestParams + + It "Should have the same mandatory parameters as Get-TargetResource" { + # Does not check for $True or $False but uses the output of Compare-Object. + # That way, if this test fails Pester will show us the actual difference(s). + (Compare-Object $GetMandatoryParameter $TestMandatoryParameter).InputObject | Should Be $Null + } + It "Should return a boolean" { + $TestReturn | Should BeOfType System.Boolean + } +} + +Describe "$($Global:DSCResourceName)\Set-TargetResource" { + +$SetReturn = & "$($Global:DSCResourceName)\Set-TargetResource" @SetParams + +It "Should have the same mandatory parameters as Test-TargetResource" { +(Compare-Object $TestMandatoryParameter $SetMandatoryParameter).InputObject | Should Be $Null +} +It "Should not return anything" { +$SetReturn | Should Be $Null +} diff --git a/test/integration/default/XOAPModuleTemplateDSC.Tests.ps1 b/test/integration/default/XOAPModuleTemplateDSC.Tests.ps1 index 3148b7b..acf638d 100644 --- a/test/integration/default/XOAPModuleTemplateDSC.Tests.ps1 +++ b/test/integration/default/XOAPModuleTemplateDSC.Tests.ps1 @@ -1,12 +1,12 @@ -Describe 'When setting up a webserver' { - Context 'to start the default website' { - - It 'verifies IIS is installed' { - (Get-WindowsFeature web-server).installed | should be $true - } - - It 'installs a default website' { - Get-Website 'Default Web Site' | should not be $null - } - } -} +Describe 'When setting up a webserver' { + Context 'to start the default website' { + + It 'verifies IIS is installed' { + (Get-WindowsFeature web-server).installed | should be $true + } + + It 'installs a default website' { + Get-Website 'Default Web Site' | should not be $null + } + } +}