chef 0.9.18 → 0.10.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. data/README.rdoc +0 -3
  2. data/distro/arch/etc/rc.d/chef-server +0 -4
  3. data/distro/arch/etc/rc.d/chef-server-webui +0 -4
  4. data/distro/arch/etc/rc.d/chef-solr +0 -4
  5. data/distro/arch/etc/rc.d/chef-solr-indexer +0 -4
  6. data/lib/chef.rb +3 -3
  7. data/lib/chef/api_client.rb +1 -1
  8. data/lib/chef/application.rb +11 -1
  9. data/lib/chef/application/client.rb +18 -22
  10. data/lib/chef/application/knife.rb +28 -29
  11. data/lib/chef/application/solo.rb +14 -12
  12. data/lib/chef/client.rb +112 -54
  13. data/lib/chef/config.rb +4 -0
  14. data/lib/chef/cookbook/chefignore.rb +66 -0
  15. data/lib/chef/cookbook/cookbook_collection.rb +6 -5
  16. data/lib/chef/cookbook/cookbook_version_loader.rb +151 -0
  17. data/lib/chef/cookbook/file_system_file_vendor.rb +10 -8
  18. data/lib/chef/cookbook/metadata.rb +200 -108
  19. data/lib/chef/cookbook_loader.rb +39 -163
  20. data/lib/chef/cookbook_uploader.rb +100 -78
  21. data/lib/chef/cookbook_version.rb +92 -47
  22. data/lib/chef/cookbook_version_selector.rb +163 -0
  23. data/lib/chef/couchdb.rb +9 -1
  24. data/lib/chef/data_bag.rb +1 -1
  25. data/lib/chef/data_bag_item.rb +1 -1
  26. data/lib/chef/encrypted_data_bag_item.rb +126 -0
  27. data/lib/chef/environment.rb +386 -0
  28. data/lib/chef/exceptions.rb +82 -1
  29. data/lib/chef/index_queue/amqp_client.rb +15 -12
  30. data/lib/chef/index_queue/indexable.rb +38 -4
  31. data/lib/chef/json_compat.rb +3 -3
  32. data/lib/chef/knife.rb +97 -202
  33. data/lib/chef/knife/bootstrap.rb +27 -61
  34. data/lib/chef/knife/bootstrap/archlinux-gems.erb +4 -2
  35. data/lib/chef/knife/bootstrap/centos5-gems.erb +6 -15
  36. data/lib/chef/knife/bootstrap/fedora13-gems.erb +3 -4
  37. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
  38. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +6 -5
  39. data/lib/chef/knife/client_bulk_delete.rb +6 -3
  40. data/lib/chef/knife/client_create.rb +13 -10
  41. data/lib/chef/knife/client_delete.rb +10 -7
  42. data/lib/chef/knife/client_edit.rb +9 -6
  43. data/lib/chef/knife/client_list.rb +8 -5
  44. data/lib/chef/knife/client_reregister.rb +9 -6
  45. data/lib/chef/knife/client_show.rb +9 -6
  46. data/lib/chef/knife/configure.rb +15 -19
  47. data/lib/chef/knife/configure_client.rb +4 -4
  48. data/lib/chef/knife/cookbook_bulk_delete.rb +11 -8
  49. data/lib/chef/knife/cookbook_create.rb +120 -55
  50. data/lib/chef/knife/cookbook_delete.rb +18 -12
  51. data/lib/chef/knife/cookbook_download.rb +10 -6
  52. data/lib/chef/knife/cookbook_list.rb +15 -6
  53. data/lib/chef/knife/cookbook_metadata.rb +41 -21
  54. data/lib/chef/knife/cookbook_metadata_from_file.rb +4 -0
  55. data/lib/chef/knife/cookbook_show.rb +16 -5
  56. data/lib/chef/knife/cookbook_site_download.rb +2 -2
  57. data/lib/chef/knife/cookbook_site_share.rb +18 -13
  58. data/lib/chef/knife/cookbook_site_unshare.rb +7 -4
  59. data/lib/chef/knife/cookbook_site_vendor.rb +21 -18
  60. data/lib/chef/knife/cookbook_test.rb +14 -14
  61. data/lib/chef/knife/cookbook_upload.rb +91 -40
  62. data/lib/chef/knife/data_bag_create.rb +41 -6
  63. data/lib/chef/knife/data_bag_delete.rb +5 -3
  64. data/lib/chef/knife/data_bag_edit.rb +55 -11
  65. data/lib/chef/knife/data_bag_from_file.rb +47 -7
  66. data/lib/chef/knife/data_bag_list.rb +4 -1
  67. data/lib/chef/knife/data_bag_show.rb +44 -4
  68. data/lib/chef/knife/environment_create.rb +53 -0
  69. data/lib/chef/knife/environment_delete.rb +45 -0
  70. data/lib/chef/knife/environment_edit.rb +45 -0
  71. data/lib/chef/knife/environment_from_file.rb +39 -0
  72. data/lib/chef/knife/environment_list.rb +42 -0
  73. data/lib/chef/knife/environment_show.rb +46 -0
  74. data/lib/chef/knife/exec.rb +1 -1
  75. data/lib/chef/knife/index_rebuild.rb +8 -9
  76. data/lib/chef/knife/node_bulk_delete.rb +9 -6
  77. data/lib/chef/knife/node_create.rb +9 -6
  78. data/lib/chef/knife/node_delete.rb +10 -7
  79. data/lib/chef/knife/node_edit.rb +129 -10
  80. data/lib/chef/knife/node_from_file.rb +10 -7
  81. data/lib/chef/knife/node_list.rb +11 -6
  82. data/lib/chef/knife/node_run_list_add.rb +10 -7
  83. data/lib/chef/knife/node_run_list_remove.rb +9 -6
  84. data/lib/chef/knife/node_show.rb +15 -7
  85. data/lib/chef/knife/recipe_list.rb +4 -3
  86. data/lib/chef/knife/role_bulk_delete.rb +9 -6
  87. data/lib/chef/knife/role_create.rb +9 -6
  88. data/lib/chef/knife/role_delete.rb +10 -7
  89. data/lib/chef/knife/role_edit.rb +11 -8
  90. data/lib/chef/knife/role_from_file.rb +10 -7
  91. data/lib/chef/knife/role_list.rb +8 -5
  92. data/lib/chef/knife/role_show.rb +11 -8
  93. data/lib/chef/knife/search.rb +33 -10
  94. data/lib/chef/knife/ssh.rb +33 -61
  95. data/lib/chef/knife/status.rb +7 -4
  96. data/lib/chef/knife/subcommand_loader.rb +101 -0
  97. data/lib/chef/knife/tag_create.rb +31 -0
  98. data/lib/chef/knife/tag_delete.rb +31 -0
  99. data/lib/chef/knife/tag_list.rb +29 -0
  100. data/lib/chef/knife/ui.rb +229 -0
  101. data/lib/chef/knife/windows_bootstrap.rb +8 -5
  102. data/lib/chef/log.rb +5 -59
  103. data/lib/chef/mash.rb +211 -0
  104. data/lib/chef/mixins.rb +1 -2
  105. data/lib/chef/nil_argument.rb +3 -0
  106. data/lib/chef/node.rb +96 -34
  107. data/lib/chef/platform.rb +27 -0
  108. data/lib/chef/provider/cookbook_file.rb +21 -20
  109. data/lib/chef/provider/deploy/revision.rb +3 -0
  110. data/lib/chef/provider/file.rb +20 -11
  111. data/lib/chef/provider/git.rb +26 -26
  112. data/lib/chef/provider/group/aix.rb +70 -0
  113. data/lib/chef/provider/group/groupadd.rb +7 -4
  114. data/lib/chef/provider/group/usermod.rb +1 -1
  115. data/lib/chef/provider/package.rb +28 -28
  116. data/lib/chef/provider/package/dpkg.rb +1 -1
  117. data/lib/chef/provider/package/portage.rb +50 -39
  118. data/lib/chef/provider/package/rubygems.rb +1 -1
  119. data/lib/chef/provider/package/zypper.rb +3 -20
  120. data/lib/chef/provider/remote_directory.rb +0 -2
  121. data/lib/chef/provider/remote_file.rb +2 -3
  122. data/lib/chef/provider/service/arch.rb +28 -35
  123. data/lib/chef/provider/service/simple.rb +1 -1
  124. data/lib/chef/provider/subversion.rb +22 -22
  125. data/lib/chef/providers.rb +1 -0
  126. data/lib/chef/recipe.rb +10 -12
  127. data/lib/chef/resource.rb +49 -42
  128. data/lib/chef/resource/gem_package.rb +7 -3
  129. data/lib/chef/resource/git.rb +5 -5
  130. data/lib/chef/resource/package.rb +7 -7
  131. data/lib/chef/resource/scm.rb +2 -1
  132. data/lib/chef/resource/solaris_package.rb +0 -1
  133. data/lib/chef/resource/yum_package.rb +0 -1
  134. data/lib/chef/rest.rb +7 -16
  135. data/lib/chef/rest/rest_request.rb +0 -16
  136. data/lib/chef/role.rb +67 -13
  137. data/lib/chef/run_context.rb +37 -21
  138. data/lib/chef/run_list.rb +30 -15
  139. data/lib/chef/run_list/run_list_expansion.rb +41 -20
  140. data/lib/chef/run_list/run_list_item.rb +20 -6
  141. data/lib/chef/run_list/versioned_recipe_list.rb +68 -0
  142. data/lib/chef/runner.rb +7 -15
  143. data/lib/chef/search/query.rb +12 -7
  144. data/lib/chef/shef.rb +6 -7
  145. data/lib/chef/shef/shef_session.rb +40 -35
  146. data/lib/chef/shell_out.rb +22 -201
  147. data/lib/chef/shell_out/unix.rb +224 -0
  148. data/lib/chef/shell_out/windows.rb +95 -0
  149. data/lib/chef/solr_query.rb +187 -0
  150. data/lib/chef/solr_query/lucene.treetop +145 -0
  151. data/lib/chef/solr_query/lucene_nodes.rb +285 -0
  152. data/lib/chef/solr_query/query_transform.rb +65 -0
  153. data/lib/chef/solr_query/solr_http_request.rb +118 -0
  154. data/lib/chef/version.rb +4 -2
  155. data/lib/chef/version_class.rb +70 -0
  156. data/lib/chef/version_constraint.rb +116 -0
  157. metadata +68 -37
  158. data/lib/chef/cookbook/metadata/version.rb +0 -87
  159. data/lib/chef/knife/bluebox_images_list.rb +0 -54
  160. data/lib/chef/knife/bluebox_server_create.rb +0 -157
  161. data/lib/chef/knife/bluebox_server_delete.rb +0 -63
  162. data/lib/chef/knife/bluebox_server_list.rb +0 -59
  163. data/lib/chef/knife/ec2_instance_data.rb +0 -46
  164. data/lib/chef/knife/ec2_server_create.rb +0 -218
  165. data/lib/chef/knife/ec2_server_delete.rb +0 -87
  166. data/lib/chef/knife/ec2_server_list.rb +0 -89
  167. data/lib/chef/knife/rackspace_server_create.rb +0 -184
  168. data/lib/chef/knife/rackspace_server_delete.rb +0 -57
  169. data/lib/chef/knife/rackspace_server_list.rb +0 -59
  170. data/lib/chef/knife/slicehost_images_list.rb +0 -53
  171. data/lib/chef/knife/slicehost_server_create.rb +0 -103
  172. data/lib/chef/knife/slicehost_server_delete.rb +0 -61
  173. data/lib/chef/knife/slicehost_server_list.rb +0 -64
  174. data/lib/chef/knife/terremark_server_create.rb +0 -152
  175. data/lib/chef/knife/terremark_server_delete.rb +0 -87
  176. data/lib/chef/knife/terremark_server_list.rb +0 -77
  177. data/lib/chef/mixin/find_preferred_file.rb +0 -92
