Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
* development:
  Update module versions for release
  (GH-151) Download install.ps1 to temp folder.
  (maint) Set pester to a max version of 4.10.1
  (GH-20) add cChocoConfig resource
  Adding comments and tests
  Add pull request template
  (doc) Add issue template configuration
  (doc) Remove invalid issue template
  (doc) Update issue templates
  throw if using prerelease with minimumversion
  quick fixes
  DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1
  adding support for specifying minimum version
  • Loading branch information
pauby committed Feb 9, 2021
2 parents d07bd82 + 9f5af03 commit f777bd0
Show file tree
Hide file tree
Showing 16 changed files with 603 additions and 18 deletions.
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Bug Report
about: Create a report to help us improve cChoco
title: ''
labels: 0 - _Triaging, Bug, Up For Grabs
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Software (please complete the following information):**
- OS: [e.g. Windows 10 1903 Build 12345]
- PowerShell Version [e.g. 5.1.123]

**Additional context**
Add any other context about the problem here.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: cChoco Community Support
url: https://gitter.im/chocolatey/cchoco/
about: Please ask and answer questions here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature---enhancement-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature / Enhancement Request
about: Suggest an idea for improving cChoco.
title: ''
labels: 0 - _Triaging, Enhancement, Up For Grabs
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
38 changes: 38 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--- Please ensure you have raised an issue for discussion before creating a Pull Request -->
<!--- Provide a general summary of your changes in the Title above with the format `(GH-<ISSUE #>) Title` -->

## Description
<!--- Describe your changes in detail -->

## Related Issue
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
<!--- Please link to the issue here: -->
Fixes #

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots (if appropriate):

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the **CONTRIBUTING** document.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
8 changes: 7 additions & 1 deletion AppVeyor/AppVeyorInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#---------------------------------#
Write-Host 'Running AppVeyor install script' -ForegroundColor Yellow

#---------------------------------#
# Enable TLS 1.2 #
#---------------------------------#
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072

#---------------------------------#
# Install NuGet #
#---------------------------------#
Expand All @@ -29,8 +34,9 @@ Write-Host "Installed NuGet version '$($pkg.version)'"
# Install Modules #
#---------------------------------#
[version]$ScriptAnalyzerVersion = '1.8.1'
[version]$PesterVersion = '4.10.1'
Install-Module -Name 'PSScriptAnalyzer' -Repository PSGallery -Force -ErrorAction Stop -MaximumVersion $ScriptAnalyzerVersion
Install-Module -Name 'Pester' -SkipPublisherCheck -Repository PSGallery -Force -ErrorAction Stop
Install-Module -Name 'Pester' -SkipPublisherCheck -Repository PSGallery -Force -ErrorAction Stop -MaximumVersion $PesterVersion
Install-Module -Name 'xDSCResourceDesigner' -Repository PSGallery -Force -ErrorAction Stop

#---------------------------------#
Expand Down
188 changes: 188 additions & 0 deletions DSCResources/cChocoConfig/cChocoConfig.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Copyright (c) 2017 Chocolatey Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

<#
.Description
Returns the configuration for cChocoConfig.
.Example
Get-TargetResource -ConfigName cacheLocation -Ensure 'Present' -Value 'c:\temp\choco'
#>
function Get-TargetResource
{
[CmdletBinding()]
[OutputType([Hashtable])]
param
(
[parameter(Mandatory = $true)]
[string]
$ConfigName,

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

[parameter(Mandatory = $false)]
[string]
$Value
)

Write-Verbose "Starting cChocoConfig Get-TargetResource - Config Name: $ConfigName, Ensure: $Ensure"

$returnValue = @{
ConfigName = $ConfigName
Ensure = $Ensure
Value = $Value
}

$returnValue

}

<#
.Description
Performs the set for the cChocoConfig resource.
.Example
Set-TargetResource -ConfigName cacheLocation -Ensure 'Present' -Value 'c:\temp\choco'
#>
function Set-TargetResource
{
[CmdletBinding(SupportsShouldProcess=$true)]
param
(
[parameter(Mandatory = $true)]
[string]
$ConfigName,

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

[parameter(Mandatory = $false)]
[string]
$Value
)


Write-Verbose "Starting cChocoConfig Set-TargetResource - Config Name: $ConfigName, Ensure: $Ensure"

if ($pscmdlet.ShouldProcess("Choco config $ConfigName will be ensured $Ensure."))
{
if ($Ensure -eq 'Present')
{
Write-Verbose "Setting choco config $ConfigName."
choco config set --name "'$ConfigName'" --value "'$Value'"
}
else
{
Write-Verbose "Unsetting choco config $ConfigName."
choco config unset --name "'$ConfigName'"
}
}

}

