From 8f5ae7a2794fa065f748285aa6ccfca0fccd5a52 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 13:04:56 +0100 Subject: [PATCH 01/17] Implemented better code coverage (#4). --- Gemfile | 7 +++++-- spec/defines/client_spec.rb | 6 ++++++ spec/defines/repo_spec.rb | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index f252a72..a727ed4 100644 --- a/Gemfile +++ b/Gemfile @@ -16,17 +16,20 @@ group :system_tests do gem 'beaker-rspec', require: false gem 'coveralls', require: false gem 'docker-api', require: false + gem 'google-api-client', '<= 0.9.4' + gem 'json_pure', '<= 2.0.1' gem 'metadata-json-lint', require: false gem 'pry', require: false gem 'puppet-blacksmith', require: false gem 'puppet-lint', require: false gem 'puppetlabs_spec_helper', require: false - gem 'rspec_junit_formatter', require: false + gem 'rspec_junit_formatter', '0.2.2' gem 'rspec-puppet', '<= 2.3.2' gem 'rspec-puppet-utils', require: false gem 'serverspec', require: false gem 'specinfra', '<= 2.59.0' gem 'spdx-licenses', '<= 1.0.0' + gem 'tins', '<= 1.6.0' end group :development do @@ -40,5 +43,5 @@ if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' gem 'rake', '~> 10.0' else # rubocop requires ruby >= 1.9 - gem 'rubocop' + gem 'rubocop', '<= 0.41.2' end diff --git a/spec/defines/client_spec.rb b/spec/defines/client_spec.rb index 8e0ec7c..bd7df1d 100644 --- a/spec/defines/client_spec.rb +++ b/spec/defines/client_spec.rb @@ -10,6 +10,12 @@ end it do + should contain_gitssh__client('nick@magpie.puppetlabs.lan').with( + ensure: 'present', + type: 'ssh-rsa', + key: 'AAAAB...aQ==' + ) + should contain_ssh_authorized_key( 'gitssh::client::nick@magpie.puppetlabs.lan' ).with('user' => 'git', diff --git a/spec/defines/repo_spec.rb b/spec/defines/repo_spec.rb index da62eda..d3a2c5b 100644 --- a/spec/defines/repo_spec.rb +++ b/spec/defines/repo_spec.rb @@ -16,6 +16,10 @@ end it do + should contain_gitssh__repo('foobar').with( + ensure: 'present' + ) + should contain_exec('/usr/bin/mkdir /var/git/foobar.git') .with('user' => 'git') From 90fcaf8bde002e905a88345af28b3ad92d54296b Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 13:09:06 +0100 Subject: [PATCH 02/17] Sorted out Rubocop version. Fixes #4. --- Gemfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index a727ed4..0959600 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,7 @@ group :system_tests do gem 'rspec_junit_formatter', '0.2.2' gem 'rspec-puppet', '<= 2.3.2' gem 'rspec-puppet-utils', require: false + gem 'rubocop', '<= 0.41.2' gem 'serverspec', require: false gem 'specinfra', '<= 2.59.0' gem 'spdx-licenses', '<= 1.0.0' @@ -41,7 +42,4 @@ end if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9' gem 'rspec', '~> 2.0' gem 'rake', '~> 10.0' -else - # rubocop requires ruby >= 1.9 - gem 'rubocop', '<= 0.41.2' end From db377abbf404103b3d8315132eb402c689fd0b05 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 13:22:06 +0100 Subject: [PATCH 03/17] Setup test environment for #3. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index f28dc59..ff4899b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,8 @@ sudo: false matrix: fast_finish: true include: + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="3.4.3" - rvm: 1.9.3 env: PUPPET_GEM_VERSION="~> 3.0" - rvm: 2.1.5 From 9194c815dc476d618a9e3c529b477d002420e735 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 14:03:02 +0100 Subject: [PATCH 04/17] Consolidated checks and made changes for #4. --- spec/classes/init_spec.rb | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index d294cd1..ddd6608 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -13,18 +13,9 @@ 'package_ensure' => 'present', 'package_name' => 'git', 'purge_ssh_keys' => 'true') - end - it do should contain_package('git').with('ensure' => 'present') - end - - it do - should contain_user('git').with('home' => '/var/git', - 'purge_ssh_keys' => true) - end - - it do + should contain_user('git').with('home' => '/var/git') should contain_exec('/bin/echo /usr/bin/git-shell >> /etc/shells') end end From 67341c847d1e734912af9ab37dd20633cf62b0a1 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 14:03:53 +0100 Subject: [PATCH 05/17] Only set purge_ssh_keys on Puppet 3.6.0. Fixes #3. --- manifests/init.pp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 4550456..0e6e17c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -17,13 +17,21 @@ before => User['git'] } + if versioncmp($::puppetversion,'3.6.0') >= 0 { + User { + purge_ssh_keys => $purge_ssh_keys, + } + } elsif $purge_ssh_keys { + warning('gitssh::purge_ssh_keys is ignored in Puppet < 3.6.0.') + warning('To disable this warning, set gitssh::purge_ssh_keys to false.') + } + user { 'git': - ensure => present, - home => $basedir, - shell => '/usr/bin/git-shell', - managehome => true, - purge_ssh_keys => $purge_ssh_keys, - require => Package[$package_name], + ensure => present, + home => $basedir, + shell => '/usr/bin/git-shell', + managehome => true, + require => Package[$package_name], } if size($clients) > 0 { From 0d6725da03b7da55379834f7dfb4e22b39712ea4 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 14:57:09 +0100 Subject: [PATCH 06/17] Add beaker tests to CircleCI. --- circle.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/circle.yml b/circle.yml index 0fe8499..f1acc13 100644 --- a/circle.yml +++ b/circle.yml @@ -27,3 +27,4 @@ test: - bundle exec rake lint - bundle exec rake validate - bundle exec rake spec SPEC_OPTS="--format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/puppet.xml" + - bundle exec rake beaker From 4a6916c47761d5f09f77cf16723e583ed04d2bb2 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 19:11:29 +0100 Subject: [PATCH 07/17] Ensure the puppet version is passed to versioncmp (#3). --- spec/classes/init_spec.rb | 22 ++++++++++++++++------ spec/defines/client_spec.rb | 8 ++++++++ spec/defines/repo_spec.rb | 8 ++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index ddd6608..b1d8500 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -7,13 +7,23 @@ end end - context 'with defaults for all parameters' do - it do - should contain_class('gitssh').with('basedir' => '/var/git', - 'package_ensure' => 'present', - 'package_name' => 'git', - 'purge_ssh_keys' => 'true') + puppetversion = Gem.loaded_specs['puppet'].version + + context "With defaults for all parameters (puppet-#{puppetversion})" do + let :facts do + { + puppetversion: puppetversion.to_s + } + end + it do + should contain_class('gitssh') + .with( + basedir: '/var/git', + package_ensure: 'present', + package_name: 'git', + purge_ssh_keys: 'true' + ) should contain_package('git').with('ensure' => 'present') should contain_user('git').with('home' => '/var/git') should contain_exec('/bin/echo /usr/bin/git-shell >> /etc/shells') diff --git a/spec/defines/client_spec.rb b/spec/defines/client_spec.rb index bd7df1d..1b9feed 100644 --- a/spec/defines/client_spec.rb +++ b/spec/defines/client_spec.rb @@ -3,6 +3,14 @@ context 'Manage authorised SSH key' do let(:title) { 'nick@magpie.puppetlabs.lan' } + puppetversion = Gem.loaded_specs['puppet'].version + + let :facts do + { + puppetversion: puppetversion.to_s + } + end + let :params do { key: 'AAAAB...aQ==' diff --git a/spec/defines/repo_spec.rb b/spec/defines/repo_spec.rb index d3a2c5b..a51cfc3 100644 --- a/spec/defines/repo_spec.rb +++ b/spec/defines/repo_spec.rb @@ -6,12 +6,15 @@ end end + puppetversion = Gem.loaded_specs['puppet'].version + context 'Add a repo (Red Hat)' do let(:title) { 'foobar' } let :facts do { - osfamily: 'RedHat' + osfamily: 'RedHat', + puppetversion: puppetversion.to_s } end @@ -36,7 +39,8 @@ let :facts do { - osfamily: 'Debian' + osfamily: 'Debian', + puppetversion: puppetversion.to_s } end From 31d2cda7da592c3131716d058392b651bbe1ee49 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 19:13:22 +0100 Subject: [PATCH 08/17] Beaker giggery-pokery. --- circle.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/circle.yml b/circle.yml index f1acc13..542cf54 100644 --- a/circle.yml +++ b/circle.yml @@ -10,6 +10,7 @@ dependencies: environment: PUPPET_GEM_VERSION: '~> 4.0' STRICT_VARIABLES: yes + BEAKER_destroy: no post: - rvm cleanup all machine: From 44b14c29d67d2fd46a997b58ed97299d622905cc Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 19:21:54 +0100 Subject: [PATCH 09/17] Ensure that it is more obvious that we check idempotency. --- spec/acceptance/gitssh_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/acceptance/gitssh_spec.rb b/spec/acceptance/gitssh_spec.rb index 788cbde..880b6b0 100644 --- a/spec/acceptance/gitssh_spec.rb +++ b/spec/acceptance/gitssh_spec.rb @@ -27,6 +27,9 @@ describe 'Git SSH installation.' do it 'should work with no errors' do apply_manifest(pre_req_install_pp, catch_failures: true) + end + + it 'check code is idempotent' do expect(apply_manifest(pre_req_install_pp, catch_failures: true).exit_code).to be_zero end From 291e7458f9c5a18c069f4c4f82195603924fde0f Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 19:22:33 +0100 Subject: [PATCH 10/17] Correct location for environment variable. --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 542cf54..a519337 100644 --- a/circle.yml +++ b/circle.yml @@ -10,13 +10,13 @@ dependencies: environment: PUPPET_GEM_VERSION: '~> 4.0' STRICT_VARIABLES: yes - BEAKER_destroy: no post: - rvm cleanup all machine: environment: PUPPET_GEM_VERSION: '~> 4.0' STRICT_VARIABLES: yes + BEAKER_destroy: no ruby: version: 2.1.6 services: From efab25e53588dbcf0fd64df9331e6145e9d88f78 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 19:53:03 +0100 Subject: [PATCH 11/17] Added a change log. --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..711f915 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,16 @@ +# Change Log for Puppet Module locp-gitssh + +##2016-09-21 - Release 0.1.2 ([diff](https://github.com/locp/gitssh/compare/0.1.1...0.1.2)) + +* Fixed a fatal error when running a Puppet version < 3.6.0. +* Improved unit and acceptance testing. +* Improved the documentation. + +##2016-09-18 - Release 0.1.1 ([diff](https://github.com/locp/gitssh/compare/0.1.0...0.1.1)) + +* Ensure the service runs on Red Hat and Debian families. +* Improved the project metadata. + +##2016-09-11 - Release 0.1.0 + +An initial release. From dd35a1b739663482d2920e256841af3ce9a96303 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 19:53:31 +0100 Subject: [PATCH 12/17] Corrected test comment (#5). --- spec/defines/repo_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/defines/repo_spec.rb b/spec/defines/repo_spec.rb index da62eda..0e04ec5 100644 --- a/spec/defines/repo_spec.rb +++ b/spec/defines/repo_spec.rb @@ -27,7 +27,7 @@ end end - context 'Add a repo (Red Hat)' do + context 'Add a repo (Debian)' do let(:title) { 'foobar' } let :facts do From 5396bd27385e872dbcb895b9644634803b88fe20 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 20:23:21 +0100 Subject: [PATCH 13/17] Added Debian 7 (#5). --- metadata.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/metadata.json b/metadata.json index d140a28..4225af8 100644 --- a/metadata.json +++ b/metadata.json @@ -20,6 +20,12 @@ "7" ] }, + { + "operatingsystem": "Debian", + "operatingsystemrelease": [ + "7" + ] + }, { "operatingsystem": "Ubuntu", "operatingsystemrelease": [ From f523598cb42a8b6a1765808b71d342b1781647da Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 20:24:27 +0100 Subject: [PATCH 14/17] Completed the attributes for gitssh. Expanded on limitations (#5). --- README.md | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 413f136..eee57e3 100644 --- a/README.md +++ b/README.md @@ -110,26 +110,50 @@ gitssh::repos: ## Reference -### Class gitssh +### Parameters -#### Parameters +* Defined type gitssh::client +* Class gitssh +* Defined type gitssh::repo + +#### Defined type gitssh::client + +#### Class gitssh ##### `basedir` This is set as the home directory for the git user. Default value: '/var/git' ##### `clients` -An array of hashes that can be passed to the gitssh::client definition. +An array of hashes that can be passed to the `gitssh::client` definition. Default value: [] ##### `package_ensure` -Passed as the **ensure** parameter package for the **git** package. Valid +Passed as the **ensure** attribute to the package resource. Valid values are **present** or a specific version number. -Default value: present +Default value: **present** + +##### `package_name` +Passed as the **name** attribute for the package resource for the git +package. +Default value: 'git' + +##### `purge_ssh_keys` +Passed as an attribute for the user resource for git. This will remove all +SSH keys from the git user that are not controlled by Puppet. This +attribute has no effect on version of Puppet < 3.6.0 and will generate a +warning unless set to **false**. +Default value: **true** + +##### `repos` +An array of hashes that can be passed to the `gitssh::repo` definition. +Default value: [] + +#### Defined type gitssh::repo ## Limitations -Currently only developed and tested on CentOS and Debian 7. +Currently only developed and tested on CentOS 7, Ubuntu 14.04 and Debian 7. ## Development From 071fd2e22b7c3ea7682658bfed97267cf09e06ce Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 20:28:01 +0100 Subject: [PATCH 15/17] Added reference links (#5). --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index eee57e3..9730001 100644 --- a/README.md +++ b/README.md @@ -110,11 +110,11 @@ gitssh::repos: ## Reference -### Parameters +* [Defined type gitssh::client](#defined-type-gitsshclient) +* [Class gitssh](#class-gitssh) +* [Defined type gitssh::repo](#defined-type-gitsshrepo) -* Defined type gitssh::client -* Class gitssh -* Defined type gitssh::repo +### Parameters #### Defined type gitssh::client From 101e3ae4804354c286592b77474e884ab49ce3a8 Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 20:38:09 +0100 Subject: [PATCH 16/17] Added acknowlegement to @nl0pvm for #3 as part of #5. --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 9730001..3bc2f66 100644 --- a/README.md +++ b/README.md @@ -161,3 +161,9 @@ Contributions will be gratefully accepted. Please go to the project page, fork the project, make your changes locally and then raise a pull request. Details on how to do this are available at https://guides.github.com/activities/contributing-to-open-source. + +### Contributers + +| Release | Issue/PR | Contributer | +| :------------- | :-------------------------------------------------------------------------------------------------------------------------- | :------------------------------------| +| 0.1.2 | [The module does not work on Puppet 3.4.3The module does not work on Puppet 3.4.3](https://github.com/locp/gitssh/issues/3) | [@nl0pvm](https://github.com/nl0pvm) | From ef0439e09c764657db46eef0fb62311a7f4a254d Mon Sep 17 00:00:00 2001 From: Ben Dalling Date: Wed, 21 Sep 2016 20:47:56 +0100 Subject: [PATCH 17/17] Added documentation for gitssh::client and gitssh::repo (#5). --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 3bc2f66..6c0d4b2 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,22 @@ gitssh::repos: #### Defined type gitssh::client +##### `ensure` +If the SSH key is to be present in the git account. Valid values are +*present* and *absent*. +Default value: **present** + +##### `type` +The type of SSH key. See +[here](https://docs.puppet.com/puppet/latest/reference/types/ssh_authorized_key.html#ssh_authorized_key-attribute-type) +for a list of valid values. +Default value: 'ssh-rsa' + +##### `key` +This value can be left as *undef* (the default) if `ensure` is set to +*absent*. Otherwise it should be the SSH key. +Default value: *undef* + #### Class gitssh ##### `basedir` @@ -151,6 +167,10 @@ Default value: [] #### Defined type gitssh::repo +##### `ensure` +If the repository is to be *present* or *absent*. +Default value: **present** + ## Limitations Currently only developed and tested on CentOS 7, Ubuntu 14.04 and Debian 7.