@@ -18,12 +18,15 @@
18
18
  #
19
19
 
20
20
  require 'chef/knife'
21
- require 'chef/json_compat'
22
21
 
23
22
  class Chef
24
23
  class Knife
25
24
  class CookbookSiteUnshare < Knife
26
25
 
26
+ deps do
27
+ require 'chef/json_compat'
28
+ end
29
+
27
30
  banner "knife cookbook site unshare COOKBOOK"
28
31
  category "cookbook site"
29
32
 
@@ -31,7 +34,7 @@ class Chef
31
34
  @cookbook_name = @name_args[0]
32
35
  if @cookbook_name.nil?
33
36
  show_usage
34
- Chef::Log.fatal "You must provide the name of the cookbook to unshare"
37
+ ui.fatal "You must provide the name of the cookbook to unshare"
35
38
  exit 1
36
39
  end
37
40
 
@@ -41,11 +44,11 @@ class Chef
41
44
  rest.delete_rest "http://cookbooks.opscode.com/api/v1/cookbooks/#{@name_args[0]}"
42
45
  rescue Net::HTTPServerException => e
43
46
  raise e unless e.message =~ /Forbidden/
44
- Chef::Log.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it."
47
+ ui.error "Forbidden: You must be the maintainer of #{@cookbook_name} to unshare it."
45
48
  exit 1
