chef 0.9.6 → 0.9.8.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef/application.rb +19 -3
- data/lib/chef/application/client.rb +7 -8
- data/lib/chef/application/knife.rb +9 -3
- data/lib/chef/application/solo.rb +5 -5
- data/lib/chef/cache/checksum.rb +2 -2
- data/lib/chef/client.rb +30 -64
- data/lib/chef/config.rb +52 -30
- data/lib/chef/cookbook/metadata.rb +12 -1
- data/lib/chef/cookbook_site_streaming_uploader.rb +211 -0
- data/lib/chef/cookbook_uploader.rb +102 -0
- data/lib/chef/cookbook_version.rb +47 -30
- data/lib/chef/couchdb.rb +1 -11
- data/lib/chef/exceptions.rb +1 -0
- data/lib/chef/file_access_control.rb +1 -1
- data/lib/chef/index_queue/amqp_client.rb +10 -3
- data/lib/chef/knife.rb +154 -58
- data/lib/chef/knife/bootstrap.rb +84 -48
- data/lib/chef/knife/bootstrap/centos5-gems.erb +41 -0
- data/lib/chef/knife/bootstrap/fedora13-gems.erb +38 -0
- data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +44 -0
- data/lib/chef/knife/client_bulk_delete.rb +1 -1
- data/lib/chef/knife/client_create.rb +1 -1
- data/lib/chef/knife/client_delete.rb +1 -1
- data/lib/chef/knife/client_edit.rb +1 -1
- data/lib/chef/knife/client_list.rb +1 -1
- data/lib/chef/knife/client_reregister.rb +1 -1
- data/lib/chef/knife/client_show.rb +1 -1
- data/lib/chef/knife/configure.rb +1 -1
- data/lib/chef/knife/configure_client.rb +1 -1
- data/lib/chef/knife/cookbook_bulk_delete.rb +1 -1
- data/lib/chef/knife/cookbook_create.rb +159 -0
- data/lib/chef/knife/cookbook_delete.rb +6 -6
- data/lib/chef/knife/cookbook_download.rb +1 -1
- data/lib/chef/knife/cookbook_list.rb +1 -1
- data/lib/chef/knife/cookbook_metadata.rb +1 -1
- data/lib/chef/knife/cookbook_metadata_from_file.rb +1 -1
- data/lib/chef/knife/cookbook_show.rb +1 -1
- data/lib/chef/knife/cookbook_site_download.rb +2 -1
- data/lib/chef/knife/cookbook_site_list.rb +2 -1
- data/lib/chef/knife/cookbook_site_search.rb +2 -1
- data/lib/chef/knife/cookbook_site_share.rb +108 -0
- data/lib/chef/knife/cookbook_site_show.rb +2 -1
- data/lib/chef/knife/cookbook_site_unshare.rb +52 -0
- data/lib/chef/knife/cookbook_site_vendor.rb +3 -2
- data/lib/chef/knife/cookbook_test.rb +1 -1
- data/lib/chef/knife/cookbook_upload.rb +22 -155
- data/lib/chef/knife/data_bag_create.rb +2 -1
- data/lib/chef/knife/data_bag_delete.rb +2 -1
- data/lib/chef/knife/data_bag_edit.rb +2 -1
- data/lib/chef/knife/data_bag_from_file.rb +2 -1
- data/lib/chef/knife/data_bag_list.rb +2 -1
- data/lib/chef/knife/data_bag_show.rb +2 -1
- data/lib/chef/knife/ec2_instance_data.rb +1 -1
- data/lib/chef/knife/ec2_server_create.rb +16 -4
- data/lib/chef/knife/ec2_server_delete.rb +8 -2
- data/lib/chef/knife/ec2_server_list.rb +8 -2
- data/lib/chef/knife/index_rebuild.rb +1 -1
- data/lib/chef/knife/node_bulk_delete.rb +1 -1
- data/lib/chef/knife/node_create.rb +1 -1
- data/lib/chef/knife/node_delete.rb +1 -1
- data/lib/chef/knife/node_edit.rb +1 -1
- data/lib/chef/knife/node_from_file.rb +1 -1
- data/lib/chef/knife/node_list.rb +1 -1
- data/lib/chef/knife/node_run_list_add.rb +1 -1
- data/lib/chef/knife/node_run_list_remove.rb +1 -1
- data/lib/chef/knife/node_show.rb +1 -1
- data/lib/chef/knife/rackspace_server_create.rb +1 -1
- data/lib/chef/knife/rackspace_server_delete.rb +1 -1
- data/lib/chef/knife/rackspace_server_list.rb +1 -1
- data/lib/chef/knife/recipe_list.rb +1 -1
- data/lib/chef/knife/role_bulk_delete.rb +1 -1
- data/lib/chef/knife/role_create.rb +1 -1
- data/lib/chef/knife/role_delete.rb +1 -1
- data/lib/chef/knife/role_edit.rb +1 -1
- data/lib/chef/knife/role_from_file.rb +1 -1
- data/lib/chef/knife/role_list.rb +1 -1
- data/lib/chef/knife/role_show.rb +1 -1
- data/lib/chef/knife/search.rb +1 -1
- data/lib/chef/knife/slicehost_images_list.rb +1 -1
- data/lib/chef/knife/slicehost_server_create.rb +1 -1
- data/lib/chef/knife/slicehost_server_delete.rb +1 -1
- data/lib/chef/knife/slicehost_server_list.rb +1 -1
- data/lib/chef/knife/ssh.rb +49 -9
- data/lib/chef/knife/status.rb +2 -2
- data/lib/chef/knife/terremark_server_create.rb +1 -1
- data/lib/chef/knife/terremark_server_delete.rb +1 -1
- data/lib/chef/knife/terremark_server_list.rb +1 -1
- data/lib/chef/mixin/command.rb +17 -204
- data/lib/chef/mixin/command/unix.rb +215 -0
- data/lib/chef/mixin/command/windows.rb +72 -0
- data/lib/chef/mixin/find_preferred_file.rb +3 -3
- data/lib/chef/mixin/language.rb +64 -23
- data/lib/chef/node.rb +27 -3
- data/lib/chef/node/attribute.rb +20 -10
- data/lib/chef/platform.rb +3 -9
- data/lib/chef/provider/cron.rb +1 -1
- data/lib/chef/provider/deploy.rb +4 -1
- data/lib/chef/provider/group.rb +1 -1
- data/lib/chef/provider/group/dscl.rb +2 -2
- data/lib/chef/provider/mount/mount.rb +6 -6
- data/lib/chef/provider/package/easy_install.rb +8 -7
- data/lib/chef/provider/package/pacman.rb +1 -1
- data/lib/chef/provider/package/rpm.rb +4 -4
- data/lib/chef/provider/package/solaris.rb +127 -0
- data/lib/chef/provider/package/yum.rb +51 -28
- data/lib/chef/provider/remote_directory.rb +5 -2
- data/lib/chef/provider/remote_file.rb +1 -1
- data/lib/chef/provider/ruby_block.rb +1 -0
- data/lib/chef/provider/script.rb +2 -2
- data/lib/chef/provider/service/debian.rb +40 -4
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/upstart.rb +3 -10
- data/lib/chef/provider/user/dscl.rb +2 -2
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource.rb +7 -8
- data/lib/chef/resource/service.rb +17 -0
- data/lib/chef/resource/solaris_package.rb +36 -0
- data/lib/chef/resource/yum_package.rb +11 -4
- data/lib/chef/rest/rest_request.rb +18 -1
- data/lib/chef/run_list/run_list_expansion.rb +4 -0
- data/lib/chef/run_list/run_list_item.rb +8 -1
- data/lib/chef/shef/ext.rb +1 -1
- data/lib/chef/shef/shef_session.rb +7 -3
- data/lib/chef/tasks/chef_repo.rake +1 -0
- data/lib/chef/version.rb +2 -1
- metadata +23 -8
- data/lib/chef/cache/file_cache_by_checksum.rb +0 -52
@@ -24,7 +24,7 @@ class Chef
|
|
24
24
|
class Knife
|
25
25
|
class CookbookShow < Knife
|
26
26
|
|
27
|
-
banner "
|
27
|
+
banner "knife cookbook show COOKBOOK [VERSION] [PART] [FILENAME] (options)"
|
28
28
|
|
29
29
|
option :fqdn,
|
30
30
|
:short => "-f FQDN",
|
@@ -23,7 +23,8 @@ class Chef
|
|
23
23
|
|
24
24
|
attr_reader :version
|
25
25
|
|
26
|
-
banner "
|
26
|
+
banner "knife cookbook site download COOKBOOK [VERSION] (options)"
|
27
|
+
category "cookbook site"
|
27
28
|
|
28
29
|
option :file,
|
29
30
|
:short => "-f FILE",
|
@@ -21,7 +21,8 @@ class Chef
|
|
21
21
|
class Knife
|
22
22
|
class CookbookSiteSearch < Knife
|
23
23
|
|
24
|
-
banner "
|
24
|
+
banner "knife cookbook site search QUERY (options)"
|
25
|
+
category "cookbook site"
|
25
26
|
|
26
27
|
def run
|
27
28
|
output(search_cookbook(name_args[0]))
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# Author:: Nuo Yan (<nuo@opscode.com>)
|
2
|
+
# Author:: Tim Hinderliter (<tim@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife'
|
20
|
+
require 'chef/cookbook_uploader'
|
21
|
+
require 'chef/cookbook_site_streaming_uploader'
|
22
|
+
|
23
|
+
class Chef
|
24
|
+
class Knife
|
25
|
+
class CookbookSiteShare < Knife
|
26
|
+
|
27
|
+
banner "knife cookbook site share COOKBOOK CATEGORY (options)"
|
28
|
+
category "cookbook site"
|
29
|
+
|
30
|
+
option :cookbook_path,
|
31
|
+
:short => "-o PATH:PATH",
|
32
|
+
:long => "--cookbook-path PATH:PATH",
|
33
|
+
:description => "A colon-separated path to look for cookbooks in",
|
34
|
+
:proc => lambda { |o| Chef::Config.cookbook_path = o.split(":") }
|
35
|
+
|
36
|
+
def run
|
37
|
+
if @name_args.length < 2
|
38
|
+
show_usage
|
39
|
+
Chef::Log.fatal("You must specify the cookbook name and the category you want to share this cookbook to.")
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
|
43
|
+
cookbook_name = @name_args[0]
|
44
|
+
category = @name_args[1]
|
45
|
+
cl = Chef::CookbookLoader.new
|
46
|
+
if cl.cookbook_exists?(cookbook_name)
|
47
|
+
cookbook = cl[cookbook_name]
|
48
|
+
Chef::CookbookUploader.validate_cookbook(cookbook)
|
49
|
+
tmp_cookbook_dir = Chef::CookbookUploader.create_build_dir(cookbook)
|
50
|
+
begin
|
51
|
+
Chef::Log.info("Making tarball #{cookbook_name}.tgz")
|
52
|
+
Chef::Mixin::Command.run_command(:command => "tar -czf #{cookbook_name}.tgz #{cookbook_name}", :cwd => tmp_cookbook_dir)
|
53
|
+
rescue => e
|
54
|
+
Chef::Log.error("Error making tarball #{cookbook_name}.tgz: #{e.message}. Set log level to debug (-l debug) for more information.")
|
55
|
+
Chef::Log.debug("\n#{e.backtrace.join("\n")}")
|
56
|
+
exit(1)
|
57
|
+
end
|
58
|
+
|
59
|
+
begin
|
60
|
+
do_upload("#{tmp_cookbook_dir}/#{cookbook_name}.tgz", category, Chef::Config[:node_name], Chef::Config[:client_key])
|
61
|
+
Chef::Log.info("Upload complete!")
|
62
|
+
Chef::Log.debug("Removing local staging directory at #{tmp_cookbook_dir}")
|
63
|
+
FileUtils.rm_rf tmp_cookbook_dir
|
64
|
+
rescue => e
|
65
|
+
Chef::Log.error("Error uploading cookbook #{cookbook_name} to the Opscode Cookbook Site: #{e.message}. Set log level to debug (-l debug) for more information.")
|
66
|
+
Chef::Log.debug("\n#{e.backtrace.join("\n")}")
|
67
|
+
exit(1)
|
68
|
+
end
|
69
|
+
|
70
|
+
else
|
71
|
+
Chef::Log.error("Could not find cookbook #{cookbook_name} in your cookbook path.")
|
72
|
+
exit(1)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def do_upload(cookbook_filename, cookbook_category, user_id, user_secret_filename)
|
78
|
+
uri = "http://cookbooks.opscode.com/api/v1/cookbooks"
|
79
|
+
|
80
|
+
category_string = { 'category'=>cookbook_category }.to_json
|
81
|
+
|
82
|
+
http_resp = Chef::CookbookSiteStreamingUploader.post(uri, user_id, user_secret_filename, {
|
83
|
+
:tarball => File.open(cookbook_filename),
|
84
|
+
:cookbook => category_string
|
85
|
+
})
|
86
|
+
|
87
|
+
res = JSON.parse(http_resp.body)
|
88
|
+
if http_resp.code.to_i != 201
|
89
|
+
if res['error_messages']
|
90
|
+
if res['error_messages'][0] =~ /Version already exists/
|
91
|
+
Chef::Log.error "The same version of this cookbook already exists on the Opscode Cookbook Site."
|
92
|
+
exit(1)
|
93
|
+
else
|
94
|
+
Chef::Log.error "#{res['error_messages'][0]}"
|
95
|
+
exit(1)
|
96
|
+
end
|
97
|
+
else
|
98
|
+
Chef::Log.error "Unknown error while sharing cookbook"
|
99
|
+
Chef::Log.error "Server response: #{http_resp.body}"
|
100
|
+
exit(1)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
res
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
@@ -21,7 +21,8 @@ class Chef
|
|
21
21
|
class Knife
|
22
22
|
class CookbookSiteShow < Knife
|
23
23
|
|
24
|
-
banner "
|
24
|
+
banner "knife cookbook site show COOKBOOK [VERSION] (options)"
|
25
|
+
category "cookbook site"
|
25
26
|
|
26
27
|
def run
|
27
28
|
case @name_args.length
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Stephen Delano (<stephen@opscode.com>)
|
3
|
+
# Author:: Tim Hinderliter (<tim@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2010 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'chef/knife'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Knife
|
24
|
+
class CookbookSiteUnshare < Knife
|
25
|
+
|
26
|
+
banner "knife cookbook site unshare COOKBOOK"
|
27
|
+
category "cookbook site"
|
28
|
+
|
29
|
+
def run
|
30
|
+
@cookbook_name = @name_args[0]
|
31
|
+
if @cookbook_name.nil?
|
32
|
+
show_usage
|
33
|
+
Chef::Log.fatal "You must provide the name of the cookbook to unshare"
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
confirm "Do you really want to unshare the cookbook #{@cookbook_name}"
|
38
|
+
|
39
|
+
begin
|
40
|
+
rest.delete_rest "http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}"
|
41
|
+
rescue Net::HTTPServerException => e
|
42
|
+
raise e unless e.message =~ /Forbidden/
|
43
|
+
Chef::Log.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it."
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
|
47
|
+
Chef::Log.info "Unshared cookbook #{@cookbook_name}"
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -23,7 +23,8 @@ class Chef
|
|
23
23
|
class Knife
|
24
24
|
class CookbookSiteVendor < Knife
|
25
25
|
|
26
|
-
banner "
|
26
|
+
banner "knife cookbook site vendor COOKBOOK [VERSION] (options)"
|
27
|
+
category "cookbook site"
|
27
28
|
|
28
29
|
option :deps,
|
29
30
|
:short => "-d",
|
@@ -58,7 +59,7 @@ class Chef
|
|
58
59
|
Chef::Mixin::Command.run_command(:command => "git checkout master", :cwd => vendor_path)
|
59
60
|
Chef::Log.info("Checking the status of the vendor branch.")
|
60
61
|
status, branch_output, branch_error = Chef::Mixin::Command.output_of_command("git branch --no-color | grep #{branch_name}", :cwd => vendor_path)
|
61
|
-
if branch_output =~ /#{branch_name}$/m
|
62
|
+
if branch_output =~ /#{Regexp.escape(branch_name)}$/m
|
62
63
|
Chef::Log.info("Vendor branch found.")
|
63
64
|
Chef::Mixin::Command.run_command(:command => "git checkout #{branch_name}", :cwd => vendor_path)
|
64
65
|
else
|
@@ -17,22 +17,16 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require 'rest_client'
|
21
|
-
|
22
20
|
require 'chef/knife'
|
23
21
|
require 'chef/cookbook_loader'
|
24
|
-
require 'chef/
|
25
|
-
require 'chef/sandbox'
|
26
|
-
require 'chef/cookbook_version'
|
27
|
-
require 'chef/cookbook/syntax_check'
|
28
|
-
require 'chef/cookbook/file_system_file_vendor'
|
22
|
+
require 'chef/cookbook_uploader'
|
29
23
|
|
30
24
|
class Chef
|
31
25
|
class Knife
|
32
26
|
class CookbookUpload < Knife
|
33
27
|
include Chef::Mixin::ShellOut
|
34
28
|
|
35
|
-
banner "
|
29
|
+
banner "knife cookbook upload [COOKBOOKS...] (options)"
|
36
30
|
|
37
31
|
option :cookbook_path,
|
38
32
|
:short => "-o PATH:PATH",
|
@@ -51,148 +45,37 @@ class Chef
|
|
51
45
|
else
|
52
46
|
config[:cookbook_path] = Chef::Config[:cookbook_path]
|
53
47
|
end
|
54
|
-
# Ugh, manipulating globals causes bugs.
|
55
|
-
@user_cookbook_path = config[:cookbook_path]
|
56
48
|
|
57
49
|
Chef::Cookbook::FileVendor.on_create { |manifest| Chef::Cookbook::FileSystemFileVendor.new(manifest) }
|
58
50
|
|
59
51
|
cl = Chef::CookbookLoader.new
|
60
|
-
if config[:all]
|
61
|
-
cl.each do |cookbook_name, cookbook|
|
62
|
-
Chef::Log.info("** #{cookbook.name.to_s} **")
|
63
|
-
upload_cookbook(cookbook)
|
64
|
-
end
|
65
|
-
else
|
66
|
-
if @name_args.length < 1
|
67
|
-
show_usage
|
68
|
-
Chef::Log.fatal("You must specify the --all flag or at least one cookbook name")
|
69
|
-
exit 1
|
70
|
-
end
|
71
|
-
@name_args.each do |cookbook_name|
|
72
|
-
if cl.cookbook_exists?(cookbook_name)
|
73
|
-
upload_cookbook(cl[cookbook_name])
|
74
|
-
else
|
75
|
-
Chef::Log.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def upload_cookbook(cookbook)
|
82
|
-
Chef::Log.info("Saving #{cookbook.name}")
|
83
|
-
|
84
|
-
# Validate the cookbook before staging it or else the syntax checker's
|
85
|
-
# cache will not be helpful.
|
86
|
-
validate_cookbook(cookbook)
|
87
|
-
# create build directory
|
88
|
-
tmp_cookbook_dir = create_build_dir(cookbook)
|
89
|
-
|
90
|
-
# create a CookbookLoader that loads a Cookbook from the build directory
|
91
|
-
orig_cookbook_path = nil
|
92
|
-
build_dir_cookbook = nil
|
93
|
-
begin
|
94
|
-
orig_cookbook_path = Chef::Config.cookbook_path
|
95
|
-
Chef::Config.cookbook_path = tmp_cookbook_dir
|
96
|
-
build_dir_cookbook = Chef::CookbookLoader.new[cookbook.name]
|
97
|
-
Chef::Log.debug("Staged cookbook manifest:\n#{JSON.pretty_generate(build_dir_cookbook)}")
|
98
|
-
ensure
|
99
|
-
Chef::Config.cookbook_path = orig_cookbook_path
|
100
|
-
end
|
101
52
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
Chef::Log.info("Uploading files")
|
108
|
-
# upload the new checksums and commit the sandbox
|
109
|
-
new_sandbox['checksums'].each do |checksum, info|
|
110
|
-
if info['needs_upload'] == true
|
111
|
-
Chef::Log.info("Uploading #{checksum_files[checksum]} (checksum hex = #{checksum}) to #{info['url']}")
|
112
|
-
|
113
|
-
# Checksum is the hexadecimal representation of the md5,
|
114
|
-
# but we need the base64 encoding for the content-md5
|
115
|
-
# header
|
116
|
-
checksum64 = Base64.encode64([checksum].pack("H*")).strip
|
117
|
-
timestamp = Time.now.utc.iso8601
|
118
|
-
file_contents = File.read(checksum_files[checksum])
|
119
|
-
# TODO - 5/28/2010, cw: make signing and sending the request streaming
|
120
|
-
sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(
|
121
|
-
:http_method => :put,
|
122
|
-
:path => URI.parse(info['url']).path,
|
123
|
-
:body => file_contents,
|
124
|
-
:timestamp => timestamp,
|
125
|
-
:user_id => rest.client_name
|
126
|
-
)
|
127
|
-
headers = { 'content-type' => 'application/x-binary', 'content-md5' => checksum64, :accept => 'application/json' }
|
128
|
-
headers.merge!(sign_obj.sign(OpenSSL::PKey::RSA.new(rest.signing_key)))
|
129
|
-
begin
|
130
|
-
RestClient::Request.execute(:method => :put, :url => info['url'], :headers => headers, :payload => file_contents)
|
131
|
-
rescue RestClient::RequestFailed => e
|
132
|
-
Chef::Log.error("Upload failed: #{e.message}\n#{e.response.body}")
|
133
|
-
raise
|
53
|
+
humanize_auth_exceptions do
|
54
|
+
if config[:all]
|
55
|
+
cl.each do |cookbook_name, cookbook|
|
56
|
+
Chef::Log.info("** #{cookbook.name.to_s} **")
|
57
|
+
Chef::CookbookUploader.upload_cookbook(cookbook)
|
134
58
|
end
|
135
59
|
else
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
sleep 2
|
149
|
-
retry
|
150
|
-
else
|
151
|
-
raise
|
60
|
+
if @name_args.length < 1
|
61
|
+
show_usage
|
62
|
+
Chef::Log.fatal("You must specify the --all flag or at least one cookbook name")
|
63
|
+
exit 1
|
64
|
+
end
|
65
|
+
@name_args.each do |cookbook_name|
|
66
|
+
if cl.cookbook_exists?(cookbook_name)
|
67
|
+
Chef::CookbookUploader.upload_cookbook(cl[cookbook_name])
|
68
|
+
else
|
69
|
+
Chef::Log.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
|
70
|
+
end
|
71
|
+
end
|
152
72
|
end
|
153
73
|
end
|
154
|
-
|
155
|
-
# files are uploaded, so save the manifest
|
156
|
-
catch_auth_exceptions{ build_dir_cookbook.save }
|
157
|
-
|
158
|
-
Chef::Log.info("Upload complete!")
|
159
|
-
Chef::Log.debug("Removing local staging directory at #{tmp_cookbook_dir}")
|
160
|
-
FileUtils.rm_rf tmp_cookbook_dir
|
161
74
|
end
|
162
75
|
|
163
|
-
|
164
|
-
tmp_cookbook_path = Tempfile.new("chef-#{cookbook.name}-build")
|
165
|
-
tmp_cookbook_path.close
|
166
|
-
tmp_cookbook_dir = tmp_cookbook_path.path
|
167
|
-
File.unlink(tmp_cookbook_dir)
|
168
|
-
FileUtils.mkdir_p(tmp_cookbook_dir)
|
169
|
-
|
170
|
-
Chef::Log.debug("Staging at #{tmp_cookbook_dir}")
|
171
|
-
|
172
|
-
checksums_to_on_disk_paths = cookbook.checksums
|
76
|
+
private
|
173
77
|
|
174
|
-
|
175
|
-
cookbook.manifest[segment].each do |manifest_record|
|
176
|
-
path_in_cookbook = manifest_record[:path]
|
177
|
-
on_disk_path = checksums_to_on_disk_paths[manifest_record[:checksum]]
|
178
|
-
dest = File.join(tmp_cookbook_dir, cookbook.name.to_s, path_in_cookbook)
|
179
|
-
FileUtils.mkdir_p(File.dirname(dest))
|
180
|
-
Chef::Log.debug("Staging #{on_disk_path} to #{dest}")
|
181
|
-
FileUtils.cp(on_disk_path, dest)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
# First, generate metadata
|
186
|
-
Chef::Log.debug("Generating metadata")
|
187
|
-
kcm = Chef::Knife::CookbookMetadata.new
|
188
|
-
kcm.config[:cookbook_path] = [ tmp_cookbook_dir ]
|
189
|
-
kcm.name_args = [ cookbook.name.to_s ]
|
190
|
-
kcm.run
|
191
|
-
|
192
|
-
tmp_cookbook_dir
|
193
|
-
end
|
194
|
-
|
195
|
-
def catch_auth_exceptions
|
78
|
+
def humanize_auth_exceptions
|
196
79
|
begin
|
197
80
|
yield
|
198
81
|
rescue Net::HTTPServerException => e
|
@@ -200,29 +83,13 @@ class Chef
|
|
200
83
|
when "401"
|
201
84
|
Chef::Log.fatal "Request failed due to authentication (#{e}), check your client configuration (username, key)"
|
202
85
|
exit 18
|
203
|
-
else
|
86
|
+
else
|
204
87
|
raise
|
205
88
|
end
|
206
89
|
end
|
207
90
|
end
|
208
91
|
|
209
|
-
def validate_cookbook(cookbook)
|
210
|
-
syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cookbook.name, @user_cookbook_path)
|
211
|
-
Chef::Log.info("Validating ruby files")
|
212
|
-
exit(1) unless syntax_checker.validate_ruby_files
|
213
|
-
Chef::Log.info("Validating templates")
|
214
|
-
exit(1) unless syntax_checker.validate_templates
|
215
|
-
Chef::Log.info("Syntax OK")
|
216
|
-
true
|
217
|
-
end
|
218
92
|
|
219
93
|
end
|
220
94
|
end
|
221
95
|
end
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|