knife-spork 1.7.2 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +35 -35
  3. data/lib/chef/knife/spork-bump.rb +100 -100
  4. data/lib/chef/knife/spork-check.rb +165 -161
  5. data/lib/chef/knife/spork-databag-create.rb +54 -54
  6. data/lib/chef/knife/spork-databag-delete.rb +51 -51
  7. data/lib/chef/knife/spork-databag-edit.rb +54 -54
  8. data/lib/chef/knife/spork-databag-fromfile.rb +88 -88
  9. data/lib/chef/knife/spork-delete.rb +132 -132
  10. data/lib/chef/knife/spork-environment-check.rb +90 -90
  11. data/lib/chef/knife/spork-environment-create.rb +63 -63
  12. data/lib/chef/knife/spork-environment-delete.rb +38 -38
  13. data/lib/chef/knife/spork-environment-edit.rb +40 -40
  14. data/lib/chef/knife/spork-environment-fromfile.rb +46 -46
  15. data/lib/chef/knife/spork-info.rb +34 -34
  16. data/lib/chef/knife/spork-node-create.rb +41 -41
  17. data/lib/chef/knife/spork-node-delete.rb +41 -41
  18. data/lib/chef/knife/spork-node-edit.rb +48 -48
  19. data/lib/chef/knife/spork-node-fromfile.rb +46 -46
  20. data/lib/chef/knife/spork-node-runlistadd.rb +51 -51
  21. data/lib/chef/knife/spork-node-runlistremove.rb +44 -44
  22. data/lib/chef/knife/spork-node-runlistset.rb +44 -44
  23. data/lib/chef/knife/spork-omni.rb +112 -112
  24. data/lib/chef/knife/spork-promote.rb +197 -197
  25. data/lib/chef/knife/spork-role-create.rb +46 -46
  26. data/lib/chef/knife/spork-role-delete.rb +50 -50
  27. data/lib/chef/knife/spork-role-edit.rb +40 -40
  28. data/lib/chef/knife/spork-role-fromfile.rb +65 -65
  29. data/lib/chef/knife/spork-upload.rb +151 -151
  30. data/lib/chef/knife/spork-version.rb +12 -12
  31. data/lib/knife-spork.rb +3 -3
  32. data/lib/knife-spork/plugins.rb +27 -27
  33. data/lib/knife-spork/plugins/campfire.rb +219 -219
  34. data/lib/knife-spork/plugins/eventinator.rb +329 -329
  35. data/lib/knife-spork/plugins/foodcritic.rb +46 -46
  36. data/lib/knife-spork/plugins/git.rb +393 -399
  37. data/lib/knife-spork/plugins/graphite.rb +25 -25
  38. data/lib/knife-spork/plugins/grove.rb +167 -167
  39. data/lib/knife-spork/plugins/hipchat.rb +171 -171
  40. data/lib/knife-spork/plugins/influxdb.rb +28 -28
  41. data/lib/knife-spork/plugins/irccat.rb +332 -332
  42. data/lib/knife-spork/plugins/jabber.rb +133 -133
  43. data/lib/knife-spork/plugins/plugin.rb +117 -117
  44. data/lib/knife-spork/plugins/rubocop.rb +56 -56
  45. data/lib/knife-spork/plugins/slack.rb +125 -125
  46. data/lib/knife-spork/plugins/statusnet.rb +122 -122
  47. data/lib/knife-spork/runner.rb +342 -342
  48. data/lib/knife-spork/version.rb +5 -5
  49. metadata +4 -51
  50. data/.gitignore +0 -21
  51. data/.ruby-gemset +0 -1
  52. data/.ruby-version +0 -1
  53. data/.travis.yml +0 -3
  54. data/CHANGELOG.md +0 -445
  55. data/Gemfile +0 -3
  56. data/README.md +0 -544
  57. data/Rakefile +0 -35
  58. data/knife-spork.gemspec +0 -28
  59. data/plugins/Campfire.md +0 -43
  60. data/plugins/Eventinator.md +0 -30
  61. data/plugins/Foodcritic.md +0 -53
  62. data/plugins/Git.md +0 -53
  63. data/plugins/Graphite.md +0 -30
  64. data/plugins/Grove.md +0 -31
  65. data/plugins/HipChat.md +0 -69
  66. data/plugins/Influxdb.md +0 -25
  67. data/plugins/Irccat.md +0 -50
  68. data/plugins/Jabber.md +0 -61
  69. data/plugins/README.md +0 -70
  70. data/plugins/Rubocop.md +0 -110
  71. data/plugins/Slack.md +0 -48
  72. data/plugins/StatusNet.md +0 -41
  73. data/plugins/Template.md +0 -34
  74. data/spec/spec_helper.rb +0 -10
  75. data/spec/test_helpers.rb +0 -46
  76. data/spec/unit/fixtures/config/spork-config.yml +0 -1
  77. data/spec/unit/fixtures/cookbooks/example/metadata.rb +0 -8
  78. data/spec/unit/fixtures/environments/example.json +0 -12
  79. data/spec/unit/fixtures/knife.rb +0 -6
  80. data/spec/unit/fixtures/test_client.pem +0 -27
  81. data/spec/unit/spork_bump_spec.rb +0 -75
  82. data/spec/unit/spork_info_spec.rb +0 -40
  83. data/spec/unit/spork_promote_spec.rb +0 -77
  84. data/spec/unit/spork_upload_spec.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8d36ad90f20dbe5a5b2a473862a010b842ccbc8038d8437094b10f4c2107b09
