-
Notifications
You must be signed in to change notification settings - Fork 130
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
{WIP}(PUP-3428) Configure Chocolatey #79
Closed
ferventcoder
wants to merge
1
commit into
chocolatey-archive:master
from
ferventcoder:ticket/master/PUP-3428-configure
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# chocolatey::source - Manage sources for Chocolatey | ||
# | ||
# @author Rob Reynolds, Rich Siegel, and puppet-chocolatey contributors | ||
# | ||
# @example Add a source | ||
# chocolatey::source {'dude': | ||
# ensure => 'present', | ||
# location => 'https://internal/ODatafeed', | ||
# } | ||
# | ||
# @example Disable default source | ||
# chocolatey::source {'chocolatey': | ||
# enable => false, | ||
# } | ||
# | ||
# @param [String] ensure Whether the source should exist or not. Defaults to | ||
# 'present'. Valid values are `present`, `absent`. | ||
# @param [String] source_name The name of the source. Defaults to the name | ||
# (`$title`) of of the resource. | ||
# @param [String] location The location of the source. Can be a url pointing to | ||
# and OData feed (like chocolatey/chocolatey_server), a CIFS (UNC) share, | ||
# or a local folder. Defaults to the name (`$title`) of of the resource. | ||
# @param [Boolean] enable Whether to use built-in shell or allow installer | ||
# to download 7zip to extract `chocolatey.nupkg` during installation. | ||
# Defaults to `true`. | ||
# @param [String] user_name Optional user name for authenticated feeds. Defaults | ||
# to `undef`. | ||
# @param [String] password Optional password for authenticated feeds. Defaults | ||
# to `undef`. | ||
define chocolatey::source ( | ||
$ensure = 'present', | ||
$source_name = $title, | ||
$location = $title, | ||
$enable = true, | ||
$user_name = undef, | ||
$password = undef | ||
) { | ||
|
||
require chocolatey | ||
|
||
#todo: do we fail if the version is wrong? | ||
if (versioncmp($::chocolateyversion, '0.9.9.0') >= 0) or ($::chocolateyversion == '0') { | ||
$_choco_exe_path = "${::choco_install_path}\\bin\\choco.exe" | ||
$_source_default_args = "-r -n ${source_name}" | ||
$_location_args = "-s ${location}" | ||
|
||
$_user_args = $user_name ? { | ||
undef => '', | ||
default => "-u ${user_name}", | ||
} | ||
|
||
$_pass_args = $password ? { | ||
undef => '', | ||
default => "-p ${password}", | ||
} | ||
|
||
if ($ensure == 'absent') { | ||
$_source_action = 'remove' | ||
exec { "chocolatey_source_${source_name}_${_source_action}": | ||
path => $::path, | ||
command => "${_choco_exe_path} source ${_source_action} ${_source_default_args}", | ||
onlyif => "cmd.exe /c ${_choco_exe_path} source list -r | findstr /B /I \"${source_name}\"", | ||
require => Exec['install_chocolatey_official'], | ||
} | ||
} else { | ||
if ($enable){ | ||
# Since we encrypt user/pass, it won't update the source if that is all that changes. | ||
#$_source_action = 'add' | ||
exec { "chocolatey_source_${source_name}_${_source_action}": | ||
path => $::path, | ||
command => "cmd.exe /c ${_choco_exe_path} source remove ${_source_default_args} && ${_choco_exe_path} source add ${_source_default_args} ${_location_args} ${_user_args} ${_pass_args}", | ||
unless => "cmd.exe /c ${_choco_exe_path} source list -r | findstr /X /I \"${source_name}.* - ${location}\"", | ||
require => Exec['install_chocolatey_official'], | ||
} | ||
|
||
$_source_action = 'enable' | ||
exec { "chocolatey_source_${source_name}_enable": | ||
path => $::path, | ||
command => "${_choco_exe_path} source ${_source_action} ${_source_default_args}", | ||
unless => "cmd.exe /c ${_choco_exe_path} source list -r | findstr /B /I /C:\"${source_name} -\"", | ||
require => Exec['install_chocolatey_official'], | ||
} | ||
} else { | ||
$_source_action = 'disable' | ||
exec { "chocolatey_source_${source_name}_${_source_action}": | ||
path => $::path, | ||
command => "${_choco_exe_path} source ${_source_action} ${_source_default_args}", | ||
unless => "cmd.exe /c ${_choco_exe_path} source list -r | findstr /B /I /C:\"${source_name} [Disabled]\"", | ||
require => Exec['install_chocolatey_official'], | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe 'chocolatey::source', :type => :define do | ||
let (:title) { 'choco_source' } | ||
|
||
context 'with older choco installed' do | ||
let(:facts) { | ||
{ | ||
:chocolateyversion => '0.9.8.33', | ||
:choco_install_path => 'C:\ProgramData\chocolatey', | ||
} | ||
} | ||
|
||
context "ensure => present" do | ||
let(:params) { { | ||
:ensure => 'present', | ||
:source_name => 'somewhere', | ||
:location => 'this', | ||
} } | ||
|
||
it 'should compile successfully' do | ||
catalogue | ||
end | ||
|
||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_add') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_enable') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_remove') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_disable') } | ||
end | ||
|
||
context "ensure => absent" do | ||
let(:params) { { | ||
:ensure => 'absent', | ||
:source_name => 'somewhere', | ||
} } | ||
|
||
it 'should compile successfully' do | ||
catalogue | ||
end | ||
|
||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_add') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_enable') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_remove') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_disable') } | ||
end | ||
|
||
context "enable => false" do | ||
let(:params) { { | ||
:ensure => 'present', | ||
:source_name => 'somewhere', | ||
:enable => false, | ||
} } | ||
|
||
it 'should compile successfully' do | ||
catalogue | ||
end | ||
|
||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_add') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_enable') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_remove') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_disable') } | ||
end | ||
end | ||
|
||
context 'without choco installed' do | ||
let(:facts) { | ||
{ | ||
:chocolateyversion => '0', | ||
:choco_install_path => 'C:\ProgramData\chocolatey', | ||
} | ||
} | ||
context "ensure => present" do | ||
let(:params) { { | ||
:ensure => 'present', | ||
:source_name => 'somewhere', | ||
:location => 'this', | ||
} } | ||
|
||
it 'should compile successfully' do | ||
catalogue | ||
end | ||
|
||
it { is_expected.to contain_exec('chocolatey_source_somewhere_add') } | ||
it { is_expected.to contain_exec('chocolatey_source_somewhere_enable') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_remove') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_disable') } | ||
end | ||
|
||
context "ensure => absent" do | ||
let(:params) { { | ||
:ensure => 'absent', | ||
:source_name => 'somewhere', | ||
} } | ||
|
||
it 'should compile successfully' do | ||
catalogue | ||
end | ||
|
||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_add') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_enable') } | ||
it { is_expected.to contain_exec('chocolatey_source_somewhere_remove') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_disable') } | ||
end | ||
|
||
context "enable => false" do | ||
let(:params) { { | ||
:ensure => 'present', | ||
:source_name => 'somewhere', | ||
:enable => false, | ||
} } | ||
|
||
it 'should compile successfully' do | ||
catalogue | ||
end | ||
|
||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_add') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_enable') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_remove') } | ||
it { is_expected.to contain_exec('chocolatey_source_somewhere_disable') } | ||
end | ||
|
||
|
||
end | ||
|
||
context 'with choco.exe installed' do | ||
let(:facts) { | ||
{ | ||
:chocolateyversion => '0.9.9.8', | ||
:choco_install_path => 'C:\ProgramData\chocolatey', | ||
} | ||
} | ||
|
||
context "ensure => present" do | ||
let(:params) { { | ||
:ensure => 'present', | ||
:source_name => 'somewhere', | ||
:location => 'this', | ||
} } | ||
|
||
it 'should compile successfully' do | ||
catalogue | ||
end | ||
|
||
it { is_expected.to contain_exec('chocolatey_source_somewhere_add') } | ||
it { is_expected.to contain_exec('chocolatey_source_somewhere_enable') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_remove') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_disable') } | ||
end | ||
|
||
context "ensure => absent" do | ||
let(:params) { { | ||
:ensure => 'absent', | ||
:source_name => 'somewhere', | ||
} } | ||
|
||
it 'should compile successfully' do | ||
catalogue | ||
end | ||
|
||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_add') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_enable') } | ||
it { is_expected.to contain_exec('chocolatey_source_somewhere_remove') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_disable') } | ||
end | ||
|
||
context "enable => false" do | ||
let(:params) { { | ||
:ensure => 'present', | ||
:source_name => 'somewhere', | ||
:enable => false, | ||
} } | ||
|
||
it 'should compile successfully' do | ||
catalogue | ||
end | ||
|
||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_add') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_enable') } | ||
it { is_expected.not_to contain_exec('chocolatey_source_somewhere_remove') } | ||
it { is_expected.to contain_exec('chocolatey_source_somewhere_disable') } | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't realize this was bumped over here - no wonder I had to reimplement.