46
49
  end
47
50
 
48
- Chef::Log.info "Unshared cookbook #{@cookbook_name}"
51
+ ui.info "Unshared cookbook #{@cookbook_name}"
49
52
  end
50
53
 
51
54
  end
@@ -17,12 +17,15 @@
17
17
  #
18
18
 
19
19
  require 'chef/knife'
20
- require 'chef/cookbook/metadata'
21
20
 
22
21
  class Chef
23
22
  class Knife
24
23
  class CookbookSiteVendor < Knife
25
24
 
25
+ deps do
26
+ require 'chef/cookbook/metadata'
27
+ end
28
+
26
29
  banner "knife cookbook site vendor COOKBOOK [VERSION] (options)"
27
30
  category "cookbook site"
28
31
 
@@ -53,7 +56,7 @@ class Chef
53
56
 
54
57
  # Check to ensure we have a valid source of cookbooks before continuing
55
58
  unless File.directory?(config[:cookbook_path].first)
56
- Chef::Log.error( File.join(config[:cookbook_path].first, " doesn't exist!. Make sure you have cookbook_path configured correctly"))
59
+ ui.error( File.join(config[:cookbook_path].first, " doesn't exist!. Make sure you have cookbook_path configured correctly"))
57
60
  exit 1
58
61
  end
