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.
- 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
@@ -1,46 +1,46 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
|
3
|
-
module KnifeSpork
|
4
|
-
class SporkRoleCreate < Chef::Knife
|
5
|
-
|
6
|
-
deps do
|
7
|
-
require 'knife-spork/runner'
|
8
|
-
end
|
9
|
-
|
10
|
-
banner 'knife spork role create ROLE (options)'
|
11
|
-
|
12
|
-
option :description,
|
13
|
-
:short => "-d DESC",
|
14
|
-
:long => "--description DESC",
|
15
|
-
:description => "The role description"
|
16
|
-
|
17
|
-
def run
|
18
|
-
self.class.send(:include, KnifeSpork::Runner)
|
19
|
-
self.config = Chef::Config.merge!(config)
|
20
|
-
|
21
|
-
if @name_args.empty?
|
22
|
-
show_usage
|
23
|
-
ui.error("You must specify a role name")
|
24
|
-
exit 1
|
25
|
-
end
|
26
|
-
|
27
|
-
@object_name = @name_args.first
|
28
|
-
|
29
|
-
run_plugins(:before_rolecreate)
|
30
|
-
pre_role = {}
|
31
|
-
role_create
|
32
|
-
post_role = load_role(@object_name)
|
33
|
-
@object_difference = json_diff(pre_role,post_role).to_s
|
34
|
-
run_plugins(:after_rolecreate)
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
def role_create
|
39
|
-
rc = Chef::Knife::RoleCreate.new
|
40
|
-
rc.name_args = @name_args
|
41
|
-
rc.config[:editor] = config[:editor]
|
42
|
-
rc.config[:description] = config[:description]
|
43
|
-
rc.run
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifeSpork
|
4
|
+
class SporkRoleCreate < Chef::Knife
|
5
|
+
|
6
|
+
deps do
|
7
|
+
require 'knife-spork/runner'
|
8
|
+
end
|
9
|
+
|
10
|
+
banner 'knife spork role create ROLE (options)'
|
11
|
+
|
12
|
+
option :description,
|
13
|
+
:short => "-d DESC",
|
14
|
+
:long => "--description DESC",
|
15
|
+
:description => "The role description"
|
16
|
+
|
17
|
+
def run
|
18
|
+
self.class.send(:include, KnifeSpork::Runner)
|
19
|
+
self.config = Chef::Config.merge!(config)
|
20
|
+
|
21
|
+
if @name_args.empty?
|
22
|
+
show_usage
|
23
|
+
ui.error("You must specify a role name")
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
@object_name = @name_args.first
|
28
|
+
|
29
|
+
run_plugins(:before_rolecreate)
|
30
|
+
pre_role = {}
|
31
|
+
role_create
|
32
|
+
post_role = load_role(@object_name)
|
33
|
+
@object_difference = json_diff(pre_role,post_role).to_s
|
34
|
+
run_plugins(:after_rolecreate)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def role_create
|
39
|
+
rc = Chef::Knife::RoleCreate.new
|
40
|
+
rc.name_args = @name_args
|
41
|
+
rc.config[:editor] = config[:editor]
|
42
|
+
rc.config[:description] = config[:description]
|
43
|
+
rc.run
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
|
3
|
-
module KnifeSpork
|
4
|
-
class SporkRoleDelete < Chef::Knife
|
5
|
-
|
6
|
-
deps do
|
7
|
-
require 'knife-spork/runner'
|
8
|
-
require 'chef/search/query'
|
9
|
-
end
|
10
|
-
|
11
|
-
banner 'knife spork role delete ROLENAME (options)'
|
12
|
-
|
13
|
-
def run
|
14
|
-
self.class.send(:include, KnifeSpork::Runner)
|
15
|
-
self.config = Chef::Config.merge!(config)
|
16
|
-
|
17
|
-
if @name_args.empty?
|
18
|
-
show_usage
|
19
|
-
ui.error("You must specify a role name")
|
20
|
-
exit 1
|
21
|
-
end
|
22
|
-
|
23
|
-
@object_name = @name_args.first
|
24
|
-
|
25
|
-
run_plugins(:before_roledelete)
|
26
|
-
|
27
|
-
if spork_config.role_safe_delete
|
28
|
-
query = Chef::Search::Query.new
|
29
|
-
nodes = query.search('node', "roles:#{@object_name}").first
|
30
|
-
if nodes.size > 0
|
31
|
-
ui.fatal("#{nodes.size} nodes have been found which still contain the role #{@object_name} in their runlists. Please remove this role from all runlists before deleting it.")
|
32
|
-
exit(1)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
pre_role = load_role(@object_name)
|
37
|
-
role_delete
|
38
|
-
post_role = {}
|
39
|
-
@object_difference = json_diff(pre_role,post_role).to_s
|
40
|
-
run_plugins(:after_roledelete)
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
def role_delete
|
45
|
-
rd = Chef::Knife::RoleDelete.new
|
46
|
-
rd.name_args = @name_args
|
47
|
-
rd.run
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifeSpork
|
4
|
+
class SporkRoleDelete < Chef::Knife
|
5
|
+
|
6
|
+
deps do
|
7
|
+
require 'knife-spork/runner'
|
8
|
+
require 'chef/search/query'
|
9
|
+
end
|
10
|
+
|
11
|
+
banner 'knife spork role delete ROLENAME (options)'
|
12
|
+
|
13
|
+
def run
|
14
|
+
self.class.send(:include, KnifeSpork::Runner)
|
15
|
+
self.config = Chef::Config.merge!(config)
|
16
|
+
|
17
|
+
if @name_args.empty?
|
18
|
+
show_usage
|
19
|
+
ui.error("You must specify a role name")
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
|
23
|
+
@object_name = @name_args.first
|
24
|
+
|
25
|
+
run_plugins(:before_roledelete)
|
26
|
+
|
27
|
+
if spork_config.role_safe_delete
|
28
|
+
query = Chef::Search::Query.new
|
29
|
+
nodes = query.search('node', "roles:#{@object_name}").first
|
30
|
+
if nodes.size > 0
|
31
|
+
ui.fatal("#{nodes.size} nodes have been found which still contain the role #{@object_name} in their runlists. Please remove this role from all runlists before deleting it.")
|
32
|
+
exit(1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
pre_role = load_role(@object_name)
|
37
|
+
role_delete
|
38
|
+
post_role = {}
|
39
|
+
@object_difference = json_diff(pre_role,post_role).to_s
|
40
|
+
run_plugins(:after_roledelete)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def role_delete
|
45
|
+
rd = Chef::Knife::RoleDelete.new
|
46
|
+
rd.name_args = @name_args
|
47
|
+
rd.run
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
|
3
|
-
module KnifeSpork
|
4
|
-
class SporkRoleEdit < Chef::Knife
|
5
|
-
|
6
|
-
deps do
|
7
|
-
require 'knife-spork/runner'
|
8
|
-
end
|
9
|
-
|
10
|
-
banner 'knife spork role edit ROLENAME (options)'
|
11
|
-
|
12
|
-
def run
|
13
|
-
self.class.send(:include, KnifeSpork::Runner)
|
14
|
-
self.config = Chef::Config.merge!(config)
|
15
|
-
|
16
|
-
if @name_args.empty?
|
17
|
-
show_usage
|
18
|
-
ui.error("You must specify a role name")
|
19
|
-
exit 1
|
20
|
-
end
|
21
|
-
|
22
|
-
@object_name = @name_args.first
|
23
|
-
|
24
|
-
run_plugins(:before_roleedit)
|
25
|
-
pre_role = load_role(@object_name)
|
26
|
-
role_edit
|
27
|
-
post_role = load_role(@object_name)
|
28
|
-
@object_difference = json_diff(pre_role,post_role).to_s
|
29
|
-
run_plugins(:after_roleedit)
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
def role_edit
|
34
|
-
re = Chef::Knife::RoleEdit.new
|
35
|
-
re.name_args = @name_args
|
36
|
-
re.config[:editor] = config[:editor]
|
37
|
-
re.run
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifeSpork
|
4
|
+
class SporkRoleEdit < Chef::Knife
|
5
|
+
|
6
|
+
deps do
|
7
|
+
require 'knife-spork/runner'
|
8
|
+
end
|
9
|
+
|
10
|
+
banner 'knife spork role edit ROLENAME (options)'
|
11
|
+
|
12
|
+
def run
|
13
|
+
self.class.send(:include, KnifeSpork::Runner)
|
14
|
+
self.config = Chef::Config.merge!(config)
|
15
|
+
|
16
|
+
if @name_args.empty?
|
17
|
+
show_usage
|
18
|
+
ui.error("You must specify a role name")
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
@object_name = @name_args.first
|
23
|
+
|
24
|
+
run_plugins(:before_roleedit)
|
25
|
+
pre_role = load_role(@object_name)
|
26
|
+
role_edit
|
27
|
+
post_role = load_role(@object_name)
|
28
|
+
@object_difference = json_diff(pre_role,post_role).to_s
|
29
|
+
run_plugins(:after_roleedit)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def role_edit
|
34
|
+
re = Chef::Knife::RoleEdit.new
|
35
|
+
re.name_args = @name_args
|
36
|
+
re.config[:editor] = config[:editor]
|
37
|
+
re.run
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,65 +1,65 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
|
3
|
-
module KnifeSpork
|
4
|
-
class SporkRoleFromFile < Chef::Knife
|
5
|
-
|
6
|
-
deps do
|
7
|
-
require 'knife-spork/runner'
|
8
|
-
require 'json'
|
9
|
-
require 'chef/knife/role_from_file'
|
10
|
-
end
|
11
|
-
|
12
|
-
banner 'knife spork role from file FILENAME (options)'
|
13
|
-
|
14
|
-
option :match_filename,
|
15
|
-
:long => '--match-filename',
|
16
|
-
:short => '-f',
|
17
|
-
:description => 'Ensure that the filename matches the name specified in the role (true|false).',
|
18
|
-
:boolean => true,
|
19
|
-
:default => false
|
20
|
-
|
21
|
-
def run
|
22
|
-
self.class.send(:include, KnifeSpork::Runner)
|
23
|
-
self.config = Chef::Config.merge!(config)
|
24
|
-
|
25
|
-
if @name_args.empty?
|
26
|
-
show_usage
|
27
|
-
ui.error("You must specify a role name")
|
28
|
-
exit 1
|
29
|
-
end
|
30
|
-
|
31
|
-
@name_args.each do |arg|
|
32
|
-
@object_name = arg.split("/").last
|
33
|
-
run_plugins(:before_rolefromfile)
|
34
|
-
begin
|
35
|
-
pre_role = load_role(@object_name.gsub(".json","").gsub(".rb",""))
|
36
|
-
rescue Net::HTTPServerException => e
|
37
|
-
pre_role = {}
|
38
|
-
end
|
39
|
-
role_from_file
|
40
|
-
post_role = load_role(@object_name.gsub(".json","").gsub(".rb",""))
|
41
|
-
@object_difference = json_diff(pre_role,post_role).to_s
|
42
|
-
run_plugins(:after_rolefromfile)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
def role_from_file
|
48
|
-
rff = Chef::Knife::RoleFromFile.new
|
49
|
-
rff.name_args = @name_args
|
50
|
-
if (config[:match_filename] || spork_config[:role_match_file_name])
|
51
|
-
## Check if file names match role names
|
52
|
-
@name_args.each do |arg|
|
53
|
-
file_name = arg.split("/").last
|
54
|
-
role = rff.loader.load_from("roles", file_name)
|
55
|
-
file_name = file_name.gsub(".json","").gsub(".rb", "")
|
56
|
-
if file_name != role.name
|
57
|
-
ui.error("Role name in file #{role.name} does not match file name #{file_name}")
|
58
|
-
exit 1
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
rff.run
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifeSpork
|
4
|
+
class SporkRoleFromFile < Chef::Knife
|
5
|
+
|
6
|
+
deps do
|
7
|
+
require 'knife-spork/runner'
|
8
|
+
require 'json'
|
9
|
+
require 'chef/knife/role_from_file'
|
10
|
+
end
|
11
|
+
|
12
|
+
banner 'knife spork role from file FILENAME (options)'
|
13
|
+
|
14
|
+
option :match_filename,
|
15
|
+
:long => '--match-filename',
|
16
|
+
:short => '-f',
|
17
|
+
:description => 'Ensure that the filename matches the name specified in the role (true|false).',
|
18
|
+
:boolean => true,
|
19
|
+
:default => false
|
20
|
+
|
21
|
+
def run
|
22
|
+
self.class.send(:include, KnifeSpork::Runner)
|
23
|
+
self.config = Chef::Config.merge!(config)
|
24
|
+
|
25
|
+
if @name_args.empty?
|
26
|
+
show_usage
|
27
|
+
ui.error("You must specify a role name")
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
@name_args.each do |arg|
|
32
|
+
@object_name = arg.split("/").last
|
33
|
+
run_plugins(:before_rolefromfile)
|
34
|
+
begin
|
35
|
+
pre_role = load_role(@object_name.gsub(".json","").gsub(".rb",""))
|
36
|
+
rescue Net::HTTPServerException => e
|
37
|
+
pre_role = {}
|
38
|
+
end
|
39
|
+
role_from_file
|
40
|
+
post_role = load_role(@object_name.gsub(".json","").gsub(".rb",""))
|
41
|
+
@object_difference = json_diff(pre_role,post_role).to_s
|
42
|
+
run_plugins(:after_rolefromfile)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def role_from_file
|
48
|
+
rff = Chef::Knife::RoleFromFile.new
|
49
|
+
rff.name_args = @name_args
|
50
|
+
if (config[:match_filename] || spork_config[:role_match_file_name])
|
51
|
+
## Check if file names match role names
|
52
|
+
@name_args.each do |arg|
|
53
|
+
file_name = arg.split("/").last
|
54
|
+
role = rff.loader.load_from("roles", file_name)
|
55
|
+
file_name = file_name.gsub(".json","").gsub(".rb", "")
|
56
|
+
if file_name != role.name
|
57
|
+
ui.error("Role name in file #{role.name} does not match file name #{file_name}")
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
rff.run
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,151 +1,151 @@
|
|
1
|
-
require 'chef/knife'
|
2
|
-
|
3
|
-
module KnifeSpork
|
4
|
-
class SporkUpload < Chef::Knife
|
5
|
-
|
6
|
-
deps do
|
7
|
-
require 'chef/exceptions'
|
8
|
-
require 'chef/cookbook_loader'
|
9
|
-
require 'chef/cookbook_uploader'
|
10
|
-
require 'knife-spork/runner'
|
11
|
-
require 'socket'
|
12
|
-
end
|
13
|
-
|
14
|
-
CHECKSUM = 'checksum'
|
15
|
-
MATCH_CHECKSUM = /[0-9a-f]{32,}/
|
16
|
-
|
17
|
-
banner 'knife spork upload [COOKBOOKS...] (options)'
|
18
|
-
|
19
|
-
option :cookbook_path,
|
20
|
-
:short => '-o PATH:PATH',
|
21
|
-
:long => '--cookbook-path PATH:PATH',
|
22
|
-
:description => 'A colon-separated path to look for cookbooks in',
|
23
|
-
:proc => lambda { |o| o.split(':') }
|
24
|
-
|
25
|
-
option :freeze,
|
26
|
-
:long => '--freeze',
|
27
|
-
:description => 'Freeze this version of the cookbook so that it cannot be overwritten',
|
28
|
-
:boolean => true
|
29
|
-
|
30
|
-
option :depends,
|
31
|
-
:short => '-D',
|
32
|
-
:long => '--include-dependencies',
|
33
|
-
:description => 'Also upload cookbook dependencies'
|
34
|
-
|
35
|
-
option :berksfile,
|
36
|
-
:short => '-b',
|
37
|
-
:long => 'berksfile',
|
38
|
-
:description => 'Path to a Berksfile to operate off of',
|
39
|
-
:default => nil,
|
40
|
-
:proc => lambda { |o| o || File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME) }
|
41
|
-
|
42
|
-
def run
|
43
|
-
self.class.send(:include, KnifeSpork::Runner)
|
44
|
-
self.config = Chef::Config.merge!(config)
|
45
|
-
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
46
|
-
|
47
|
-
if @name_args.empty?
|
48
|
-
show_usage
|
49
|
-
ui.error("You must specify the --all flag or at least one cookbook name")
|
50
|
-
exit 1
|
51
|
-
end
|
52
|
-
|
53
|
-
# Temporary fix for #138 to allow Berkshelf functionality
|
54
|
-
# to be bypassed until #85 has been completed and Berkshelf 3 support added
|
55
|
-
unload_berkshelf_if_specified
|
56
|
-
|
57
|
-
#First load so plugins etc know what to work with
|
58
|
-
@cookbooks = load_cookbooks(name_args)
|
59
|
-
include_dependencies if config[:depends]
|
60
|
-
|
61
|
-
run_plugins(:before_upload)
|
62
|
-
|
63
|
-
#Reload cookbook in case a VCS plugin found updates
|
64
|
-
@cookbooks = load_cookbooks(name_args)
|
65
|
-
include_dependencies if config[:depends]
|
66
|
-
|
67
|
-
upload
|
68
|
-
run_plugins(:after_upload)
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
def include_dependencies
|
73
|
-
@cookbooks.each do |cookbook|
|
74
|
-
@cookbooks.concat(load_cookbooks(cookbook.metadata.dependencies.keys))
|
75
|
-
end
|
76
|
-
|
77
|
-
@cookbooks.uniq!
|
78
|
-
end
|
79
|
-
|
80
|
-
def upload
|
81
|
-
# upload cookbooks in reverse so that dependencies are satisfied first
|
82
|
-
@cookbooks.reverse.each do |cookbook|
|
83
|
-
begin
|
84
|
-
check_dependencies(cookbook)
|
85
|
-
if name_args.include?(cookbook.name.to_s)
|
86
|
-
if Gem::Version.new(Chef::VERSION).release >= Gem::Version.new('12.0.0')
|
87
|
-
uploader = Chef::CookbookUploader.new(cookbook)
|
88
|
-
else
|
89
|
-
uploader = Chef::CookbookUploader.new(cookbook, ::Chef::Config.cookbook_path)
|
90
|
-
end
|
91
|
-
begin
|
92
|
-
if uploader.respond_to?(:upload_cookbooks)
|
93
|
-
# Chef >= 10.14.0
|
94
|
-
uploader.upload_cookbooks
|
95
|
-
ui.info "Freezing #{cookbook.name} at #{cookbook.version}..."
|
96
|
-
cookbook.freeze_version
|
97
|
-
uploader.upload_cookbooks
|
98
|
-
else
|
99
|
-
uploader.upload_cookbook
|
100
|
-
ui.info "Freezing #{cookbook.name} at #{cookbook.version}..."
|
101
|
-
cookbook.freeze_version
|
102
|
-
uploader.upload_cookbook
|
103
|
-
|
104
|
-
end
|
105
|
-
rescue Chef::Exceptions::CookbookFrozen => msg
|
106
|
-
ui.error "#{cookbook.name}@#{cookbook.version} is frozen. Please bump your version number before continuing!"
|
107
|
-
exit(1)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
rescue Net::HTTPServerException => e
|
111
|
-
if e.response.code == '409'
|
112
|
-
ui.error "#{cookbook.name}@#{cookbook.version} is frozen. Please bump your version number before continuing!"
|
113
|
-
exit(1)
|
114
|
-
else
|
115
|
-
raise
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
ui.msg "Successfully uploaded #{@cookbooks.collect{|c| "#{c.name}@#{c.version}"}.join(', ')}!"
|
121
|
-
end
|
122
|
-
|
123
|
-
# Ensures that all the cookbooks dependencies are either already on the server or being uploaded in this pass
|
124
|
-
def check_dependencies(cookbook)
|
125
|
-
negotiate_protocol_version
|
126
|
-
cookbook.metadata.dependencies.each do |cookbook_name, version|
|
127
|
-
unless server_has_version(cookbook_name, version)
|
128
|
-
ui.error "#{cookbook.name} depends on #{cookbook_name} (#{version}), which is not currently being uploaded and cannot be found on the server!"
|
129
|
-
exit(1)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def server_has_version(cookbook_name, version)
|
135
|
-
hash = server_side_cookbooks[cookbook_name]
|
136
|
-
hash && hash['versions'] && hash['versions'].any?{ |v| Chef::VersionConstraint.new(version).include?(v['version']) }
|
137
|
-
end
|
138
|
-
|
139
|
-
def server_side_cookbooks
|
140
|
-
if Chef::CookbookVersion.respond_to?(:list_all_versions)
|
141
|
-
@server_side_cookbooks ||= Chef::CookbookVersion.list_all_versions
|
142
|
-
else
|
143
|
-
@server_side_cookbooks ||= Chef::CookbookVersion.list
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def negotiate_protocol_version
|
148
|
-
server_side_cookbooks
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifeSpork
|
4
|
+
class SporkUpload < Chef::Knife
|
5
|
+
|
6
|
+
deps do
|
7
|
+
require 'chef/exceptions'
|
8
|
+
require 'chef/cookbook_loader'
|
9
|
+
require 'chef/cookbook_uploader'
|
10
|
+
require 'knife-spork/runner'
|
11
|
+
require 'socket'
|
12
|
+
end
|
13
|
+
|
14
|
+
CHECKSUM = 'checksum'
|
15
|
+
MATCH_CHECKSUM = /[0-9a-f]{32,}/
|
16
|
+
|
17
|
+
banner 'knife spork upload [COOKBOOKS...] (options)'
|
18
|
+
|
19
|
+
option :cookbook_path,
|
20
|
+
:short => '-o PATH:PATH',
|
21
|
+
:long => '--cookbook-path PATH:PATH',
|
22
|
+
:description => 'A colon-separated path to look for cookbooks in',
|
23
|
+
:proc => lambda { |o| o.split(':') }
|
24
|
+
|
25
|
+
option :freeze,
|
26
|
+
:long => '--freeze',
|
27
|
+
:description => 'Freeze this version of the cookbook so that it cannot be overwritten',
|
28
|
+
:boolean => true
|
29
|
+
|
30
|
+
option :depends,
|
31
|
+
:short => '-D',
|
32
|
+
:long => '--include-dependencies',
|
33
|
+
:description => 'Also upload cookbook dependencies'
|
34
|
+
|
35
|
+
option :berksfile,
|
36
|
+
:short => '-b',
|
37
|
+
:long => 'berksfile',
|
38
|
+
:description => 'Path to a Berksfile to operate off of',
|
39
|
+
:default => nil,
|
40
|
+
:proc => lambda { |o| o || File.join(Dir.pwd, ::Berkshelf::DEFAULT_FILENAME) }
|
41
|
+
|
42
|
+
def run
|
43
|
+
self.class.send(:include, KnifeSpork::Runner)
|
44
|
+
self.config = Chef::Config.merge!(config)
|
45
|
+
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
|
46
|
+
|
47
|
+
if @name_args.empty?
|
48
|
+
show_usage
|
49
|
+
ui.error("You must specify the --all flag or at least one cookbook name")
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
|
53
|
+
# Temporary fix for #138 to allow Berkshelf functionality
|
54
|
+
# to be bypassed until #85 has been completed and Berkshelf 3 support added
|
55
|
+
unload_berkshelf_if_specified
|
56
|
+
|
57
|
+
#First load so plugins etc know what to work with
|
58
|
+
@cookbooks = load_cookbooks(name_args)
|
59
|
+
include_dependencies if config[:depends]
|
60
|
+
|
61
|
+
run_plugins(:before_upload)
|
62
|
+
|
63
|
+
#Reload cookbook in case a VCS plugin found updates
|
64
|
+
@cookbooks = load_cookbooks(name_args)
|
65
|
+
include_dependencies if config[:depends]
|
66
|
+
|
67
|
+
upload
|
68
|
+
run_plugins(:after_upload)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def include_dependencies
|
73
|
+
@cookbooks.each do |cookbook|
|
74
|
+
@cookbooks.concat(load_cookbooks(cookbook.metadata.dependencies.keys))
|
75
|
+
end
|
76
|
+
|
77
|
+
@cookbooks.uniq!
|
78
|
+
end
|
79
|
+
|
80
|
+
def upload
|
81
|
+
# upload cookbooks in reverse so that dependencies are satisfied first
|
82
|
+
@cookbooks.reverse.each do |cookbook|
|
83
|
+
begin
|
84
|
+
check_dependencies(cookbook)
|
85
|
+
if name_args.include?(cookbook.name.to_s)
|
86
|
+
if Gem::Version.new(Chef::VERSION).release >= Gem::Version.new('12.0.0')
|
87
|
+
uploader = Chef::CookbookUploader.new(cookbook)
|
88
|
+
else
|
89
|
+
uploader = Chef::CookbookUploader.new(cookbook, ::Chef::Config.cookbook_path)
|
90
|
+
end
|
91
|
+
begin
|
92
|
+
if uploader.respond_to?(:upload_cookbooks)
|
93
|
+
# Chef >= 10.14.0
|
94
|
+
uploader.upload_cookbooks
|
95
|
+
ui.info "Freezing #{cookbook.name} at #{cookbook.version}..."
|
96
|
+
cookbook.freeze_version
|
97
|
+
uploader.upload_cookbooks
|
98
|
+
else
|
99
|
+
uploader.upload_cookbook
|
100
|
+
ui.info "Freezing #{cookbook.name} at #{cookbook.version}..."
|
101
|
+
cookbook.freeze_version
|
102
|
+
uploader.upload_cookbook
|
103
|
+
|
104
|
+
end
|
105
|
+
rescue Chef::Exceptions::CookbookFrozen => msg
|
106
|
+
ui.error "#{cookbook.name}@#{cookbook.version} is frozen. Please bump your version number before continuing!"
|
107
|
+
exit(1)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
rescue Net::HTTPServerException => e
|
111
|
+
if e.response.code == '409'
|
112
|
+
ui.error "#{cookbook.name}@#{cookbook.version} is frozen. Please bump your version number before continuing!"
|
113
|
+
exit(1)
|
114
|
+
else
|
115
|
+
raise
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
ui.msg "Successfully uploaded #{@cookbooks.collect{|c| "#{c.name}@#{c.version}"}.join(', ')}!"
|
121
|
+
end
|
122
|
+
|
123
|
+
# Ensures that all the cookbooks dependencies are either already on the server or being uploaded in this pass
|
124
|
+
def check_dependencies(cookbook)
|
125
|
+
negotiate_protocol_version
|
126
|
+
cookbook.metadata.dependencies.each do |cookbook_name, version|
|
127
|
+
unless server_has_version(cookbook_name, version)
|
128
|
+
ui.error "#{cookbook.name} depends on #{cookbook_name} (#{version}), which is not currently being uploaded and cannot be found on the server!"
|
129
|
+
exit(1)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def server_has_version(cookbook_name, version)
|
135
|
+
hash = server_side_cookbooks[cookbook_name]
|
136
|
+
hash && hash['versions'] && hash['versions'].any?{ |v| Chef::VersionConstraint.new(version).include?(v['version']) }
|
137
|
+
end
|
138
|
+
|
139
|
+
def server_side_cookbooks
|
140
|
+
if Chef::CookbookVersion.respond_to?(:list_all_versions)
|
141
|
+
@server_side_cookbooks ||= Chef::CookbookVersion.list_all_versions
|
142
|
+
else
|
143
|
+
@server_side_cookbooks ||= Chef::CookbookVersion.list
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def negotiate_protocol_version
|
148
|
+
server_side_cookbooks
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|