<#
.Description
Performs the test for cChocoFeature.
.Example
Test-TargetResource -ConfigName cacheLocation -Ensure 'Present' -Value 'c:\temp\choco'
#>
function Test-TargetResource
{
[CmdletBinding()]
[OutputType([Boolean])]
param
(
[parameter(Mandatory = $true)]
[string]
$ConfigName,

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

[parameter(Mandatory = $false)]
[string]
$Value
)

Write-Verbose "Starting cChocoConfig Test-TargetResource - Config Name: $ConfigName, Ensure: $Ensure."

# validate value is given when ensure present
if ($Ensure -eq 'Present' -and (-not $PSBoundParameters.ContainsKey('Value') -or [String]::IsNullOrEmpty($Value))) {
throw "Missing parameter 'Value' when ensuring config is present!"
}

if($env:ChocolateyInstall -eq "" -or $null -eq $env:ChocolateyInstall)
{
$command = Get-Command -Name choco.exe -ErrorAction SilentlyContinue

if(!$command) {
throw "Unable to find choco.exe. Please make sure Chocolatey is installed correctly."
}

$chocofolder = Split-Path $command.Source

if( $chocofolder.EndsWith("bin") )
{
$chocofolder = Split-Path $chocofolder
}
}
else
{
$chocofolder = $env:ChocolateyInstall
}

if(!(Get-Item -Path $chocofolder -ErrorAction SilentlyContinue)) {
throw "Unable to find Chocolatey installation folder. Please make sure Chocolatey is installed and configured properly."
}

$configfolder = Join-Path -Path $chocofolder -ChildPath "config"
$configfile = Get-ChildItem -Path $configfolder | Where-Object {$_.Name -match "chocolatey.config$"}

if(!(Get-Item -Path $configfile.FullName -ErrorAction SilentlyContinue)) {
throw "Unable to find Chocolatey config file. Please make sure Chocolatey is installed and configured properly."
}

# There is currently no choco command that only returns the settings in an CSV format.
# choco config list -r shows settings, sources, features and a note about API keys.
$xml = [xml](Get-Content -Path $configfile.FullName)
$settings = $xml.chocolatey.config.add
foreach($setting in $settings)
{
# If the config name matches and it should be present, check the value and
# if it matches it returns true.
if($setting.key -eq $ConfigName -and $Ensure -eq 'Present')
{
return ($setting.value -eq $Value)
}
# If the config name matches and it should be absent, check the value and
# if it is null or empty, return true
elseif($setting.key -eq $ConfigName -and $Ensure -eq 'Absent')
{
return ([String]::IsNullOrEmpty($setting.value))
}
}

# If we get this far, the configuraion item hasn't been found.
# There is currently no value, so return false if it should be present.
# True otherwise.
return !($Ensure -eq 'Present')
}

Export-ModuleMember -Function *-TargetResource
9 changes: 9 additions & 0 deletions DSCResources/cChocoConfig/cChocoConfig.schema.mof
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

[ClassVersion("1.0.0.0"), FriendlyName("cChocoConfig")]
class cChocoConfig : OMI_BaseResource
{
[Key] String ConfigName;
[Write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] String Ensure;
[Write] String Value;
};

4 changes: 3 additions & 1 deletion DSCResources/cChocoInstaller/cChocoInstaller.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ Function Install-Chocolatey {
Write-Verbose "Env:ChocolateyInstall has $env:ChocolateyInstall"

#Download an execute install script
$file = Join-Path -Path $InstallDir -ChildPath 'install.ps1'
$tempPath = Join-Path -Path $env:TEMP -ChildPath ([GUID]::NewGuid().ToString())
New-Item -Path $tempPath -ItemType Directory | Out-Null
$file = Join-Path -Path $tempPath -ChildPath 'install.ps1'
Get-FileDownload -url $ChocoInstallScriptUrl -file $file
. $file

Expand Down
Loading

0 comments on commit f777bd0

Please sign in to comment.