59
62
 
@@ -67,49 +70,49 @@ class Chef
67
70
  download.name_args = name_args
68
71
  download.run
69
72
 
70
- Chef::Log.info("Checking out the #{config[:branch_default]} branch.")
73
+ ui.info("Checking out the #{config[:branch_default]} branch.")
71
74
  Chef::Mixin::Command.run_command(:command => "git checkout #{config[:branch_default]}", :cwd => vendor_path)
72
- Chef::Log.info("Checking the status of the vendor branch.")
75
+ ui.info("Checking the status of the vendor branch.")
73
76
  status, branch_output, branch_error = Chef::Mixin::Command.output_of_command("git branch --no-color | grep #{branch_name}", :cwd => vendor_path)
74
77
  if branch_output =~ /#{Regexp.escape(branch_name)}$/m
75
- Chef::Log.info("Vendor branch found.")
78
+ ui.info("Vendor branch found.")
76
79
  Chef::Mixin::Command.run_command(:command => "git checkout #{branch_name}", :cwd => vendor_path)
77
80
  else
78
- Chef::Log.info("Creating vendor branch.")
81
+ ui.info("Creating vendor branch.")
79
82
  Chef::Mixin::Command.run_command(:command => "git checkout -b #{branch_name}", :cwd => vendor_path)
