poise-git 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.kitchen.yml +3 -0
  4. data/.travis.yml +54 -0
  5. data/.yardopts +7 -0
  6. data/CHANGELOG.md +5 -0
  7. data/Gemfile +36 -0
  8. data/LICENSE +201 -0
  9. data/README.md +151 -0
  10. data/Rakefile +17 -0
  11. data/chef/attributes/default.rb +26 -0
  12. data/chef/recipes/default.rb +22 -0
  13. data/lib/poise_git.rb +24 -0
  14. data/lib/poise_git/cheftie.rb +18 -0
  15. data/lib/poise_git/git_client_providers.rb +36 -0
  16. data/lib/poise_git/git_client_providers/base.rb +93 -0
  17. data/lib/poise_git/git_client_providers/dummy.rb +79 -0
  18. data/lib/poise_git/git_client_providers/system.rb +73 -0
  19. data/lib/poise_git/git_command_mixin.rb +37 -0
  20. data/lib/poise_git/resources.rb +27 -0
  21. data/lib/poise_git/resources/poise_git.rb +252 -0
  22. data/lib/poise_git/resources/poise_git_client.rb +82 -0
  23. data/lib/poise_git/safe_string.rb +25 -0
  24. data/lib/poise_git/version.rb +20 -0
  25. data/poise-git.gemspec +42 -0
  26. data/test/cookbook/metadata.rb +18 -0
  27. data/test/cookbook/recipes/default.rb +96 -0
  28. data/test/gemfiles/chef-12.1.gemfile +23 -0
  29. data/test/gemfiles/chef-12.10.gemfile +23 -0
  30. data/test/gemfiles/chef-12.11.gemfile +23 -0
  31. data/test/gemfiles/chef-12.12.gemfile +22 -0
  32. data/test/gemfiles/chef-12.13.gemfile +22 -0
  33. data/test/gemfiles/chef-12.14.gemfile +19 -0
  34. data/test/gemfiles/chef-12.15.gemfile +19 -0
  35. data/test/gemfiles/chef-12.16.gemfile +19 -0
  36. data/test/gemfiles/chef-12.17.gemfile +19 -0
  37. data/test/gemfiles/chef-12.18.gemfile +19 -0
  38. data/test/gemfiles/chef-12.19.gemfile +19 -0
  39. data/test/gemfiles/chef-12.2.gemfile +23 -0
  40. data/test/gemfiles/chef-12.3.gemfile +23 -0
  41. data/test/gemfiles/chef-12.4.gemfile +24 -0
  42. data/test/gemfiles/chef-12.5.gemfile +23 -0
  43. data/test/gemfiles/chef-12.6.gemfile +23 -0
  44. data/test/gemfiles/chef-12.7.gemfile +23 -0
  45. data/test/gemfiles/chef-12.8.gemfile +23 -0
  46. data/test/gemfiles/chef-12.9.gemfile +23 -0
  47. data/test/gemfiles/chef-12.gemfile +19 -0
  48. data/test/gemfiles/master.gemfile +25 -0
  49. data/test/integration/default/serverspec/default_spec.rb +49 -0
  50. data/test/spec/git_client_providers/dummy_spec.rb +76 -0
  51. data/test/spec/git_client_providers/system_spec.rb +64 -0
  52. data/test/spec/recipe_spec.rb +35 -0
  53. data/test/spec/resources/poise_git_client.rb +64 -0
  54. data/test/spec/resources/poise_git_spec.rb +153 -0
  55. data/test/spec/spec_helper.rb +19 -0
  56. metadata +208 -0
