knife-spork 1.7.2 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +35 -35
- data/lib/chef/knife/spork-bump.rb +100 -100
- data/lib/chef/knife/spork-check.rb +165 -161
- data/lib/chef/knife/spork-databag-create.rb +54 -54
- data/lib/chef/knife/spork-databag-delete.rb +51 -51
- data/lib/chef/knife/spork-databag-edit.rb +54 -54
- data/lib/chef/knife/spork-databag-fromfile.rb +88 -88
- data/lib/chef/knife/spork-delete.rb +132 -132
- data/lib/chef/knife/spork-environment-check.rb +90 -90
- data/lib/chef/knife/spork-environment-create.rb +63 -63
- data/lib/chef/knife/spork-environment-delete.rb +38 -38
- data/lib/chef/knife/spork-environment-edit.rb +40 -40
- data/lib/chef/knife/spork-environment-fromfile.rb +46 -46
- data/lib/chef/knife/spork-info.rb +34 -34
- data/lib/chef/knife/spork-node-create.rb +41 -41
- data/lib/chef/knife/spork-node-delete.rb +41 -41
- data/lib/chef/knife/spork-node-edit.rb +48 -48
- data/lib/chef/knife/spork-node-fromfile.rb +46 -46
- data/lib/chef/knife/spork-node-runlistadd.rb +51 -51
- data/lib/chef/knife/spork-node-runlistremove.rb +44 -44
- data/lib/chef/knife/spork-node-runlistset.rb +44 -44
- data/lib/chef/knife/spork-omni.rb +112 -112
- data/lib/chef/knife/spork-promote.rb +197 -197
- data/lib/chef/knife/spork-role-create.rb +46 -46
- data/lib/chef/knife/spork-role-delete.rb +50 -50
- data/lib/chef/knife/spork-role-edit.rb +40 -40
- data/lib/chef/knife/spork-role-fromfile.rb +65 -65
- data/lib/chef/knife/spork-upload.rb +151 -151
- data/lib/chef/knife/spork-version.rb +12 -12
- data/lib/knife-spork.rb +3 -3
- data/lib/knife-spork/plugins.rb +27 -27
- data/lib/knife-spork/plugins/campfire.rb +219 -219
- data/lib/knife-spork/plugins/eventinator.rb +329 -329
- data/lib/knife-spork/plugins/foodcritic.rb +46 -46
- data/lib/knife-spork/plugins/git.rb +393 -399
- data/lib/knife-spork/plugins/graphite.rb +25 -25
- data/lib/knife-spork/plugins/grove.rb +167 -167
- data/lib/knife-spork/plugins/hipchat.rb +171 -171
- data/lib/knife-spork/plugins/influxdb.rb +28 -28
- data/lib/knife-spork/plugins/irccat.rb +332 -332
- data/lib/knife-spork/plugins/jabber.rb +133 -133
- data/lib/knife-spork/plugins/plugin.rb +117 -117
- data/lib/knife-spork/plugins/rubocop.rb +56 -56
- data/lib/knife-spork/plugins/slack.rb +125 -125
- data/lib/knife-spork/plugins/statusnet.rb +122 -122
- data/lib/knife-spork/runner.rb +342 -342
- data/lib/knife-spork/version.rb +5 -5
- metadata +4 -51
- data/.gitignore +0 -21
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -3
- data/CHANGELOG.md +0 -445
- data/Gemfile +0 -3
- data/README.md +0 -544
- data/Rakefile +0 -35
- data/knife-spork.gemspec +0 -28
- data/plugins/Campfire.md +0 -43
- data/plugins/Eventinator.md +0 -30
- data/plugins/Foodcritic.md +0 -53
- data/plugins/Git.md +0 -53
- data/plugins/Graphite.md +0 -30
- data/plugins/Grove.md +0 -31
- data/plugins/HipChat.md +0 -69
- data/plugins/Influxdb.md +0 -25
- data/plugins/Irccat.md +0 -50
- data/plugins/Jabber.md +0 -61
- data/plugins/README.md +0 -70
- data/plugins/Rubocop.md +0 -110
- data/plugins/Slack.md +0 -48
- data/plugins/StatusNet.md +0 -41
- data/plugins/Template.md +0 -34
- data/spec/spec_helper.rb +0 -10
- data/spec/test_helpers.rb +0 -46
- data/spec/unit/fixtures/config/spork-config.yml +0 -1
- data/spec/unit/fixtures/cookbooks/example/metadata.rb +0 -8
- data/spec/unit/fixtures/environments/example.json +0 -12
- data/spec/unit/fixtures/knife.rb +0 -6
- data/spec/unit/fixtures/test_client.pem +0 -27
- data/spec/unit/spork_bump_spec.rb +0 -75
- data/spec/unit/spork_info_spec.rb +0 -40
- data/spec/unit/spork_promote_spec.rb +0 -77
- data/spec/unit/spork_upload_spec.rb +0 -46
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4ae83cf6601495d0432b1bf24073d2e2ae0579b1e2d7d0da06a4d14c21846a54
|
|
4
|
+
data.tar.gz: 0cef1ae4aa4f1f8a9595ea173da77b1d5214a639c06e25e2fd3ea81128694091
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 :
|
|
22
|
-
:
|
|
23
|
-
:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
:
|
|
29
|
-
:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
:
|
|
36
|
-
:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
#
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
ui.msg ""
|
|
73
|
-
ui.msg "
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def
|
|
132
|
-
@
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|