80
83
  end
81
- Chef::Log.info("Removing pre-existing version.")
84
+ ui.info("Removing pre-existing version.")
82
85
  Chef::Mixin::Command.run_command(:command => "rm -r #{cookbook_path}", :cwd => vendor_path) if File.directory?(cookbook_path)
83
- Chef::Log.info("Uncompressing #{name_args[0]} version #{download.version}.")
86
+ ui.info("Uncompressing #{name_args[0]} version #{download.version}.")
84
87
  Chef::Mixin::Command.run_command(:command => "tar zxvf #{upstream_file}", :cwd => vendor_path)
85
88
  Chef::Mixin::Command.run_command(:command => "rm #{upstream_file}", :cwd => vendor_path)
86
- Chef::Log.info("Adding changes.")
89
+ ui.info("Adding changes.")
87
90
  Chef::Mixin::Command.run_command(:command => "git add #{name_args[0]}", :cwd => vendor_path)
88
91
 
89
- Chef::Log.info("Committing changes.")
92
+ ui.info("Committing changes.")
90
93
  changes = true
91
94
  begin
92
95
  Chef::Mixin::Command.run_command(:command => "git commit -a -m 'Import #{name_args[0]} version #{download.version}'", :cwd => vendor_path)
93
96
  rescue Chef::Exceptions::Exec => e
94
- Chef::Log.warn("Checking out the #{config[:branch_default]} branch.")
95
- Chef::Log.warn("No changes from current vendor #{name_args[0]}")
97
+ ui.warn("Checking out the #{config[:branch_default]} branch.")
98
+ ui.warn("No changes from current vendor #{name_args[0]}")
96
99
  Chef::Mixin::Command.run_command(:command => "git checkout #{config[:branch_default]}", :cwd => vendor_path)
97
100
  changes = false
98
101
  end
99
102
 
100
103
  if changes
101
- Chef::Log.info("Creating tag chef-vendor-#{name_args[0]}-#{download.version}.")
104
+ ui.info("Creating tag chef-vendor-#{name_args[0]}-#{download.version}.")
102
105
  Chef::Mixin::Command.run_command(:command => "git tag -f chef-vendor-#{name_args[0]}-#{download.version}", :cwd => vendor_path)
103
- Chef::Log.info("Checking out the #{config[:branch_default]} branch.")
106
+ ui.info("Checking out the #{config[:branch_default]} branch.")
104
107
  Chef::Mixin::Command.run_command(:command => "git checkout #{config[:branch_default]}", :cwd => vendor_path)
105
- Chef::Log.info("Merging changes from #{name_args[0]} version #{download.version}.")
108
+ ui.info("Merging changes from #{name_args[0]} version #{download.version}.")
106
109
 
107
110
  Dir.chdir(vendor_path) do
108
111
  if system("git merge #{branch_name}")
109
- Chef::Log.info("Cookbook #{name_args[0]} version #{download.version} successfully vendored!")
112
+ ui.info("Cookbook #{name_args[0]} version #{download.version} successfully vendored!")
110
113
  else
111
- Chef::Log.error("You have merge conflicts - please resolve manually!")
112
- Chef::Log.error("(Hint: cd #{vendor_path}; git status)")
114
+ ui.error("You have merge conflicts - please resolve manually!")
115
+ ui.error("(Hint: cd #{vendor_path}; git status)")
113
116
  exit 1