@@ -0,0 +1,25 @@
1
+ #
2
+ # Copyright 2015-2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', github: 'chef/chef'
20
+ gem 'halite', github: 'poise/halite'
21
+ gem 'ohai', github: 'chef/ohai'
22
+ gem 'poise', github: 'poise/poise'
23
+ gem 'poise-boiler', github: 'poise/poise-boiler'
24
+ gem 'poise-languages', github: 'poise/poise-languages'
25
+ gem 'poise-profiler', github: 'poise/poise-profiler'
@@ -0,0 +1,49 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'serverspec'
18
+ set :backend, :exec
19
+
20
+ describe file('/test1/README.md') do
21
+ it { is_expected.to be_a_file }
22
+ its(:content) { is_expected.to include('repo=test_repo') }
23
+ its(:content) { is_expected.to include('branch=master') }
24
+ end
25
+
26
+ describe file('/test2/README.md') do
27
+ it { is_expected.to be_a_file }
28
+ its(:content) { is_expected.to include('repo=test_repo') }
29
+ its(:content) { is_expected.to include('branch=release') }
30
+ end
31
+
32
+ describe file('/test3/README.md') do
33
+ it { is_expected.to be_a_file }
34
+ its(:content) { is_expected.to include('repo=private_test_repo') }
35
+ its(:content) { is_expected.to include('branch=master') }
36
+ end
37
+
38
+ describe file('/test4/README.md') do
39
+ it { is_expected.to be_a_file }
40
+ its(:content) { is_expected.to include('repo=private_test_repo') }
41
+ its(:content) { is_expected.to include('branch=release') }
42
+ end
43
+
44
+ describe file('/test5/README.md') do
45
+ it { is_expected.to be_a_file }
46
+ it { is_expected.to be_owned_by('poise') }
47
+ its(:content) { is_expected.to include('repo=private_test_repo') }
48
+ its(:content) { is_expected.to include('branch=master') }
49
+ end
@@ -0,0 +1,76 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe PoiseGit::GitClientProviders::Dummy do
20
+ let(:git_client_resource) { chef_run.poise_git_client('test') }
21
+ step_into(:poise_git_client)
22
+ recipe do
23
+ poise_git_client 'test' do
24
+ provider :dummy
25
+ end
26
+ end
27
+
28
+ describe '#git_binary' do
29
+ subject { git_client_resource.git_binary }
30
+
31
+ it { is_expected.to eq '/git' }
32
+
33
+ context 'with an option override' do
34
+ before do
35
+ override_attributes['poise-git'] ||= {}
36
+ override_attributes['poise-git']['test'] ||= {}
37
+ override_attributes['poise-git']['test']['git_binary'] = '/other'
38
+ end
39
+
40
+ it { is_expected.to eq '/other' }
41
+ end # /context with an option override
42
+ end # /describe #git_binary
43
+
44
+ describe '#git_environment' do
45
+ subject { git_client_resource.git_environment }
46
+
47
+ it { is_expected.to eq({}) }
48
+
49
+ context 'with an option override' do
50
+ before do
51
+ override_attributes['poise-git'] ||= {}
52
+ override_attributes['poise-git']['test'] ||= {}
53
+ override_attributes['poise-git']['test']['git_environment'] = {'FOO' => 'BAR'}
54
+ end
55
+
56
+ it { is_expected.to eq({'FOO' => 'BAR'}) }
57
+ end # /context with an option override
58
+ end # /describe #git_environment
59
+
60
+ describe 'action :install' do
61
+ # Just make sure it doesn't error.
62
+ it { run_chef }
63
+ end # /describe action :install
64
+
65
+ describe 'action :uninstall' do
66
+ recipe do
67
+ poise_git_client 'test' do
68
+ action :uninstall
69
+ provider :dummy
70
+ end
71
+ end
72
+
73
+ # Just make sure it doesn't error.
74
+ it { run_chef }
75
+ end # /describe action :uninstall
76
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe PoiseGit::GitClientProviders::System do
20
+ let(:git_client_resource) { chef_run.poise_git_client('git') }
21
+ step_into(:poise_git_client)
22
+ recipe do
23
+ poise_git_client 'git' do
24
+ provider :system
25
+ end
26
+ end
27
+
28
+ shared_examples_for 'system provider' do |pkg='git'|
29
+ it { expect(git_client_resource.provider_for_action(:install)).to be_a described_class }
30
+ it { is_expected.to install_poise_languages_system(pkg).with(dev_package: false) }
31
+ end
32
+
33
+ context 'on Ubuntu' do
34
+ let(:chefspec_options) { {platform: 'ubuntu', version: '16.04'} }
35
+ it_behaves_like 'system provider'
36
+ end # /context on Ubuntu
37
+
38
+ context 'on CentOS' do
39
+ let(:chefspec_options) { {platform: 'centos', version: '7.0'} }
40
+ it_behaves_like 'system provider'
41
+ end # /context on CentOS
42
+
43
+ context 'on OmniOS' do
44
+ let(:chefspec_options) { {platform: 'omnios', version: '151018'} }
45
+ it_behaves_like 'system provider', 'developer/versioning/git'
46
+ end # /context on OmniOS
47
+
48
+ context 'on SmartOS' do
49
+ let(:chefspec_options) { {platform: 'smartos', version: '5.11'} }
50
+ it_behaves_like 'system provider', 'scmgit'
51
+ end # /context on SmartOS
52
+
53
+ context 'action :uninstall' do
54
+ recipe do
55
+ poise_git_client 'git' do
56
+ action :uninstall
57
+ provider :system
58
+ end
59
+ end
60
+
61
+ it { expect(git_client_resource.provider_for_action(:uninstall)).to be_a described_class }
62
+ it { is_expected.to uninstall_poise_languages_system('git').with(dev_package: false) }
63
+ end # /context action :uninstall
64
+ end
@@ -0,0 +1,35 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe 'poise-git::default' do
20
+ recipe { include_recipe 'poise-git' }
21
+
22
+ context 'with defaults' do
23
+ it { is_expected.to install_poise_git_client('git').with(version: '') }
24
+ end # /context with defaults
25
+
26
+ context 'with attributes' do
27
+ before do
28
+ override_attributes['poise-git'] = {}
29
+ override_attributes['poise-git']['recipe'] = {}
30
+ override_attributes['poise-git']['recipe']['version'] = '1.2.3'
31
+ end
32
+
33
+ it { is_expected.to install_poise_git_client('git').with(version: '1.2.3') }
34
+ end # /context with attributes
35
+ end
@@ -0,0 +1,64 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe PoiseGit::Resources::PoiseGitClient do
20
+ before do
21
+ override_attributes['poise-git'] ||= {}
22
+ override_attributes['poise-git']['provider'] = 'dummy'
23
+ end
24
+
25
+ context 'with an empty name' do
26
+ recipe do
27
+ poise_git_client ''
28
+ end
29
+
30
+ it { is_expected.to install_poise_git_client('').with(version: '') }
31
+ end # /context with an empty name
32
+
33
+ context 'with name git' do
34
+ recipe do
35
+ poise_git_client 'git'
36
+ end
37
+
38
+ it { is_expected.to install_poise_git_client('git').with(version: '') }
39
+ end # /context with name git
40
+
41
+ context 'with name 1.2.3' do
42
+ recipe do
43
+ poise_git_client '1.2.3'
44
+ end
45
+
46
+ it { is_expected.to install_poise_git_client('1.2.3').with(version: '1.2.3') }
47
+ end # /context with name 1.2.3
48
+
49
+ context 'with name git-1.2.3' do
50
+ recipe do
51
+ poise_git_client 'git-1.2.3'
52
+ end
53
+
54
+ it { is_expected.to install_poise_git_client('git-1.2.3').with(version: '1.2.3') }
55
+ end # /context with name git-1.2.3
56
+
57
+ context 'with name git1.2.3' do
58
+ recipe do
59
+ poise_git_client 'git1.2.3'
60
+ end
61
+
62
+ it { is_expected.to install_poise_git_client('git1.2.3').with(version: '1.2.3') }
63
+ end # /context with name git1.2.3
64
+ end
@@ -0,0 +1,153 @@
1
+ #
2
+ # Copyright 2017, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe PoiseGit::Resources::PoiseGit do
20
+ step_into(:poise_git)
21
+ before do
22
+ override_attributes['poise-git'] ||= {}
23
+ override_attributes['poise-git']['provider'] = 'dummy'
24
+ end
25
+
26
+ before do
27
+ # Don't actually run the real thing
28
+ allow_any_instance_of(described_class::Provider).to receive(:action_sync).and_return(nil)
29
+ end
30
+
31
+ def cache_path(path)
32
+ "#{Chef::Config[:file_cache_path]}/#{path}"
33
+ end
34
+
35
+ context 'with defaults' do
36
+ recipe do
37
+ poise_git_client 'git'
38
+ poise_git '/test' do
39
+ repository 'https://example.com/test.git'
40
+ revision 'd44ec06d0b2a87732e91c005ed2048c824fd63ed'
41
+ end
42
+ end
43
+
44
+ it { is_expected.to_not render_file(cache_path('poise_git_deploy_2089348824')) }
45
+ it { is_expected.to_not render_file(cache_path('poise_git_wrapper_2089348824')) }
46
+ end # /context with defaults
47
+
48
+ context 'with in-line deploy key' do
49
+ recipe do
50
+ poise_git_client 'git'
51
+ poise_git '/test' do
52
+ repository 'https://example.com/test.git'
53
+ revision 'd44ec06d0b2a87732e91c005ed2048c824fd63ed'
54
+ deploy_key 'secretkey'
55
+ end
56
+ end
57
+
58
+ it { is_expected.to render_file(cache_path('poise_git_deploy_2089348824')).with_content('secretkey') }
59
+ it { is_expected.to render_file(cache_path('poise_git_wrapper_2089348824')).with_content(%Q{#!/bin/sh\n/usr/bin/env ssh -o "StrictHostKeyChecking=no" -i "#{cache_path('poise_git_deploy_2089348824')}" $@\n}) }
60
+ it { expect(chef_run.poise_git('/test').to_text).to include 'deploy_key "suppressed sensitive value"' }
61
+ end # /context with in-line deploy key
62
+
63
+ context 'with in-line deploy key with embedded newlines' do
64
+ # Reversion test for a weird bug that only triggers on SSH keys that have a
65
+ # line starting with /.
66
+ recipe do
67
+ poise_git_client 'git'
68
+ poise_git '/test' do
69
+ repository 'https://example.com/test.git'
70
+ revision 'd44ec06d0b2a87732e91c005ed2048c824fd63ed'
71
+ deploy_key "secretkey\n/foo"
72
+ end
73
+ end
74
+
75
+ it { is_expected.to render_file(cache_path('poise_git_deploy_2089348824')).with_content("secretkey\n/foo") }
76
+ it { is_expected.to render_file(cache_path('poise_git_wrapper_2089348824')).with_content(%Q{#!/bin/sh\n/usr/bin/env ssh -o "StrictHostKeyChecking=no" -i "#{cache_path('poise_git_deploy_2089348824')}" $@\n}) }
77
+ it { expect(chef_run.poise_git('/test').to_text).to include 'deploy_key "suppressed sensitive value"' }
78
+ end # /context with in-line deploy key with embedded newlines
79
+
80
+ context 'with path deploy key' do
81
+ recipe do
82
+ poise_git_client 'git'
83
+ poise_git '/test' do
84
+ repository 'https://example.com/test.git'
85
+ revision 'd44ec06d0b2a87732e91c005ed2048c824fd63ed'
86
+ deploy_key '/mykey'
87
+ end
88
+ end
89
+
90
+ it { is_expected.to_not render_file(cache_path('poise_git_deploy_2089348824')) }
91
+ it { is_expected.to render_file(cache_path('poise_git_wrapper_2089348824')).with_content(%Q{#!/bin/sh\n/usr/bin/env ssh -o "StrictHostKeyChecking=no" -i "/mykey" $@\n}) }
92
+ it { expect(chef_run.poise_git('/test').to_text).to include 'deploy_key "/mykey"' }
93
+ end # /context with path deploy key
94
+
95
+ context 'with path deploy key on Windows' do
96
+ recipe do
97
+ poise_git_client 'git'
98
+ poise_git '/test' do
99
+ repository 'https://example.com/test.git'
100
+ revision 'd44ec06d0b2a87732e91c005ed2048c824fd63ed'
101
+ deploy_key 'C:\\mykey'
102
+ end
103
+ end
104
+
105
+ it { is_expected.to_not render_file(cache_path('poise_git_deploy_2089348824')) }
106
+ it { is_expected.to render_file(cache_path('poise_git_wrapper_2089348824')).with_content(%Q{#!/bin/sh\n/usr/bin/env ssh -o "StrictHostKeyChecking=no" -i "C:\\mykey" $@\n}) }
107
+ it { expect(chef_run.poise_git('/test').to_text).to include 'deploy_key "C:\\\\mykey"' }
108
+ end # /context with path deploy key on Windows
109
+
110
+ context 'with strict SSH' do
111
+ recipe do
112
+ poise_git_client 'git'
113
+ poise_git '/test' do
114
+ repository 'https://example.com/test.git'
115
+ revision 'd44ec06d0b2a87732e91c005ed2048c824fd63ed'
116
+ deploy_key 'secretkey'
117
+ strict_ssh true
118
+ end
119
+ end
120
+
121
+ it { is_expected.to render_file(cache_path('poise_git_deploy_2089348824')).with_content('secretkey') }
122
+ it { is_expected.to render_file(cache_path('poise_git_wrapper_2089348824')).with_content(%Q{#!/bin/sh\n/usr/bin/env ssh -i "#{cache_path('poise_git_deploy_2089348824')}" $@\n}) }
123
+ it { expect(chef_run.poise_git('/test').to_text).to include 'deploy_key "suppressed sensitive value"' }
124
+ end # /context with strict SSH
125
+
126
+ context 'with no parent' do
127
+ recipe do
128
+ poise_git '/test' do
129
+ repository 'https://example.com/test.git'
130
+ revision 'd44ec06d0b2a87732e91c005ed2048c824fd63ed'
131
+ end
132
+ end
133
+
134
+ it { is_expected.to install_poise_git_client('git') }
135
+ end # /context with no parent
136
+
137
+ context 'without an explicit revision' do
138
+ # This test confirms the execution plumbing is working because
139
+ # load_current_resource will try to ls-remote.
140
+ recipe do
141
+ poise_git_client 'git'
142
+ poise_git '/test' do
143
+ repository 'https://example.com/test.git'
144
+ end
145
+ end
146
+
147
+ it do
148
+ fake_cmd = double(error!: nil, stdout: "d44ec06d0b2a87732e91c005ed2048c824fd63ed\tHEAD\n")
149
+ expect_any_instance_of(described_class::Provider).to receive(:poise_shell_out).with(%w{/git ls-remote https://example.com/test.git HEAD}, kind_of(Hash)).and_return(fake_cmd)
150
+ run_chef
151
+ end
152
+ end # /context without an explicit revision
153
+ end