diff --git a/Puppetfile b/Puppetfile index abdc80ce0..6deb62b32 100644 --- a/Puppetfile +++ b/Puppetfile @@ -66,6 +66,10 @@ mod 'galera', :commit => 'a2ecf273aef9ef9193bba35c235fb7b8b821a0c3', :git => 'https://github.com/redhat-openstack/puppet-galera.git' +mod 'git', + :commit => '8e7f586', + :git => 'https://github.com/puppetlabs/puppetlabs-git.git' + mod 'glance', :commit => 'c3b685ba0dfd4a0ac78642844d9c16e5f472a78f', :git => 'https://github.com/openstack/puppet-glance.git' diff --git a/git/.fixtures.yml b/git/.fixtures.yml new file mode 100644 index 000000000..2aa9e3d77 --- /dev/null +++ b/git/.fixtures.yml @@ -0,0 +1,5 @@ +fixtures: + repositories: + vcsrepo: git://github.com/puppetlabs/puppetlabs-vcsrepo.git + symlinks: + git: "#{source_dir}" diff --git a/git/.gitignore b/git/.gitignore new file mode 100644 index 000000000..34894fa6b --- /dev/null +++ b/git/.gitignore @@ -0,0 +1,7 @@ +pkg/ +Gemfile.lock +vendor/ +spec/fixtures/ +.vagrant/ +.bundle/ +coverage/ \ No newline at end of file diff --git a/git/.travis.yml b/git/.travis.yml new file mode 100644 index 000000000..c0d90693f --- /dev/null +++ b/git/.travis.yml @@ -0,0 +1,21 @@ +--- +language: ruby +bundler_args: --without development system_tests +script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'" +matrix: + fast_finish: true + include: + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 1.0" + - rvm: 1.8.7 + env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 2.0" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 1.0" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 2.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 1.0" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.0" FACTER_GEM_VERSION="~> 2.0" +notifications: + email: false diff --git a/git/CHANGELOG.md b/git/CHANGELOG.md new file mode 100644 index 000000000..004c37d00 --- /dev/null +++ b/git/CHANGELOG.md @@ -0,0 +1,56 @@ +##2015-05-26 - Release 0.4.0 +###Summary +This release adds greater flexibility to `git` and `git_config` and includes a couple of bug fixes, including fixing `git_config` with multiple users. + +####Deprecations +- The `section` parameter in `git_config` and `git::config` has been deprecated. The full option name should be passed to the `key` parameter instead (i.e., "user.email") + +####Features +- Refactored existing facts and added spec tests (MODULES-1571) +- Test and doc updates +- New parameters in class `git`: + - `package_manage` + - `package_ensure` + - `configs` + +####Bugfixes +- Only run if git is actually installed (MODULES-1238) +- Fix `git_config` to work with multiple users (MODULES-1863) + +##2014-11-18 - Release 0.3.0 +###Summary +This release primarily includes improvements to `git::config` and the addition of the `git_config` type&provider, along with much improved testing + +####Features +- Add `user` and `scope` parameter to `git::config` +- Add `git_config` type +- Refactor `git::config` to use `git_config` +- Test improvements + +####Bugfixes +- Redirect stderr to the correct place on windows + +##2014-07-15 - Release 0.2.0 +###Summary +This release updates metadata.json so the module can be uninstalled and +upgraded via the puppet module command. It also lets you set the +`package_name`. + +####Features +- Ability to set `package_name` + +##2014-06-25 - Release 0.1.0 +###Summary +This release adds git::subtree and git::config, as well as fixes up the +documentation and unit tests. + +####Features +- README improvements. +- Add git::subtree class to install git-subtree. +- Add git::config resource + +####Bugfixes +- Fix git_version fact. + +##2011-06-03 - Release 0.0.1 +- Initial commit diff --git a/git/Gemfile b/git/Gemfile new file mode 100644 index 000000000..b9665d6b1 --- /dev/null +++ b/git/Gemfile @@ -0,0 +1,53 @@ +source ENV['GEM_SOURCE'] || "https://rubygems.org" + +def location_for(place, fake_version = nil) + if place =~ /^(git:[^#]*)#(.*)/ + [fake_version, { :git => $1, :branch => $2, :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path($1), :require => false }] + else + [place, { :require => false }] + end +end + +is_ruby18 = RUBY_VERSION.start_with? '1.8' + +group :development, :test do + gem 'rake', :require => false + if is_ruby18 + gem 'rspec', "~> 3.1.0", :require => false + end + gem 'rspec-puppet', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'puppet-lint', :require => false + gem 'pry', :require => false + gem 'simplecov', :require => false + gem 'metadata-json-lint', :require => false +end + +beaker_version = ENV['BEAKER_VERSION'] +group :system_tests do + gem 'serverspec', :require => false + if beaker_version + gem 'beaker', *location_for(beaker_version) + else + gem 'beaker', :require => false + end + gem 'beaker-rspec', :require => false +end + +facter_version = ENV['FACTER_GEM_VERSION'] +if facter_version + gem 'facter', *location_for(facter_version) +else + gem 'facter', :require => false +end + +puppet_version = ENV['PUPPET_GEM_VERSION'] +if puppet_version + gem 'puppet', *location_for(puppet_version) +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/git/LICENSE b/git/LICENSE new file mode 100644 index 000000000..297f85cfa --- /dev/null +++ b/git/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2013 Puppet Labs + + 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. diff --git a/git/README.md b/git/README.md new file mode 100644 index 000000000..32f5c1dcf --- /dev/null +++ b/git/README.md @@ -0,0 +1,107 @@ +#git + +####Table of Contents + +1. [Overview - What is the git module?](#overview) +2. [Module Description - What does the module do?](#module-description) +3. [Setup - The basics of getting started with git](#setup) + * [What git affects](#what-registry-affects) +4. [Usage - Configuration options and additional functionality](#usage) +6. [Limitations - OS compatibility, etc.](#limitations) +7. [Development - Guide for contributing to the module](#development) + +##Overview + +Simple module that can install git or gitosis + +##Module Description + +This module installs the git revision control system on a target node. It does not manage a git server or any associated services; it simply ensures a bare minimum set of features (e.g. just a package) to use git. + +##Setup + +###What git affects + +* Package['git'] + +The specifics managed by the module may vary depending on the platform. + +##Usage + +###I just want `git` installed +Simply include the `git` class. + +```puppet +include git +``` + +###I want to configure `git` using hiera + +```yaml +git::configs: + user.name: 'test' + user.email: 'test@example.com' + core.filemode: + value: false + scope: system +``` + +If using the flat config syntax, options common to all items can be set: + +```yaml +git::configs: + core.filemode: false +git::configs_defaults: + scope: system +``` + +###I want to use `git subtree` with bash completion + +```puppet +include git::subtree +``` + +###I want to set my user.name and user.email + +```puppet +git::config { 'user.name': + value => 'John Doe', +} + +git::config { 'user.email': + value => 'john.doe@example.com', +} +``` + +##Reference + +###Classes + +* `git`: Installs the git client package. +* `gitosis`: Installs the gitosis package. No configuration +* `subtree`: Installs and configures git-subtree for git 1.7 and up. + +###Resources + +* `git::config`: Set git global configuration for the user running puppet, for the specified `$user` or for the system. + +###Facts + +* `git_exec_path`: Path to the directory containing all `git-*` commands. +* `git_version`: Version of git that is installed. Undefined if not installed. + +##Limitations + +This module is known to work with the following operating system families: + + - RedHat 5, 6 + - Debian 6.0.7 or newer + - Ubuntu 12.04 or newer + +##Development + +Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. + +We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. + +You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing) diff --git a/git/Rakefile b/git/Rakefile new file mode 100644 index 000000000..cd3d37995 --- /dev/null +++ b/git/Rakefile @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/rake_tasks' diff --git a/git/files/subtree/bash_completion.sh b/git/files/subtree/bash_completion.sh new file mode 100644 index 000000000..f2683e449 --- /dev/null +++ b/git/files/subtree/bash_completion.sh @@ -0,0 +1,25 @@ +#!bash +# +# bash completion support for Git subtree. +# +# To use this routine: +# +# 1) Make sure you have installed and configured the core Git completion script, which is required to make this script work; +# 2) Copy this file to somewhere (e.g. ~/.git-subtree-completion.sh); +# 3) Added the following line to your .bashrc: +# source ~/.git-subtree-completion.sh +# + +_git_subtree () +{ + local cur="${COMP_WORDS[COMP_CWORD]}" + + if [ $COMP_CWORD -eq 2 ]; then + __gitcomp "add merge pull push split" + return + elif [ $COMP_CWORD -eq 3 ]; then + __gitcomp "--prefix=" + return + fi + __gitcomp "$(__git_remotes)" +} diff --git a/git/lib/facter/git_exec_path.rb b/git/lib/facter/git_exec_path.rb new file mode 100644 index 000000000..3a4ad8f04 --- /dev/null +++ b/git/lib/facter/git_exec_path.rb @@ -0,0 +1,25 @@ +# Fact: git_exec_path +# +# Purpose: get git's exec path +# +# Resolution: +# Uses git's --exec-path flag +# +# Caveats: +# none +# +# Notes: +# None +Facter.add('git_exec_path') do + case Facter.value(:osfamily) + when 'windows' + null_path = 'nul' + else + null_path = '/dev/null' + end + git_exec_path_cmd = "git --exec-path 2>#{null_path}" + setcode do + Facter::Util::Resolution.exec(git_exec_path_cmd) + end +end + diff --git a/git/lib/facter/git_html_path.rb b/git/lib/facter/git_html_path.rb new file mode 100644 index 000000000..471fed730 --- /dev/null +++ b/git/lib/facter/git_html_path.rb @@ -0,0 +1,24 @@ +# Fact: git_html_path +# +# Purpose: get git's html path +# +# Resolution: +# Uses git's --html-path flag +# +# Caveats: +# none +# +# Notes: +# None +Facter.add('git_html_path') do + case Facter.value(:osfamily) + when 'windows' + null_path = 'nul' + else + null_path = '/dev/null' + end + git_html_path_cmd = "git --html-path 2>#{null_path}" + setcode do + Facter::Util::Resolution.exec(git_html_path_cmd) + end +end diff --git a/git/lib/facter/git_version.rb b/git/lib/facter/git_version.rb new file mode 100644 index 000000000..c0ece6ae9 --- /dev/null +++ b/git/lib/facter/git_version.rb @@ -0,0 +1,21 @@ +# Fact: git_version +# +# Purpose: get git's current version +# +# Resolution: +# Uses git's --version flag and parses the result from 'version' +# +# Caveats: +# none +# +# Notes: +# None +Facter.add('git_version') do + setcode do + if Facter::Util::Resolution.which('git') + git_version_cmd = 'git --version 2>&1' + git_version_result = Facter::Util::Resolution.exec(git_version_cmd) + git_version_result.to_s.lines.first.strip.split(/version/)[1].strip + end + end +end diff --git a/git/lib/puppet/parser/functions/git_config_hash.rb b/git/lib/puppet/parser/functions/git_config_hash.rb new file mode 100644 index 000000000..edb6fddac --- /dev/null +++ b/git/lib/puppet/parser/functions/git_config_hash.rb @@ -0,0 +1,25 @@ +# +# config_hash.rb +# + +module Puppet::Parser::Functions + newfunction(:git_config_hash, :type => :rvalue, :doc => <<-EOS +This function ensures the proper structure for git configuration options. +*Examples:* + git_config_hash({"foo" => 1, "bar" => {"value" => 2}}) +Would return: {"foo" => {"value" => 1}, "bar" => {"value" => 2}} + EOS + ) do |arguments| + + raise(Puppet::ParseError, "git_config_hash(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + configs = arguments[0] + + unless configs.is_a?(Hash) + raise(Puppet::ParseError, 'git_config_hash(): Requires hash to work with') + end + + return Hash[configs.map {|k, v| [k, v.is_a?(Hash) ? v : {"value" => v}] }] + end +end diff --git a/git/lib/puppet/provider/git_config/git_config.rb b/git/lib/puppet/provider/git_config/git_config.rb new file mode 100644 index 000000000..c0e9d6331 --- /dev/null +++ b/git/lib/puppet/provider/git_config/git_config.rb @@ -0,0 +1,53 @@ +require "shellwords" + +Puppet::Type.type(:git_config).provide(:git_config) do + + mk_resource_methods + + def value + require 'etc' + user = @property_hash[:user] = @resource[:user] + key = @property_hash[:key] = @resource[:key] + section = @property_hash[:section] = @resource[:section] + scope = @property_hash[:scope] = @resource[:scope] + home = Etc.getpwnam(user)[:dir] + + # Backwards compatibility with deprecated $section parameter. + if section && !section.empty? + key = "#{section}.#{key}" + end + + current = Puppet::Util::Execution.execute( + "cd / ; git config --#{scope} --get #{key}", + :uid => user, + :failonfail => false, + :combine => true, + :custom_environment => { 'HOME' => home } + ) + @property_hash[:value] = current.strip + @property_hash[:value] + end + + def value=(value) + require 'etc' + user = @resource[:user] + key = @resource[:key] + section = @resource[:section] + scope = @resource[:scope] + home = Etc.getpwnam(user)[:dir] + + # Backwards compatibility with deprecated $section parameter. + if section && !section.empty? + key = "#{section}.#{key}" + end + + Puppet::Util::Execution.execute( + "cd / ; git config --#{scope} #{key} #{value.shellescape}", + :uid => user, + :failonfail => true, + :combine => true, + :custom_environment => { 'HOME' => home } + ) + end + +end diff --git a/git/lib/puppet/type/git_config.rb b/git/lib/puppet/type/git_config.rb new file mode 100644 index 000000000..55c330e52 --- /dev/null +++ b/git/lib/puppet/type/git_config.rb @@ -0,0 +1,67 @@ +Puppet::Type.newtype(:git_config) do + + desc <<-DOC + Used to configure git + === Examples + + + git_config { 'user.name': + value => 'John Doe', + } + + git_config { 'user.email': + value => 'john.doe@example.com', + } + + git_config { 'user.name': + value => 'Mike Color', + user => 'vagrant', + require => Class['git'], + } + + git_config { 'http.sslCAInfo': + value => $companyCAroot, + user => 'root', + scope => 'system', + require => Company::Certificate['companyCAroot'], + } + DOC + + validate do + fail('it is required to pass "value"') if self[:value].nil? || self[:value].empty? || self[:value] == :absent + warning('Parameter `section` is deprecated, supply the full option name (e.g. "user.email") in the `key` parameter') if + self[:section] && !self[:section].empty? + end + + newparam(:name, :namevar => true) do + desc "The name of the config" + end + + newproperty(:value) do + desc "The config value. Example Mike Color or john.doe@example.com" + end + + newparam(:user) do + desc "The user for which the config will be set. Default value: root" + defaultto "root" + end + + newparam(:key) do + desc "The configuration key. Example: user.email." + end + + autorequire(:user) do + self[:user] + end + + newparam(:section) do + desc "Deprecated: the configuration section. For example, to set user.email, use section => \"user\", key => \"email\"." + defaultto "" + end + + newparam(:scope) do + desc "The scope of the configuration, can be system or global. Default value: global" + defaultto "global" + end + +end diff --git a/git/manifests/config.pp b/git/manifests/config.pp new file mode 100644 index 000000000..a582f489f --- /dev/null +++ b/git/manifests/config.pp @@ -0,0 +1,73 @@ +# == Define: git::config +# +# Used to configure git +# +# === Parameters +# +# [*value*] +# The config value. Example: Mike Color or john.doe@example.com. +# See examples below. +# +# [*key*] +# The name of the option to be set. Example: user.email. +# Default value: same as resource name. +# +# [*user*] +# The user for which the config will be set. Default value: root +# +# [*scope*] +# The scope of the configuration, can be system or global. +# Default value: global +# +# === Examples +# +# Provide some examples on how to use this type: +# +# git::config { 'user.name': +# value => 'John Doe', +# } +# +# git::config { 'user.email': +# value => 'john.doe@example.com', +# } +# +# git::config { 'user.name': +# value => 'Mike Color', +# user => 'vagrant', +# require => Class['git'], +# } +# +# git::config { 'http.sslCAInfo': +# value => $companyCAroot, +# user => 'root', +# scope => 'system', +# require => Company::Certificate['companyCAroot'], +# } +# +# === Authors +# +# === Copyright +# +define git::config ( + $value, + $key = $name, + $section = undef, + $user = 'root', + $scope = 'global', +) { + # Backwards compatibility with deprecated $section parameter. + # (Old versions took separate $section and $key, e.g. "user" and "email".) + if $section != undef { + warning('Parameter `section` is deprecated, supply the full option name (e.g. "user.email") in the `key` parameter') + $_key = "${section}.${key}" + } else { + $_key = $key + } + + git_config { $title: + key => $_key, + value => $value, + user => $user, + scope => $scope, + } +} diff --git a/git/manifests/gitosis.pp b/git/manifests/gitosis.pp new file mode 100644 index 000000000..64b7b2df3 --- /dev/null +++ b/git/manifests/gitosis.pp @@ -0,0 +1,13 @@ +# Class: gitosis +# +# This installs and configures gitosis +# +# Requires: +# - Class[git] +# +class git::gitosis { + include ::git + package {'gitosis': + ensure => present + } +} diff --git a/git/manifests/init.pp b/git/manifests/init.pp new file mode 100644 index 000000000..77a79610c --- /dev/null +++ b/git/manifests/init.pp @@ -0,0 +1,43 @@ +# Class: git +# +# This class installs and configures git +# +# Actions: +# - Install the git package +# - Configure git +# +# Sample Usage: +# class { 'git': } +# +# === Parameters +# +# [*package_ensure*] +# Value to be passed to ensure in the package resource. Defaults to installed. +# +# [*package_manage*] +# boolean toggle to overide the management of the git package. +# You may want to change this behavior if another module manages git packages +# defaults to true +# +# [*configs*] +# hash of configurations as per the git::config defined type +# +# [*configs_defaults*] +# hash of configuration defaults as per the git::config defined type +# to use for every *configs* item +# +class git ( + $package_name = 'git', + $package_ensure = 'installed', + $package_manage = true, + $configs = {}, + $configs_defaults = {} +) { + if ( $package_manage ) { + package { $package_name: + ensure => $package_ensure, + } + } + + create_resources(git::config, git_config_hash($configs), $configs_defaults) +} diff --git a/git/manifests/subtree.pp b/git/manifests/subtree.pp new file mode 100644 index 000000000..199b6dfe0 --- /dev/null +++ b/git/manifests/subtree.pp @@ -0,0 +1,57 @@ +# == Class: git::subtree +# +# Installs and configure git-subtree +# +class git::subtree { + + include ::git + + Package['git'] -> Class['git::subtree'] + + if (versioncmp('1.7.0', $::git_version) > 0) { + fail 'git-subtree requires git 1.7 or later!' + } + + if (versioncmp('1.7.11', $::git_version) > 0) { + $source_dir = '/usr/src/git-subtree' + vcsrepo { $source_dir: + ensure => present, + source => 'https://github.com/apenwarr/git-subtree.git', + provider => 'git', + revision => '2793ee6ba', + before => Exec['Build git-subtree'], + } + } else { + $source_dir = "${::git_html_path}/contrib/subtree" + } + + exec { 'Build git-subtree': + command => "make prefix=/usr libexecdir=${::git_exec_path}", + creates => "${source_dir}/git-subtree", + cwd => $source_dir, + path => ['/usr/bin', '/bin', '/usr/local/bin'], + } + -> + package { [ 'asciidoc', 'xmlto', ]: + ensure => present, + } + -> + exec { 'Install git-subtree': + command => "make prefix=/usr libexecdir=${::git_exec_path} install", + onlyif => [ + "test ! -f ${::git_exec_path}/git-subtree", + 'test ! -f /usr/share/man/man1/git-subtree.1', + ], + cwd => $source_dir, + path => ['/usr/bin', '/bin', '/usr/local/bin'], + } + + file { '/etc/bash_completion.d/git-subtree': + ensure => file, + source => 'puppet:///modules/git/subtree/bash_completion.sh', + owner => 'root', + group => 'root', + mode => '0644', + } + +} diff --git a/git/metadata.json b/git/metadata.json new file mode 100644 index 000000000..a8a76c68a --- /dev/null +++ b/git/metadata.json @@ -0,0 +1,56 @@ +{ + "name": "puppetlabs-git", + "version": "0.4.0", + "author": "Puppet Labs", + "summary": "Module for installing Git or Gitosis.", + "license": "Apache-2.0", + "source": "https://github.com/puppetlabs/puppetlabs-git", + "project_page": "https://github.com/puppetlabs/puppetlabs-git", + "issues_url": "https://tickets.puppetlabs.com/browse/MODULES", + "operatingsystem_support": [ + { + "operatingsystem": "RedHat", + "operatingsystemrelease": [ + "5", + "6", + "7" + ] + }, + { + "operatingsystem": "CentOS", + "operatingsystemrelease": [ + "5", + "6", + "7" + ] + }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "6", + "7" + ] + }, + { + "operatingsystem": "Ubuntu", + "operatingsystemrelease": [ + "10.04", + "12.04", + "14.04" + ] + } + ], + "requirements": [ + { + "name": "pe", + "version_requirement": "3.x" + }, + { + "name": "puppet", + "version_requirement": "3.x" + } + ], + "dependencies": [ + {"name":"puppetlabs/stdlib","version_requirement":">= 3.2.0"} + ] +} diff --git a/git/spec/acceptance/class_spec.rb b/git/spec/acceptance/class_spec.rb new file mode 100644 index 000000000..1f8471081 --- /dev/null +++ b/git/spec/acceptance/class_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper_acceptance' + +describe 'git class' do + + context 'default parameters' do + # Using puppet_apply as a helper + it 'should work idempotently with no errors' do + pp = <<-EOS + class { 'git': } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe package('git') do + it { should be_installed } + end + end +end diff --git a/git/spec/acceptance/git_config_different_users_spec.rb b/git/spec/acceptance/git_config_different_users_spec.rb new file mode 100644 index 000000000..4c4d5e142 --- /dev/null +++ b/git/spec/acceptance/git_config_different_users_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper_acceptance' + +describe 'git::config class' do + + context 'with some user settings' do + it 'should work idempotently with no errors' do + pp = <<-EOS + package { 'git': } + -> + git::config { 'Root User Email': + key => 'user.email', + value => 'john.doe@example.com', + } + -> + user { 'janedoe': + ensure => 'present', + managehome => true, + } + -> + file { '/home/janedoe/.gitconfig': + ensure => 'present', + } + -> + git::config { 'Jane User Email': + key => 'user.email', + user => 'janedoe', + value => 'jane.doe@example.com', + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe file('/home/janedoe/.gitconfig') do + its(:content) { should match /email = jane.doe@example.com/ } + end + + describe file('/root/.gitconfig') do + its(:content) { should match /email = john.doe@example.com/ } + end + end +end diff --git a/git/spec/acceptance/git_config_provider_spec.rb b/git/spec/acceptance/git_config_provider_spec.rb new file mode 100644 index 000000000..ca9863d30 --- /dev/null +++ b/git/spec/acceptance/git_config_provider_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper_acceptance' + +describe 'git::config class' do + + context 'with some user settings' do + it 'should work idempotently with no errors' do + pp = <<-EOS + package { 'git': } + -> + git::config { 'user.name': + value => 'John Doe', + } + -> + git::config { 'user.email': + value => 'john.doe@example.com', + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe file('/root/.gitconfig') do + its(:content) { should match /email = john.doe@example.com/ } + its(:content) { should match /name = John Doe/ } + end + end +end diff --git a/git/spec/acceptance/nodesets/centos-64-x64.yml b/git/spec/acceptance/nodesets/centos-64-x64.yml new file mode 100644 index 000000000..d19aa6951 --- /dev/null +++ b/git/spec/acceptance/nodesets/centos-64-x64.yml @@ -0,0 +1,11 @@ +HOSTS: + centos-64-x64: + roles: + - master + platform: el-6-x86_64 + box : centos-64-x64-vbox4210-nocm + box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box + hypervisor : vagrant +CONFIG: + log_level: verbose + type: foss diff --git a/git/spec/acceptance/nodesets/default.yml b/git/spec/acceptance/nodesets/default.yml new file mode 100644 index 000000000..b392dab75 --- /dev/null +++ b/git/spec/acceptance/nodesets/default.yml @@ -0,0 +1,12 @@ +HOSTS: + ubuntu-server-12042-x64: + roles: + - master + platform: ubuntu-server-12.04-amd64 + box: ubuntu-server-12042-x64-vbox4210-nocm + box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/git/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml b/git/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml new file mode 100644 index 000000000..b392dab75 --- /dev/null +++ b/git/spec/acceptance/nodesets/ubuntu-server-12042-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + ubuntu-server-12042-x64: + roles: + - master + platform: ubuntu-server-12.04-amd64 + box: ubuntu-server-12042-x64-vbox4210-nocm + box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/git/spec/classes/git_gitosis_spec.rb b/git/spec/classes/git_gitosis_spec.rb new file mode 100644 index 000000000..eb8ceada6 --- /dev/null +++ b/git/spec/classes/git_gitosis_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe 'git::gitosis' do + + context 'defaults' do + it { should contain_package('gitosis') } + it { should contain_class('git') } + it { should create_class('git::gitosis') } + end +end diff --git a/git/spec/classes/git_spec.rb b/git/spec/classes/git_spec.rb new file mode 100644 index 000000000..fabdf5194 --- /dev/null +++ b/git/spec/classes/git_spec.rb @@ -0,0 +1,70 @@ +require 'spec_helper' + +describe 'git' do + + context 'defaults' do + it { should contain_package('git') } + end + + context 'with package_manage set to false' do + let(:params) { + { + :package_manage => false, + } + } + it { should_not contain_package('git') } + end + + context 'with a custom git package name' do + let(:params) { + { + :package_name => 'gitolite', + } + } + it { should contain_package('gitolite') } + end + + context 'with package_ensure => latest' do + let(:params) { + { + :package_ensure => 'latest', + } + } + it { should contain_package('git').with( + { + 'ensure' => 'latest' + } + )} + end + + context 'with configs' do + let(:params) { + { + :configs => { + "user.name" => {"value" => "test"}, + "user.email" => "test@example.com" + } + } + } + it { should contain_git__config('user.name') } + it { should contain_git__config('user.email') } + end + + context 'with configs and configs defaults' do + let(:params) { + { + :configs => { + "core.filemode" => false + }, + :configs_defaults => { + "scope" => "system" + } + } + } + it { should contain_git__config('core.filemode').with( + 'value' => false, + 'scope' => 'system' + ) } + end + +end diff --git a/git/spec/classes/git_subtree_spec.rb b/git/spec/classes/git_subtree_spec.rb new file mode 100644 index 000000000..137e59241 --- /dev/null +++ b/git/spec/classes/git_subtree_spec.rb @@ -0,0 +1,77 @@ +require 'spec_helper' + +describe 'git::subtree' do + + versions = ['1.6.0', '1.7.0', '1.7.11'] + versions.each do |version| + context "when git version is #{version}" do + let(:facts) { { + :git_version => version, + } } + if version < '1.7.0' + it 'should fail' do + expect { should create_class('git::subtree') }.to raise_error(Puppet::Error, /git-subtree requires git 1.7 or later!/) + end + else + it { should create_class('git::subtree') } + it { should contain_class('git') } + it { should contain_package('asciidoc') } + it { should contain_package('xmlto') } + it { should contain_exec('Install git-subtree') } + it { should contain_exec('Build git-subtree') } + + it { should create_file('/etc/bash_completion.d/git-subtree').with({ + :ensure => 'file', + :source => 'puppet:///modules/git/subtree/bash_completion.sh', + :mode => '0644', + })} + end + end + end + + context 'when git version > 1.7.0 and < 1.7.11' do + let(:facts) { { + :git_version => '1.7.0', + :git_exec_path => '/usr/lib/git-core', + :git_html_path => "/usr/share/doc/git" + } } + + it { should create_vcsrepo('/usr/src/git-subtree').with({ + :ensure => 'present', + :source => 'https://github.com/apenwarr/git-subtree.git', + :provider => 'git', + :revision => '2793ee6ba', + })} + + it { should create_exec('Build git-subtree').with({ + :command => 'make prefix=/usr libexecdir=/usr/lib/git-core', + :creates => '/usr/src/git-subtree/git-subtree', + :cwd => '/usr/src/git-subtree', + })} + + it { should create_exec('Install git-subtree').with({ + :command => 'make prefix=/usr libexecdir=/usr/lib/git-core install', + :cwd => '/usr/src/git-subtree', + })} + end + + context 'when git version >= 1.7.11' do + let(:facts) { { + :git_version => '1.7.11', + :git_exec_path => '/usr/lib/git-core', + :git_html_path => "/usr/share/doc/git" + } } + + it { should create_exec('Build git-subtree').with({ + :creates => '/usr/share/doc/git/contrib/subtree/git-subtree', + :cwd => '/usr/share/doc/git/contrib/subtree', + })} + + it { should create_exec('Install git-subtree').with({ + :command => 'make prefix=/usr libexecdir=/usr/lib/git-core install', + :cwd => '/usr/share/doc/git/contrib/subtree', + })} + end + + +end diff --git a/git/spec/defines/git_config_spec.rb b/git/spec/defines/git_config_spec.rb new file mode 100644 index 000000000..4149fc77a --- /dev/null +++ b/git/spec/defines/git_config_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe 'git::config', :type => :define do + context 'has working default parameters' do + let(:title) { 'user.name' } + let(:params) { + { + :value => 'JC Denton', + } + } + it do + should contain_git_config('user.name').with( + 'value' => 'JC Denton', + 'key' => 'user.name', + 'user' => 'root' + ) + have_git_config_resource_count(1) + end + end + context 'allows you to change user' do + let(:title) { 'user.email' } + let(:params) { + { + :value => 'jcdenton@UNATCO.com', + :user => 'admin' + } + } + it do + should contain_git_config('user.email').with( + 'value' => 'jcdenton@UNATCO.com', + 'key' => 'user.email', + 'user' => 'admin' + ) + have_git_config_resource_count(1) + end + end +end diff --git a/git/spec/spec_helper.rb b/git/spec/spec_helper.rb new file mode 100644 index 000000000..2c6f56649 --- /dev/null +++ b/git/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/git/spec/spec_helper_acceptance.rb b/git/spec/spec_helper_acceptance.rb new file mode 100644 index 000000000..de3635102 --- /dev/null +++ b/git/spec/spec_helper_acceptance.rb @@ -0,0 +1,24 @@ +require 'beaker-rspec/spec_helper' +require 'beaker-rspec/helpers/serverspec' + +hosts.each do |host| + # Install Puppet + install_puppet +end + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Readable test descriptions + c.formatter = :documentation + + # Configure all nodes in nodeset + c.before :suite do + # Install module and dependencies + puppet_module_install(:source => proj_root, :module_name => 'git') + hosts.each do |host| + on host, puppet('module', 'install', 'puppetlabs-vcsrepo'), { :acceptable_exit_codes => [0,1] } + end + end +end \ No newline at end of file diff --git a/git/spec/unit/facter/git_exec_path_spec.rb b/git/spec/unit/facter/git_exec_path_spec.rb new file mode 100644 index 000000000..0394869a0 --- /dev/null +++ b/git/spec/unit/facter/git_exec_path_spec.rb @@ -0,0 +1,27 @@ +require "spec_helper" + +describe Facter::Util::Fact do + before { + Facter.clear + } + + describe "git_exec_path" do + + context 'windows' do + it do + Facter.fact(:osfamily).stubs(:value).returns('windows') + Facter::Util::Resolution.expects(:exec).with("git --exec-path 2>nul").returns('windows_path_change') + Facter.fact(:git_exec_path).value.should == 'windows_path_change' + end + end + + context 'non-windows' do + it do + Facter.fact(:osfamily).stubs(:value).returns('RedHat') + Facter::Util::Resolution.expects(:exec).with("git --exec-path 2>/dev/null").returns('/usr/libexec/git-core') + Facter.fact(:git_exec_path).value.should == '/usr/libexec/git-core' + end + end + + end +end \ No newline at end of file diff --git a/git/spec/unit/facter/git_html_path_spec.rb b/git/spec/unit/facter/git_html_path_spec.rb new file mode 100644 index 000000000..4f332e248 --- /dev/null +++ b/git/spec/unit/facter/git_html_path_spec.rb @@ -0,0 +1,27 @@ +require "spec_helper" + +describe Facter::Util::Fact do + before { + Facter.clear + } + + describe "git_html_path" do + + context 'windows' do + it do + Facter.fact(:osfamily).stubs(:value).returns('windows') + Facter::Util::Resolution.expects(:exec).with("git --html-path 2>nul").returns('windows_path_change') + Facter.fact(:git_html_path).value.should == 'windows_path_change' + end + end + + context 'non-windows' do + it do + Facter.fact(:osfamily).stubs(:value).returns('RedHat') + Facter::Util::Resolution.expects(:exec).with("git --html-path 2>/dev/null").returns('/usr/share/doc/git-1.7.1') + Facter.fact(:git_html_path).value.should == '/usr/share/doc/git-1.7.1' + end + end + + end +end \ No newline at end of file diff --git a/git/spec/unit/facter/git_version_spec.rb b/git/spec/unit/facter/git_version_spec.rb new file mode 100644 index 000000000..e12057700 --- /dev/null +++ b/git/spec/unit/facter/git_version_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe Facter::Util::Fact do + before { + Facter.clear + } + + describe "git_version" do + context 'vanilla git' do + it do + git_version_output = 'git version 2.1.2' + Facter::Util::Resolution.expects(:exec).with("git --version 2>&1").returns(git_version_output) + Facter.value(:git_version).should == "2.1.2" + end + end + + context 'git with hub' do + it do + git_version_output = <<-EOS +git version 2.1.2 +hub version 1.12.2 + EOS + Facter::Util::Resolution.expects(:exec).with("git --version 2>&1").returns(git_version_output) + Facter.value(:git_version).should == "2.1.2" + end + end + + context 'no git present' do + it do + Facter::Util::Resolution.expects(:which).with("git").returns(false) + Facter.value(:git_version).should be_nil + end + end + end +end diff --git a/git/spec/unit/puppet/provider/git_config/git_config_spec.rb b/git/spec/unit/puppet/provider/git_config/git_config_spec.rb new file mode 100644 index 000000000..6f60390bf --- /dev/null +++ b/git/spec/unit/puppet/provider/git_config/git_config_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe Puppet::Type.type(:git_config).provider(:git_config) do + + let(:resource) { Puppet::Type.type(:git_config).new( + { + :key => 'user.email', + :value => 'john.doe@example.com', + } + )} + + let(:provider) { resource.provider } + +end \ No newline at end of file diff --git a/git/spec/unit/puppet/type/git_config/git_config_spec.rb b/git/spec/unit/puppet/type/git_config/git_config_spec.rb new file mode 100644 index 000000000..0fd26856d --- /dev/null +++ b/git/spec/unit/puppet/type/git_config/git_config_spec.rb @@ -0,0 +1,49 @@ +#!/usr/bin/env ruby + +require 'spec_helper' + +describe Puppet::Type.type(:git_config) do + + before do + @class = described_class + @provider_class = @class.provide(:fake) { mk_resource_methods } + @provider = @provider_class.new + @resource = stub 'resource', :resource => nil, :provider => @provider + + @class.stubs(:defaultprovider).returns @provider_class + @class.any_instance.stubs(:provider).returns @provider + end + + it "should have :name as its keyattribute" do + @class.key_attributes.should == [:name] + end + + describe "when validating attributes" do + + params = [ + :name, + :user, + :key, + :section, + :scope, + ] + + properties = [ + :value, + ] + + params.each do |param| + it "should have a #{param} parameter" do + @class.attrtype(param).should == :param + end + end + + properties.each do |property| + it "should have a #{property} property" do + @class.attrtype(property).should == :property + end + end + + end + +end \ No newline at end of file diff --git a/git/tests/gitosis.pp b/git/tests/gitosis.pp new file mode 100644 index 000000000..e6240ae21 --- /dev/null +++ b/git/tests/gitosis.pp @@ -0,0 +1 @@ +class { 'git::gitosis': } diff --git a/git/tests/init.pp b/git/tests/init.pp new file mode 100644 index 000000000..c23290471 --- /dev/null +++ b/git/tests/init.pp @@ -0,0 +1 @@ +class { 'git': }