114
117
  end
115
118
  end
@@ -9,9 +9,9 @@
9
9
  # Licensed under the Apache License, Version 2.0 (the "License");
10
10
  # you may not use this file except in compliance with the License.
11
11
  # You may obtain a copy of the License at
12
- #
12
+ #
13
13
  # http://www.apache.org/licenses/LICENSE-2.0
14
- #
14
+ #
15
15
  # Unless required by applicable law or agreed to in writing, software
16
16
  # distributed under the License is distributed on an "AS IS" BASIS,
17
17
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,12 +19,16 @@
19
19
  # limitations under the License.
20
20
  #
21
21
  require 'chef/knife'
22
- require 'chef/checksum_cache'
23
22
 
24
23
  class Chef
25
24
  class Knife
26
25
  class CookbookTest < Knife
27
26
 
27
+ deps do
28
+ require 'chef/checksum_cache'
29
+ require 'chef/cookbook/syntax_check'
30
+ end
31
+
28
32
  banner "knife cookbook test [COOKBOOKS...] (options)"
29
33
 
30
34
  option :cookbook_path,
@@ -38,15 +42,11 @@ class Chef
38
42
  :long => "--all",
39
43
  :description => "Test all cookbooks, rather than just a single cookbook"
40
44
 
41
- def run
42
- if config[:cookbook_path]
43
- Chef::Config[:cookbook_path] = config[:cookbook_path]
44
- else
45
- config[:cookbook_path] = Chef::Config[:cookbook_path]
46
- end
45
+ def run
46
+ config[:cookbook_path] ||= Chef::Config[:cookbook_path]
47
47
 
48
48
  if config[:all]
49
- cl = Chef::CookbookLoader.new
49
+ cl = Chef::CookbookLoader.new(config[:cookbook_path])
50
50
  cl.each do |key, cookbook|
51
51
  test_cookbook(key)
52
52
  end
@@ -58,7 +58,7 @@ class Chef
58
58
  end
59
59
 
60
60
  def test_cookbook(cookbook)
61
- Chef::Log.info("Running syntax check on #{cookbook}")
61
+ ui.info("Running syntax check on #{cookbook}")
62
62
  Array(config[:cookbook_path]).reverse.each do |path|
63
63
  syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cookbook, path)
64
64
  test_ruby(syntax_checker)
@@ -68,12 +68,12 @@ class Chef
68
68
 
69
69
 
70
70
  def test_ruby(syntax_checker)
71
- Chef::Log.info("Validating ruby files")
71
+ ui.info("Validating ruby files")
72
72
  exit(1) unless syntax_checker.validate_ruby_files
73
73
  end
74
-
74
+
75
75
  def test_templates(syntax_checker)
76
- Chef::Log.info("Validating templates")
76
+ ui.info("Validating templates")
77
77
  exit(1) unless syntax_checker.validate_templates
78
78
  end
79
79
 
@@ -18,13 +18,16 @@
18
18
  #
19
19
 
20
20
  require 'chef/knife'
21
- require 'chef/cookbook_loader'
22
- require 'chef/cookbook_uploader'
23
21
 
24
22
  class Chef
25
23
  class Knife
26
24
  class CookbookUpload < Knife
27
- include Chef::Mixin::ShellOut
25
+
26
+ deps do
27
+ require 'chef/exceptions'
28
+ require 'chef/cookbook_loader'
29
+ require 'chef/cookbook_uploader'
30
+ end
28
31
 
29
32
  banner "knife cookbook upload [COOKBOOKS...] (options)"
30
33
 
@@ -34,61 +37,109 @@ class Chef
34
37
  :description => "A colon-separated path to look for cookbooks in",
35
38
  :proc => lambda { |o| o.split(":") }
36
39
 