4
- data.tar.gz: 34ad1ffb10bbc77b02b9a3cd20235baf73d3a09d5e97244ac547a036da2d279c
3
+ metadata.gz: 4ae83cf6601495d0432b1bf24073d2e2ae0579b1e2d7d0da06a4d14c21846a54
4
+ data.tar.gz: 0cef1ae4aa4f1f8a9595ea173da77b1d5214a639c06e25e2fd3ea81128694091
5
5
  SHA512:
6
- metadata.gz: 50630ebcc3d3183b04430cdfde3e01d30e76de268080b1dd62ff4cbd372569a91b71f59ae7a18cf3d7ae279e59dd4a569e893d0fd0c08f4dea865dcbfc863f33
7
- data.tar.gz: 8520fc4d6359f811446fbc3d6112ef0ff26e9526c87651b7f1e6ac50afbdc6651c3252114d134822850c5673326fc56d05667c6e61590ebb4590a86f60b27adc
6
+ metadata.gz: 64f7a05346b2eb0ea29339d0c086ac452caa793f34db3d8f5b605aa8c900130d2d6d9d65cf621c65844d50eea1be74116fe4ed842df9027f3050c31e26687ef7
7
+ data.tar.gz: 52d66912a6d511443067a555dfd7411acf321749a304f4afbdb67ccec28b5ace54878a17e0ad82851c57cdea264f43b350e4de691c64748ecc69aa0c8da85242
data/LICENSE CHANGED
@@ -1,35 +1,35 @@
1
- KnifeSpork
2
- ----------
3
- Author:: Jon Cowie (<jonlives@gmail.com>)
4
- Copyright:: Copyright (c) 2011 Jon Cowie
5
- License:: GPL
6
-
7
- Plugin API
8
- ----------
9
- Author:: Seth Vargo (<svargo@customink.com>)
10
- Copyright:: Copyright (c) 2012 Seth Vargo
11
- License:: GPL
12
-
13
- Other
14
- -----
15
- spork bump is based on the knife-cookbook-bump plugin by:
16
- Alalanta (no license specified)
17
-
18
- With snippets from:
19
- Author:: Adam Jacob (<adam@opscode.com>)
20
- Author:: Christopher Walters (<cw@opscode.com>)
21
- Author:: Nuo Yan (<yan.nuo@gmail.com>)
22
- Copyright:: Copyright (c) 2009, 2010 Opscode, Inc.
23
- License:: Apache License, Version 2.0
24
-
25
- Licensed under the Apache License, Version 2.0 (the "License");
26
- you may not use this file except in compliance with the License.
27
- You may obtain a copy of the License at
28
-
29
- http://www.apache.org/licenses/LICENSE-2.0
30
-
31
- Unless required by applicable law or agreed to in writing, software
32
- distributed under the License is distributed on an "AS IS" BASIS,
33
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34
- See the License for the specific language governing permissions and
35
- limitations under the License.
1
+ KnifeSpork
2
+ ----------
3
+ Author:: Jon Cowie (<jonlives@gmail.com>)
4
+ Copyright:: Copyright (c) 2011 Jon Cowie
5
+ License:: GPL
6
+
7
+ Plugin API
8
+ ----------
9
+ Author:: Seth Vargo (<svargo@customink.com>)
10
+ Copyright:: Copyright (c) 2012 Seth Vargo
11
+ License:: GPL
12
+
13
+ Other
14
+ -----
15
+ spork bump is based on the knife-cookbook-bump plugin by:
16
+ Alalanta (no license specified)
17
+
18
+ With snippets from:
19
+ Author:: Adam Jacob (<adam@opscode.com>)
20
+ Author:: Christopher Walters (<cw@opscode.com>)
21
+ Author:: Nuo Yan (<yan.nuo@gmail.com>)
22
+ Copyright:: Copyright (c) 2009, 2010 Opscode, Inc.
23
+ License:: Apache License, Version 2.0
24
+
25
+ Licensed under the Apache License, Version 2.0 (the "License");
26
+ you may not use this file except in compliance with the License.
27
+ You may obtain a copy of the License at
28
+
29
+ http://www.apache.org/licenses/LICENSE-2.0
30
+
31
+ Unless required by applicable law or agreed to in writing, software
32
+ distributed under the License is distributed on an "AS IS" BASIS,
33
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34
+ See the License for the specific language governing permissions and
35
+ limitations under the License.
@@ -1,100 +1,100 @@
1
- require 'chef/knife'
2
-
3
- module KnifeSpork
4
- class SporkBump < Chef::Knife
5
-
6
- deps do
7
- require 'knife-spork/runner'
8
- end
9
-
10
- TYPE_INDEX = { :major => 0, :minor => 1, :patch => 2, :manual => 3 }.freeze
11
-
12
- option :cookbook_path,
13
- :short => '-o PATH:PATH',
14
- :long => '--cookbook-path PATH:PATH',
15
- :description => 'A colon-separated path to look for cookbooks in',
16
- :proc => lambda { |o| o.split(':') }
17
-
18
- option :berksfile,
19
- :short => '-b',
20
- :long => 'berksfile',
21
- :description => 'Path to a Berksfile to operate off of',
22
- :default => nil,
23
- :proc => lambda { |o| o || File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME) }
24
-
25
- option :skip_dependencies,
26
- :short => '-s',
27
- :long => '--skip-dependencies',
28
- :description => 'Berksfile skips resolving source cookbook dependencies',
29
- :default => true
30
-
31
- banner 'knife spork bump COOKBOOK [major|minor|patch|manual]'
32
-
33
- def run
34
- self.class.send(:include, KnifeSpork::Runner)
35
- self.config = Chef::Config.merge!(config)
36
- config[:cookbook_path] ||= Chef::Config[:cookbook_path]
37
-
38
- cookbook_name = ""
39
-
40
- if @name_args.empty? && File.exists?("#{Dir.pwd}/metadata.rb")
41
- cookbook_name = File.read("#{Dir.pwd}/metadata.rb").split("\n").select{|l|l.start_with?("name")}.first.split.last.gsub("\"","").gsub("'","")
42
- ui.info "Cookbook name omitted, but metadata.rb for cookbook #{cookbook_name} found - bumping that."
43
- elsif @name_args.empty?
44
- show_usage
45
- ui.error("You must specify at least a cookbook name")
46
- exit 1
47
- else
48
- cookbook_name = name_args.first
49
- end
50
-
51
- # Temporary fix for #138 to allow Berkshelf functionality
52
- # to be bypassed until #85 has been completed and Berkshelf 3 support added
53
- unload_berkshelf_if_specified
54
-
55
- #First load so plugins etc know what to work with
56
- @cookbook = load_cookbook(cookbook_name)
57
-
58
- run_plugins(:before_bump)
59
-
60
- #Reload cookbook in case a VCS plugin found updates
61
- @cookbook = load_cookbook(cookbook_name)
62
- bump
63
- run_plugins(:after_bump)
64
- end
65
-
66
- private
67
-
68
- def bump
69
- old_version = @cookbook.version
70
-
71
- if bump_type == 3
72
- # manual bump
73
- version_array = manual_bump_version.split('.')
74
- else
75
- # major, minor, or patch bump
76
- version_array = old_version.split('.').collect{ |i| i.to_i }
77
- version_array[bump_type] += 1
78
- ((bump_type+1)..2).each{ |i| version_array[i] = 0 } # reset all lower version numbers to 0
79
- end
80
-
81
- new_version = version_array.join('.')
82
-
83
- metadata_file = "#{@cookbook.root_dir}/metadata.rb"
84
- new_contents = File.read(metadata_file).gsub(/(version\s+['"])[0-9\.]+(['"])/, "\\1#{new_version}\\2")
85
- File.open(metadata_file, 'w'){ |f| f.write(new_contents) }
86
-
87
- ui.info "Successfully bumped #{@cookbook.name} to v#{new_version}!"
88
- end
89
-
90
- def bump_type
91
- TYPE_INDEX[(name_args[1] || 'patch').to_sym]
92
- end
93
-
94
- def manual_bump_version
95
- version = name_args.last
96
- validate_version!(version)
97
- version
98
- end
99
- end
100
- end
1
+ require 'chef/knife'
2
+
3
+ module KnifeSpork
4
+ class SporkBump < Chef::Knife
5
+
6
+ deps do
7
+ require 'knife-spork/runner'
8
+ end
9
+
10
+ TYPE_INDEX = { :major => 0, :minor => 1, :patch => 2, :manual => 3 }.freeze
11
+
12
+ option :cookbook_path,
13
+ :short => '-o PATH:PATH',
14
+ :long => '--cookbook-path PATH:PATH',
15
+ :description => 'A colon-separated path to look for cookbooks in',
16
+ :proc => lambda { |o| o.split(':') }
17
+
18
+ option :berksfile,
19
+ :short => '-b',
20
+ :long => 'berksfile',
21
+ :description => 'Path to a Berksfile to operate off of',
22
+ :default => nil,
23
+ :proc => lambda { |o| o || File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME) }
24
+
25
+ option :skip_dependencies,
26
+ :short => '-s',
27
+ :long => '--skip-dependencies',
28
+ :description => 'Berksfile skips resolving source cookbook dependencies',
29
+ :default => true
30
+
31
+ banner 'knife spork bump COOKBOOK [major|minor|patch|manual]'
32
+
33
+ def run
34
+ self.class.send(:include, KnifeSpork::Runner)
35
+ self.config = Chef::Config.merge!(config)
36
+ config[:cookbook_path] ||= Chef::Config[:cookbook_path]
37
+
38
+ cookbook_name = ""
39
+
40
+ if @name_args.empty? && File.exists?("#{Dir.pwd}/metadata.rb")
41
+ cookbook_name = File.read("#{Dir.pwd}/metadata.rb").split("\n").select{|l|l.start_with?("name")}.first.split.last.gsub("\"","").gsub("'","")
42
+ ui.info "Cookbook name omitted, but metadata.rb for cookbook #{cookbook_name} found - bumping that."
43
+ elsif @name_args.empty?
44
+ show_usage
45
+ ui.error("You must specify at least a cookbook name")
46
+ exit 1
47
+ else
48
+ cookbook_name = name_args.first
49
+ end
50
+
51
+ # Temporary fix for #138 to allow Berkshelf functionality
52
+ # to be bypassed until #85 has been completed and Berkshelf 3 support added
53
+ unload_berkshelf_if_specified
54
+
55
+ #First load so plugins etc know what to work with
56
+ @cookbook = load_cookbook(cookbook_name)
57
+
58
+ run_plugins(:before_bump)
59
+
60
+ #Reload cookbook in case a VCS plugin found updates
61
+ @cookbook = load_cookbook(cookbook_name)
62
+ bump
63
+ run_plugins(:after_bump)
64
+ end
65
+
66
+ private
67
+
68
+ def bump
69
+ old_version = @cookbook.version
70
+
71
+ if bump_type == 3
72
+ # manual bump
73
+ version_array = manual_bump_version.split('.')
74
+ else
75
+ # major, minor, or patch bump
76
+ version_array = old_version.split('.').collect{ |i| i.to_i }
77
+ version_array[bump_type] += 1
78
+ ((bump_type+1)..2).each{ |i| version_array[i] = 0 } # reset all lower version numbers to 0
79
+ end
80
+
81
+ new_version = version_array.join('.')
82
+
83
+ metadata_file = "#{@cookbook.root_dir}/metadata.rb"
84
+ new_contents = File.read(metadata_file).gsub(/(version\s+['"])[0-9\.]+(['"])/, "\\1#{new_version}\\2")
85
+ File.open(metadata_file, 'w'){ |f| f.write(new_contents) }
86
+
87
+ ui.info "Successfully bumped #{@cookbook.name} to v#{new_version}!"
88
+ end
89
+
90
+ def bump_type
91
+ TYPE_INDEX[(name_args[1] || 'patch').to_sym]
92
+ end
93
+
94
+ def manual_bump_version
95
+ version = name_args.last
96
+ validate_version!(version)
97
+ version
98
+ end
99
+ end
100
+ end
@@ -1,161 +1,165 @@
1
- require 'chef/knife'
2
-
3
- module KnifeSpork
4
- class SporkCheck < Chef::Knife
5
-
6
- deps do
7
- require 'knife-spork/runner'
8
- end
9
-
10
- banner 'knife spork check COOKBOOK (options)'
11
-
12
- option :all,
13
- :short => '--a',
14
- :long => '--all',
15
- :description => 'Show all uploaded versions of the cookbook'
16
-
17
- option :fail,
18
- :long => "--fail",
19
- :description => "If the check fails exit with non-zero exit code"
20
-
21
- option :cookbook_path,
22
- :short => '-o PATH:PATH',
23
- :long => '--cookbook-path PATH:PATH',
24
- :description => 'A colon-separated path to look for cookbooks in',
25
- :proc => lambda { |o| o.split(':') }
26
-
27
- option :berksfile,
28
- :short => '-b',
29
- :long => 'berksfile',
30
- :description => 'Path to a Berksfile to operate off of',
31
- :default => nil,
32
- :proc => lambda { |o| o || File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME) }
33
-
34
- option :skip_dependencies,
35
- :short => '-s',
36
- :long => '--skip-dependencies',
37
- :description => 'Berksfile skips resolving source cookbook dependencies',
38
- :default => true
39
-
40
- def run
41
- self.class.send(:include, KnifeSpork::Runner)
42
- self.config = Chef::Config.merge!(config)
43
-
44
- if name_args.empty?
45
- ui.fatal 'You must specify a cookbook name!'
46
- show_usage
47
- exit(1)
48
- end
49
-
50
- # Temporary fix for #138 to allow Berkshelf functionality
51
- # to be bypassed until #85 has been completed and Berkshelf 3 support added
52
- unload_berkshelf_if_specified
53
-
54
- #First load so plugins etc know what to work with
55
- initial_load
56
-
57
- run_plugins(:before_check)
58
-
59
- #Reload cookbook in case a VCS plugin found updates
60
- initial_load
61
-
62
- check
63
- run_plugins(:after_check)
64
- end
65
-
66
- private
67
- def check
68
- ui.msg "Checking versions for cookbook #{@cookbook.name}..."
69
- ui.msg ""
70
- ui.msg "Local Version:"
71
- ui.msg " #{local_version}"
72
- ui.msg ""
73
- ui.msg "Remote Versions: (* indicates frozen)"
74
- remote_versions.each do |remote_version|
75
- if frozen?(remote_version)
76
- ui.msg " *#{remote_version}"
77
- else
78
- ui.msg " #{remote_version}"
79
- end
80
- end
81
- ui.msg ""
82
-
83
- remote_versions.each do |remote_version|
84
- if remote_version == local_version
85
- if frozen?(remote_version)
86
- message = "Your local version (#{local_version}) is frozen on the remote server. You'll need to bump before you can upload."
87
- message_autobump = "Your local version (#{local_version}) is frozen on the remote server. Autobumping so you can upload."
88
- if config[:fail]
89
- fail_and_exit("#{message}")
90
- else
91
- answer = nil
92
- unless config[:yes]
93
- ui.warn("#{message}")
94
- answer = ui.ask("Would you like to perform a patch-level bump on the #{@cookbook.name} cookbook now? (Y/N)")
95
- else
96
- ui.warn message_autobump
97
- end
98
- if config[:yes] or answer == "Y" or answer == "y"
99
- bump = SporkBump.new
100
- bump.name_args = [@cookbook.name,"patch"]
101
- bump.run
102
- else
103
- ui.info "Skipping bump..."
104
- end
105
- end
106
- else
107
- message = "The version #{local_version} exists on the server and is not frozen. Uploading will overwrite!"
108
- config[:fail] ? fail_and_exit("#{message}") : ui.error("#{message}")
109
- end
110
-
111
- return
112
- end
113
- end
114
-
115
- ui.msg 'Everything looks good!'
116
- end
117
-
118
- def initial_load
119
- begin
120
- @cookbook = load_cookbook(name_args.first)
121
- rescue Chef::Exceptions::CookbookNotFoundInRepo => e
122
- ui.error "#{name_args.first} does not exist locally in your cookbook path(s), Exiting."
123
- exit(1)
124
- end
125
- end
126
-
127
- def local_version
128
- @cookbook.version
129
- end
130
-
131
- def remote_versions
132
- @remote_versions ||= begin
133
- environment = config[:environment]
134
- api_endpoint = environment ? "environments/#{environment}/cookbooks/#{@cookbook.name}" : "cookbooks/#{@cookbook.name}"
135
- cookbooks = rest.get_rest(api_endpoint)
136
-
137
- versions = cookbooks[@cookbook.name.to_s]['versions']
138
- (config[:all] ? versions : versions[0..4]).collect{|v| v['version']}
139
- rescue Net::HTTPServerException => e
140
- ui.info "#{@cookbook.name} does not yet exist on the Chef Server!"
141
- return []
142
- end
143
- end
144
-
145
- def frozen?(version)
146
- @versions_cache ||= {}
147
-
148
- @versions_cache[version.to_sym] ||= begin
149
- environment = config[:environment]
150
- api_endpoint = environment ? "environments/#{environment}/cookbooks/#{@cookbook.name}" : "cookbooks/#{@cookbook.name}/#{version}"
151
- rest.get_rest(api_endpoint).to_hash['frozen?']
152
- end
153
- end
154
-
155
- def fail_and_exit(message, options={})
156
- ui.fatal message
157
- show_usage if options[:show_usage]
158
- exit 1
159
- end
160
- end
161
- end
1
+ require 'chef/knife'
2
+
3
+ module KnifeSpork
4
+ class SporkCheck < Chef::Knife
5
+
6
+ deps do
7
+ require 'knife-spork/runner'
8
+ end
9
+
10
+ banner 'knife spork check COOKBOOK (options)'
11
+
12
+ option :all,
13
+ :short => '--a',
14
+ :long => '--all',
15
+ :description => 'Show all uploaded versions of the cookbook'
16
+
17
+ option :fail,
18
+ :long => "--fail",
19
+ :description => "If the check fails exit with non-zero exit code"
20
+
21
+ option :fail_if_frozen,
22
+ :long => "--fail-if-frozen",
23
+ :description => "If the check fails exit with non-zero exit code when cookbook is frozen"
24
+
25
+ option :cookbook_path,
26
+ :short => '-o PATH:PATH',
27
+ :long => '--cookbook-path PATH:PATH',
28
+ :description => 'A colon-separated path to look for cookbooks in',
29
+ :proc => lambda { |o| o.split(':') }
30
+
31
+ option :berksfile,
32
+ :short => '-b',
33
+ :long => 'berksfile',
34
+ :description => 'Path to a Berksfile to operate off of',
35
+ :default => nil,
36
+ :proc => lambda { |o| o || File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME) }
37
+
38
+ option :skip_dependencies,
39
+ :short => '-s',
40
+ :long => '--skip-dependencies',
41
+ :description => 'Berksfile skips resolving source cookbook dependencies',
42
+ :default => true
43
+
44
+ def run
45
+ self.class.send(:include, KnifeSpork::Runner)
46
+ self.config = Chef::Config.merge!(config)
47
+
48
+ if name_args.empty?
49
+ ui.fatal 'You must specify a cookbook name!'
50
+ show_usage
51
+ exit(1)
52
+ end
53
+
54
+ # Temporary fix for #138 to allow Berkshelf functionality
55
+ # to be bypassed until #85 has been completed and Berkshelf 3 support added
56
+ unload_berkshelf_if_specified
57
+
58
+ #First load so plugins etc know what to work with
59
+ initial_load
60
+
61
+ run_plugins(:before_check)
62
+
63
+ #Reload cookbook in case a VCS plugin found updates
64
+ initial_load
65
+
66
+ check
67
+ run_plugins(:after_check)
68
+ end
69
+
70
+ private
71
+ def check
72
+ ui.msg "Checking versions for cookbook #{@cookbook.name}..."
73
+ ui.msg ""
74
+ ui.msg "Local Version:"
75
+ ui.msg " #{local_version}"
76
+ ui.msg ""
77
+ ui.msg "Remote Versions: (* indicates frozen)"
78
+ remote_versions.each do |remote_version|
79
+ if frozen?(remote_version)
80
+ ui.msg " *#{remote_version}"
81
+ else
82
+ ui.msg " #{remote_version}"
83
+ end
84
+ end
85
+ ui.msg ""
86
+
87
+ remote_versions.each do |remote_version|
88
+ if remote_version == local_version
89
+ if frozen?(remote_version)
90
+ message = "Your local version (#{local_version}) is frozen on the remote server. You'll need to bump before you can upload."
91
+ message_autobump = "Your local version (#{local_version}) is frozen on the remote server. Autobumping so you can upload."
92
+ if config[:fail] || config[:fail_if_frozen]
93
+ fail_and_exit("#{message}")
94
+ else
95
+ answer = nil
96
+ unless config[:yes]
97
+ ui.warn("#{message}")
98
+ answer = ui.ask("Would you like to perform a patch-level bump on the #{@cookbook.name} cookbook now? (Y/N)")
99
+ else
100
+ ui.warn message_autobump
101
+ end
102
+ if config[:yes] or answer == "Y" or answer == "y"
103
+ bump = SporkBump.new
104
+ bump.name_args = [@cookbook.name,"patch"]
105
+ bump.run
106
+ else
107
+ ui.info "Skipping bump..."
108
+ end
109
+ end
110
+ else
111
+ message = "The version #{local_version} exists on the server and is not frozen. Uploading will overwrite!"
112
+ config[:fail] ? fail_and_exit("#{message}") : ui.error("#{message}")
113
+ end
114
+
115
+ return
116
+ end
117
+ end
118
+
119
+ ui.msg 'Everything looks good!'
120
+ end
121
+
122
+ def initial_load
123
+ begin
124
+ @cookbook = load_cookbook(name_args.first)
125
+ rescue Chef::Exceptions::CookbookNotFoundInRepo => e
126
+ ui.error "#{name_args.first} does not exist locally in your cookbook path(s), Exiting."
127
+ exit(1)
128
+ end
129
+ end
130
+
131
+ def local_version
132
+ @cookbook.version
133
+ end
134
+
135
+ def remote_versions
136
+ @remote_versions ||= begin
137
+ environment = config[:environment]
138
+ api_endpoint = environment ? "environments/#{environment}/cookbooks/#{@cookbook.name}" : "cookbooks/#{@cookbook.name}"
139
+ cookbooks = rest.get_rest(api_endpoint)
140
+
141
+ versions = cookbooks[@cookbook.name.to_s]['versions']
142
+ (config[:all] ? versions : versions[0..4]).collect{|v| v['version']}
143
+ rescue Net::HTTPServerException => e
144
+ ui.info "#{@cookbook.name} does not yet exist on the Chef Server!"
145
+ return []
146
+ end
147
+ end
148
+
149
+ def frozen?(version)
150
+ @versions_cache ||= {}
151
+
152
+ @versions_cache[version.to_sym] ||= begin
153
+ environment = config[:environment]
154
+ api_endpoint = environment ? "environments/#{environment}/cookbooks/#{@cookbook.name}" : "cookbooks/#{@cookbook.name}/#{version}"
155
+ rest.get_rest(api_endpoint).to_hash['frozen?']
156
+ end
157
+ end
158
+
159
+ def fail_and_exit(message, options={})
160
+ ui.fatal message
161
+ show_usage if options[:show_usage]
162
+ exit 1
163
+ end
164
+ end
165
+ end