40
+ option :freeze,
41
+ :long => '--freeze',
42
+ :description => 'Freeze this version of the cookbook so that it cannot be overwritten',
43
+ :boolean => true
44
+
37
45
  option :all,
38
46
  :short => "-a",
39
47
  :long => "--all",
40
48
  :description => "Upload all cookbooks, rather than just a single cookbook"
41
49
 
42
- def run
43
- if config[:cookbook_path]
44
- Chef::Config[:cookbook_path] = config[:cookbook_path]
45
- else
46
- config[:cookbook_path] = Chef::Config[:cookbook_path]
47
- end
50
+ option :force,
51
+ :long => '--force',
52
+ :boolean => true,
53
+ :description => "Update cookbook versions even if they have been frozen"
48
54
 
49
- Chef::Cookbook::FileVendor.on_create { |manifest| Chef::Cookbook::FileSystemFileVendor.new(manifest) }
55
+ option :environment,
56
+ :short => '-E',
57
+ :long => '--environment ENVIRONMENT',
58
+ :description => "Set ENVIRONMENT's version dependency match the version you're uploading."
50
59
 
51
- cl = Chef::CookbookLoader.new
60
+ def run
61
+ config[:cookbook_path] ||= Chef::Config[:cookbook_path]
52
62
 
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)
58
- end
59
- else
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
63
+ assert_environment_valid!
64
+ version_constraints_to_update = {}
65
+
66
+ if config[:all]
67
+ cookbook_repo.each do |cookbook_name, cookbook|
68
+ cookbook.freeze_version if config[:freeze]
69
+ upload(cookbook)
70
+ version_constraints_to_update[cookbook_name] = cookbook.version
71
+ end
72
+ else
73
+ if @name_args.empty?
74
+ show_usage
75
+ Chef::Log.fatal("You must specify the --all flag or at least one cookbook name")
76
+ exit 1
77
+ end
78
+ @name_args.each do |cookbook_name|
79
+ begin
80
+ cookbook = cookbook_repo[cookbook_name]
81
+ cookbook.freeze_version if config[:freeze]
82
+ upload(cookbook)
83
+ version_constraints_to_update[cookbook_name] = cookbook.version
84
+ rescue Exceptions::CookbookNotFoundInRepo => e
85
+ Log.error("Could not find cookbook #{cookbook_name} in your cookbook path, skipping it")
86
+ Log.debug(e)
71
87
  end
72
88
  end
73
89
  end
90
+
91
+ update_version_constraints(version_constraints_to_update) if config[:environment]
92
+ end
93
+
94
+ def cookbook_repo
95
+ @cookbook_loader ||= begin
96
+ Chef::Cookbook::FileVendor.on_create { |manifest| Chef::Cookbook::FileSystemFileVendor.new(manifest, config[:cookbook_path]) }
97
+ Chef::CookbookLoader.new(config[:cookbook_path])
98
+ end
99
+ end
100
+
101
+ def update_version_constraints(new_version_constraints)
102
+ new_version_constraints.each do |cookbook_name, version|
103
+ environment.cookbook_versions[cookbook_name] = "= #{version}"
104
+ end
105
+ environment.save
106
+ end
107
+
108
+
109
+ def environment
110
+ @environment ||= Environment.load(config[:environment])
74
111
  end
75
112
 
76
113
  private
77
114
 
78
- def humanize_auth_exceptions
79
- begin
80
- yield
81
- rescue Net::HTTPServerException => e
82
- case e.response.code
83
- when "401"
84
- Chef::Log.fatal "Request failed due to authentication (#{e}), check your client configuration (username, key)"
85
- exit 18
86
- else
87
- raise
88
- end
115
+ def assert_environment_valid!
116
+ environment
117
+ rescue Net::HTTPServerException => e
118
+ if e.response.code.to_s == "404"
119
+ Log.error "The environment #{config[:environment]} does not exist on the server"
120
+ Log.debug(e)
121
+ exit 1
122
+ else
123
+ raise
89
124
  end
90
125
  end
91
126
 
127
+ def upload(cookbook)
128
+ Chef::Log.info("** #{cookbook.name} **")
129
+ Chef::CookbookUploader.new(cookbook, config[:cookbook_path], :force => config[:force]).upload_cookbook
130
+ rescue Net::HTTPServerException => e
131
+ case e.response.code
132
+ when "401"
133
+ Log.error "Request failed due to authentication (#{e}), check your client configuration (username, key)"
134
+ Log.debug(e)
135
+ exit 18
136
+ when "409"
137
+ Log.error "Version #{cookbook.version} of cookbook #{cookbook.name} is frozen. Use --force to override."
138
+ Log.debug(e)
139
+ else
140
+ raise
141
+ end
142
+ end
92
143
 
93
144
  end
94
145
  end
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2009 Opscode, Inc.
3
+ # Author:: Seth Falcon (<seth@opscode.com>)
4
+ # Copyright:: Copyright (c) 2009-2010 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,37 +18,71 @@
17
18
  #
18
19
 
19
20
  require 'chef/knife'
20
- require 'chef/data_bag'
21
21
 
22
22
  class Chef
23
23
  class Knife
24
24
  class DataBagCreate < Knife
25
25
 
26
+ deps do
27
+ require 'chef/data_bag'
28
+ end
29
+
26
30
  banner "knife data bag create BAG [ITEM] (options)"
27
31
  category "data bag"
28
32
 
33
+ option :secret,
34
+ :short => "-s SECRET",
35
+ :long => "--secret ",
36
+ :description => "The secret key to use to encrypt data bag item values"
37
+
38
+ option :secret_file,
39
+ :long => "--secret_file SECRET_FILE",
40
+ :description => "A file containing the secret key to use to encrypt data bag item values"
41
+
42
+ def read_secret
43
+ if config[:secret]
44
+ config[:secret]
45
+ else
46
+ Chef::EncryptedDataBagItem.load_secret(config[:secret_file])
47
+ end
48
+ end
49
+
50
+ def use_encryption
51
+ if config[:secret] && config[:secret_file]
52
+ stdout.puts "please specify only one of --secret, --secret_file"
53
+ exit(1)
54
+ end
55
+ config[:secret] || config[:secret_file]
56
+ end
57
+
29
58
  def run
30
59
  @data_bag_name, @data_bag_item_name = @name_args
31
60
 
32
61
  if @data_bag_name.nil?
33
62
  show_usage
34
- Chef::Log.fatal("You must specify a data bag name")
63
+ stdout.puts("You must specify a data bag name")
35
64
  exit 1
36
65
  end
37
66
 
38
67
  # create the data bag
39
68
  begin
40
69
  rest.post_rest("data", { "name" => @data_bag_name })
41
- Chef::Log.info("Created data_bag[#{@data_bag_name}]")
70
+ ui.info("Created data_bag[#{@data_bag_name}]")
42
71
  rescue Net::HTTPServerException => e
43
72
  raise unless e.to_s =~ /^409/
44
- Chef::Log.info("Data bag #{@data_bag_name} already exists")
73
+ ui.info("Data bag #{@data_bag_name} already exists")
45
74
  end
46
75
 
47
76
  # if an item is specified, create it, as well
48
77
  if @data_bag_item_name
49
78
  create_object({ "id" => @data_bag_item_name }, "data_bag_item[#{@data_bag_item_name}]") do |output|
50
- rest.post_rest("data/#{@data_bag_name}", output)
79
+ item = if use_encryption
80
+ Chef::EncryptedDataBagItem.encrypt_data_bag_item(output,
81
+ read_secret)
82
+ else
83
+ output
84
+ end
85
+ rest.post_rest("data/#{@data_bag_name}", item)
51
86
  end
52
87
  end
53
88
  end