chef 0.10.8 → 0.10.10.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. data/distro/arch/etc/rc.d/chef-client +15 -1
  2. data/distro/common/html/chef-client.8.html +4 -4
  3. data/distro/common/html/chef-expander.8.html +4 -4
  4. data/distro/common/html/chef-expanderctl.8.html +4 -4
  5. data/distro/common/html/chef-server-webui.8.html +4 -4
  6. data/distro/common/html/chef-server.8.html +4 -4
  7. data/distro/common/html/chef-solo.8.html +4 -4
  8. data/distro/common/html/chef-solr.8.html +4 -4
  9. data/distro/common/html/knife-bootstrap.1.html +6 -10
  10. data/distro/common/html/knife-client.1.html +4 -4
  11. data/distro/common/html/knife-configure.1.html +4 -4
  12. data/distro/common/html/knife-cookbook-site.1.html +6 -6
  13. data/distro/common/html/knife-cookbook.1.html +4 -4
  14. data/distro/common/html/knife-data-bag.1.html +4 -4
  15. data/distro/common/html/knife-environment.1.html +4 -4
  16. data/distro/common/html/knife-exec.1.html +4 -4
  17. data/distro/common/html/knife-index.1.html +4 -4
  18. data/distro/common/html/knife-node.1.html +5 -5
  19. data/distro/common/html/knife-role.1.html +4 -4
  20. data/distro/common/html/knife-search.1.html +4 -4
  21. data/distro/common/html/knife-ssh.1.html +5 -6
  22. data/distro/common/html/knife-status.1.html +4 -4
  23. data/distro/common/html/knife-tag.1.html +4 -4
  24. data/distro/common/html/knife.1.html +7 -8
  25. data/distro/common/html/shef.1.html +4 -4
  26. data/distro/common/man/man1/knife-bootstrap.1 +4 -4
  27. data/distro/common/man/man1/knife-client.1 +1 -1
  28. data/distro/common/man/man1/knife-configure.1 +1 -1
  29. data/distro/common/man/man1/knife-cookbook-site.1 +4 -4
  30. data/distro/common/man/man1/knife-cookbook.1 +1 -1
  31. data/distro/common/man/man1/knife-data-bag.1 +1 -1
  32. data/distro/common/man/man1/knife-environment.1 +1 -1
  33. data/distro/common/man/man1/knife-exec.1 +1 -1
  34. data/distro/common/man/man1/knife-index.1 +1 -1
  35. data/distro/common/man/man1/knife-node.1 +2 -2
  36. data/distro/common/man/man1/knife-role.1 +1 -1
  37. data/distro/common/man/man1/knife-search.1 +1 -1
  38. data/distro/common/man/man1/knife-ssh.1 +3 -7
  39. data/distro/common/man/man1/knife-status.1 +1 -1
  40. data/distro/common/man/man1/knife-tag.1 +1 -1
  41. data/distro/common/man/man1/knife.1 +5 -9
  42. data/distro/common/man/man1/shef.1 +1 -1
  43. data/distro/common/man/man8/chef-client.8 +1 -1
  44. data/distro/common/man/man8/chef-expander.8 +1 -1
  45. data/distro/common/man/man8/chef-expanderctl.8 +1 -1
  46. data/distro/common/man/man8/chef-server-webui.8 +1 -1
  47. data/distro/common/man/man8/chef-server.8 +1 -1
  48. data/distro/common/man/man8/chef-solo.8 +1 -1
  49. data/distro/common/man/man8/chef-solr.8 +1 -1
  50. data/distro/common/markdown/man1/knife-bootstrap.mkd +3 -7
  51. data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
  52. data/distro/common/markdown/man1/knife-node.mkd +2 -2
  53. data/distro/common/markdown/man1/knife-ssh.mkd +2 -5
  54. data/distro/common/markdown/man1/knife.mkd +7 -9
  55. data/distro/debian/etc/init.d/chef-client +22 -1
  56. data/distro/redhat/etc/init.d/chef-client +12 -1
  57. data/distro/windows/service_manager.rb +164 -0
  58. data/lib/chef/application.rb +12 -6
  59. data/lib/chef/application/client.rb +4 -3
  60. data/lib/chef/application/knife.rb +7 -12
  61. data/lib/chef/application/solo.rb +2 -1
  62. data/lib/chef/application/windows_service.rb +224 -0
  63. data/lib/chef/checksum_cache.rb +1 -0
  64. data/lib/chef/client.rb +3 -16
  65. data/lib/chef/config.rb +42 -13
  66. data/lib/chef/cookbook/metadata.rb +1 -1
  67. data/lib/chef/cookbook/syntax_check.rb +2 -2
  68. data/lib/chef/cookbook_version.rb +5 -0
  69. data/lib/chef/daemon.rb +1 -1
  70. data/lib/chef/exceptions.rb +7 -1
  71. data/lib/chef/file_access_control.rb +13 -87
  72. data/lib/chef/file_access_control/unix.rb +119 -0
  73. data/lib/chef/file_access_control/windows.rb +257 -0
  74. data/lib/chef/handler/json_file.rb +7 -1
  75. data/lib/chef/knife.rb +10 -16
  76. data/lib/chef/knife/bootstrap.rb +15 -8
  77. data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
  78. data/lib/chef/knife/bootstrap/chef-full.erb +59 -0
  79. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -0
  80. data/lib/chef/knife/configure.rb +2 -2
  81. data/lib/chef/knife/cookbook_site_download.rb +60 -21
  82. data/lib/chef/knife/cookbook_site_install.rb +16 -21
  83. data/lib/chef/knife/cookbook_upload.rb +77 -48
  84. data/lib/chef/knife/core/bootstrap_context.rb +3 -1
  85. data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
  86. data/lib/chef/knife/core/node_editor.rb +1 -1
  87. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  88. data/lib/chef/knife/core/ui.rb +3 -2
  89. data/lib/chef/knife/help_topics.rb +1 -1
  90. data/lib/chef/knife/node_run_list_add.rb +14 -6
  91. data/lib/chef/knife/node_run_list_remove.rb +3 -3
  92. data/lib/chef/knife/ssh.rb +32 -13
  93. data/lib/chef/mash.rb +14 -0
  94. data/lib/chef/mixin/command.rb +1 -0
  95. data/lib/chef/mixin/command/unix.rb +5 -0
  96. data/lib/chef/mixin/convert_to_class_name.rb +2 -0
  97. data/lib/chef/mixin/deep_merge.rb +40 -18
  98. data/lib/chef/mixin/enforce_ownership_and_permissions.rb +39 -0
  99. data/lib/chef/mixin/language.rb +89 -3
  100. data/lib/chef/mixin/language_include_recipe.rb +8 -4
  101. data/lib/chef/mixin/path_sanity.rb +67 -0
  102. data/lib/chef/mixin/recipe_definition_dsl_core.rb +19 -11
  103. data/lib/chef/mixin/securable.rb +152 -0
  104. data/lib/chef/mixin/shell_out.rb +1 -1
  105. data/lib/chef/mixin/template.rb +8 -3
  106. data/lib/chef/mixins.rb +3 -0
  107. data/lib/chef/monkey_patches/moneta.rb +50 -0
  108. data/lib/chef/monkey_patches/string.rb +1 -1
  109. data/lib/chef/node.rb +2 -1
  110. data/lib/chef/platform.rb +34 -0
  111. data/lib/chef/provider.rb +23 -21
  112. data/lib/chef/provider/cron.rb +17 -12
  113. data/lib/chef/provider/cron/solaris.rb +6 -18
  114. data/lib/chef/provider/deploy.rb +14 -15
  115. data/lib/chef/provider/deploy/timestamped.rb +0 -1
  116. data/lib/chef/provider/directory.rb +1 -3
  117. data/lib/chef/provider/execute.rb +2 -2
  118. data/lib/chef/provider/file.rb +1 -75
  119. data/lib/chef/provider/git.rb +11 -9
  120. data/lib/chef/provider/group/gpasswd.rb +14 -9
  121. data/lib/chef/provider/link.rb +28 -59
  122. data/lib/chef/provider/mdadm.rb +2 -2
  123. data/lib/chef/provider/mount/mount.rb +1 -1
  124. data/lib/chef/provider/package.rb +10 -6
  125. data/lib/chef/provider/package/apt.rb +3 -1
  126. data/lib/chef/provider/package/dpkg.rb +1 -1
  127. data/lib/chef/provider/package/portage.rb +6 -3
  128. data/lib/chef/provider/package/rubygems.rb +75 -6
  129. data/lib/chef/provider/package/smartos.rb +84 -0
  130. data/lib/chef/provider/package/yum-dump.py +3 -2
  131. data/lib/chef/provider/package/yum.rb +51 -10
  132. data/lib/chef/provider/remote_directory.rb +24 -3
  133. data/lib/chef/provider/remote_file.rb +0 -6
  134. data/lib/chef/provider/route.rb +3 -3
  135. data/lib/chef/provider/service/debian.rb +2 -2
  136. data/lib/chef/provider/service/freebsd.rb +1 -1
  137. data/lib/chef/provider/service/macosx.rb +125 -0
  138. data/lib/chef/provider/service/windows.rb +5 -1
  139. data/lib/chef/provider/subversion.rb +10 -7
  140. data/lib/chef/providers.rb +3 -0
  141. data/lib/chef/resource.rb +181 -87
  142. data/lib/chef/resource/apt_package.rb +10 -1
  143. data/lib/chef/resource/chef_gem.rb +53 -0
  144. data/lib/chef/resource/conditional.rb +3 -0
  145. data/lib/chef/resource/cookbook_file.rb +12 -6
  146. data/lib/chef/resource/cron.rb +9 -0
  147. data/lib/chef/resource/directory.rb +14 -31
  148. data/lib/chef/resource/execute.rb +11 -9
  149. data/lib/chef/resource/file.rb +9 -33
  150. data/lib/chef/resource/link.rb +13 -8
  151. data/lib/chef/resource/mdadm.rb +10 -1
  152. data/lib/chef/resource/remote_directory.rb +13 -2
  153. data/lib/chef/resource/remote_file.rb +14 -7
  154. data/lib/chef/resource/smartos_package.rb +36 -0
  155. data/lib/chef/resource/template.rb +12 -5
  156. data/lib/chef/resource_platform_map.rb +153 -0
  157. data/lib/chef/resources.rb +2 -0
  158. data/lib/chef/rest.rb +55 -10
  159. data/lib/chef/rest/auth_credentials.rb +1 -0
  160. data/lib/chef/rest/rest_request.rb +24 -8
  161. data/lib/chef/role.rb +8 -2
  162. data/lib/chef/run_list.rb +1 -1
  163. data/lib/chef/run_list/run_list_expansion.rb +2 -2
  164. data/lib/chef/run_list/run_list_item.rb +7 -0
  165. data/lib/chef/runner.rb +4 -0
  166. data/lib/chef/shef.rb +2 -2
  167. data/lib/chef/shef/shef_session.rb +4 -5
  168. data/lib/chef/shell_out.rb +2 -245
  169. data/lib/chef/util/file_edit.rb +99 -89
  170. data/lib/chef/version.rb +1 -1
  171. data/lib/chef/win32/api.rb +349 -0
  172. data/lib/chef/win32/api/error.rb +921 -0
  173. data/lib/chef/win32/api/file.rb +289 -0
  174. data/lib/chef/win32/api/memory.rb +105 -0
  175. data/lib/chef/win32/api/process.rb +40 -0
  176. data/lib/chef/win32/api/psapi.rb +51 -0
  177. data/lib/chef/win32/api/security.rb +341 -0
  178. data/lib/chef/win32/api/system.rb +192 -0
  179. data/lib/chef/win32/api/unicode.rb +178 -0
  180. data/lib/chef/win32/error.rb +73 -0
  181. data/lib/chef/win32/file.rb +117 -0
  182. data/lib/chef/win32/file/info.rb +100 -0
  183. data/lib/chef/win32/handle.rb +48 -0
  184. data/lib/chef/win32/memory.rb +101 -0
  185. data/lib/chef/win32/process.rb +84 -0
  186. data/lib/chef/win32/security.rb +489 -0
  187. data/lib/chef/win32/security/ace.rb +125 -0
  188. data/lib/chef/win32/security/acl.rb +101 -0
  189. data/lib/chef/win32/security/securable_object.rb +109 -0
  190. data/lib/chef/win32/security/security_descriptor.rb +93 -0
  191. data/lib/chef/win32/security/sid.rb +199 -0
  192. data/lib/chef/win32/security/token.rb +64 -0
  193. data/lib/chef/win32/unicode.rb +43 -0
  194. data/lib/chef/win32/version.rb +119 -0
  195. metadata +104 -158
  196. data/lib/chef/shell_out/unix.rb +0 -223
  197. data/lib/chef/shell_out/windows.rb +0 -588
@@ -21,7 +21,7 @@ require 'chef/resource'
21
21
  class Chef
22
22
  class Resource
23
23
  class Mdadm < Chef::Resource
24
-
24
+
25
25
  def initialize(name, run_context=nil)
26
26
  super
27
27
  @resource_name = :mdadm
@@ -30,6 +30,7 @@ class Chef
30
30
  @devices = []
31
31
  @exists = false
32
32
  @level = 1
33
+ @metadata = "0.90"
33
34
  @raid_device = name
34
35
 
35
36
  @action = :create
@@ -68,6 +69,14 @@ class Chef
68
69
  )
69
70
  end
70
71
 
72
+ def metadata(arg=nil)
73
+ set_or_return(
74
+ :metadata,
75
+ arg,
76
+ :kind_of => [ String ]
77
+ )
78
+ end
79
+
71
80
  def raid_device(arg=nil)
72
81
  set_or_return(
73
82
  :raid_device,
@@ -17,11 +17,16 @@
17
17
  #
18
18
 
19
19
  require 'chef/resource/directory'
20
+ require 'chef/provider/remote_directory'
21
+ require 'chef/mixin/securable'
20
22
 
21
23
  class Chef
22
24
  class Resource
23
25
  class RemoteDirectory < Chef::Resource::Directory
24
-
26
+ include Chef::Mixin::Securable
27
+
28
+ provides :remote_directory, :on_platforms => :all
29
+
25
30
  def initialize(name, run_context=nil)
26
31
  super
27
32
  @resource_name = :remote_directory
@@ -34,10 +39,11 @@ class Chef
34
39
  @files_backup = 5
35
40
  @files_owner = nil
36
41
  @files_group = nil
37
- @files_mode = 0644
42
+ @files_mode = 0644 unless Chef::Platform.windows?
38
43
  @overwrite = true
39
44
  @allowed_actions.push(:create, :create_if_missing, :delete)
40
45
  @cookbook = nil
46
+ @provider = Chef::Provider::RemoteDirectory
41
47
  end
42
48
 
43
49
  def source(args=nil)
@@ -72,6 +78,11 @@ class Chef
72
78
  )
73
79
  end
74
80
 
81
+ if Chef::Platform.windows?
82
+ # create a second instance of the 'rights' attribute
83
+ Chef::Mixin::Securable.rights_attribute(:files_rights)
84
+ end
85
+
75
86
  def files_mode(arg=nil)
76
87
  set_or_return(
77
88
  :files_mode,
@@ -1,14 +1,15 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
3
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
4
+ # Copyright:: Copyright (c) 2008, 2011 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
7
8
  # you may not use this file except in compliance with the License.
8
9
  # You may obtain a copy of the License at
9
- #
10
+ #
10
11
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
+ #
12
13
  # Unless required by applicable law or agreed to in writing, software
13
14
  # distributed under the License is distributed on an "AS IS" BASIS,
14
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,19 +18,25 @@
17
18
  #
18
19
 
19
20
  require 'chef/resource/file'
21
+ require 'chef/provider/remote_file'
22
+ require 'chef/mixin/securable'
20
23
 
21
24
  class Chef
22
25
  class Resource
23
26
  class RemoteFile < Chef::Resource::File
24
-
27
+ include Chef::Mixin::Securable
28
+
29
+ provides :remote_file, :on_platforms => :all
30
+
25
31
  def initialize(name, run_context=nil)
26
32
  super
27
33
  @resource_name = :remote_file
28
34
  @action = "create"
29
35
  @source = ::File.basename(name)
30
36
  @cookbook = nil
37
+ @provider = Chef::Provider::RemoteFile
31
38
  end
32
-
39
+
33
40
  def source(args=nil)
34
41
  set_or_return(
35
42
  :source,
@@ -37,7 +44,7 @@ class Chef
37
44
  :kind_of => String
38
45
  )
39
46
  end
40
-
47
+
41
48
  def cookbook(args=nil)
42
49
  set_or_return(
43
50
  :cookbook,
@@ -71,7 +78,7 @@ class Chef
71
78
  end
72
79
 
73
80
  private
74
-
81
+
75
82
  def absolute_uri?(source)
76
83
  URI.parse(source).absolute?
77
84
  rescue URI::InvalidURIError
@@ -0,0 +1,36 @@
1
+ #
2
+ # Author:: Toomas Pelberg (<toomasp@gmx.net>)
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/resource/package'
20
+ require 'chef/provider/package/smartos'
21
+
22
+ class Chef
23
+ class Resource
24
+ class SmartOSPackage < Chef::Resource::Package
25
+
26
+ def initialize(name, run_context=nil)
27
+ super
28
+ @resource_name = :smartos_package
29
+ @provider = Chef::Provider::Package::SmartOS
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+
36
+
@@ -1,14 +1,15 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
3
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
4
+ # Copyright:: Copyright (c) 2008, 2011 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
6
7
  # Licensed under the Apache License, Version 2.0 (the "License");
7
8
  # you may not use this file except in compliance with the License.
8
9
  # You may obtain a copy of the License at
9
- #
10
+ #
10
11
  # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
+ #
12
13
  # Unless required by applicable law or agreed to in writing, software
13
14
  # distributed under the License is distributed on an "AS IS" BASIS,
14
15
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,11 +18,16 @@
17
18
  #
18
19
 
19
20
  require 'chef/resource/file'
21
+ require 'chef/provider/template'
22
+ require 'chef/mixin/securable'
20
23
 
21
24
  class Chef
22
25
  class Resource
23
26
  class Template < Chef::Resource::File
24
-
27
+ include Chef::Mixin::Securable
28
+
29
+ provides :template, :on_platforms => :all
30
+
25
31
  def initialize(name, run_context=nil)
26
32
  super
27
33
  @resource_name = :template
@@ -30,6 +36,7 @@ class Chef
30
36
  @cookbook = nil
31
37
  @local = false
32
38
  @variables = Hash.new
39
+ @provider = Chef::Provider::Template
33
40
  end
34
41
 
35
42
  def source(file=nil)
@@ -47,7 +54,7 @@ class Chef
47
54
  :kind_of => [ Hash ]
48
55
  )
49
56
  end
50
-
57
+
51
58
  def cookbook(args=nil)
52
59
  set_or_return(
53
60
  :cookbook,
@@ -0,0 +1,153 @@
1
+ #
2
+ # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
+ # Copyright:: Copyright (c) 2011 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/mixin/params_validate'
20
+ require 'chef/mixin/convert_to_class_name'
21
+
22
+ class Chef
23
+ class Resource
24
+ class PlatformMap
25
+
26
+ include Chef::Mixin::ParamsValidate
27
+ include Chef::Mixin::ConvertToClassName
28
+
29
+ attr_reader :map
30
+
31
+ def initialize(map={:default => {}})
32
+ @map = map
33
+ end
34
+
35
+ def filter(platform, version)
36
+ resource_map = map[:default].clone
37
+ platform_sym = platform
38
+ if platform.kind_of?(String)
39
+ platform.downcase!
40
+ platform.gsub!(/\s/, "_")
41
+ platform_sym = platform.to_sym
42
+ end
43
+
44
+ if map.has_key?(platform_sym)
45
+ if map[platform_sym].has_key?(version)
46
+ Chef::Log.debug("Platform #{platform_sym} version #{version} found")
47
+ if map[platform_sym].has_key?(:default)
48
+ resource_map.merge!(map[platform_sym][:default])
49
+ end
50
+ resource_map.merge!(map[platform_sym][version])
51
+ elsif map[platform_sym].has_key?(:default)
52
+ resource_map.merge!(map[platform_sym][:default])
53
+ end
54
+ else
55
+ Chef::Log.debug("Platform #{platform} not found, using all defaults. (Unsupported platform?)")
56
+ end
57
+ resource_map
58
+ end
59
+
60
+ def set(args)
61
+ validate(
62
+ args,
63
+ {
64
+ :platform => {
65
+ :kind_of => Symbol,
66
+ :required => false
67
+ },
68
+ :version => {
69
+ :kind_of => String,
70
+ :required => false
71
+ },
72
+ :short_name => {
73
+ :kind_of => Symbol,
74
+ :required => true
75
+ },
76
+ :resource => {
77
+ :kind_of => [ String, Symbol, Class ],
78
+ :required => true
79
+ }
80
+ }
81
+ )
82
+ if args.has_key?(:platform)
83
+ if args.has_key?(:version)
84
+ if map.has_key?(args[:platform])
85
+ if map[args[:platform]].has_key?(args[:version])
86
+ map[args[:platform]][args[:version]][args[:short_name].to_sym] = args[:resource]
87
+ else
88
+ map[args[:platform]][args[:version]] = {
89
+ args[:short_name].to_sym => args[:resource]
90
+ }
91
+ end
92
+ else
93
+ map[args[:platform]] = {
94
+ args[:version] => {
95
+ args[:short_name].to_sym => args[:resource]
96
+ }
97
+ }
98
+ end
99
+ else
100
+ if map.has_key?(args[:platform])
101
+ if map[args[:platform]].has_key?(:default)
102
+ map[args[:platform]][:default][args[:short_name].to_sym] = args[:resource]
103
+ else
104
+ map[args[:platform]] = { :default => { args[:short_name].to_sym => args[:resource] } }
105
+ end
106
+ else
107
+ map[args[:platform]] = {
108
+ :default => {
109
+ args[:short_name].to_sym => args[:resource]
110
+ }
111
+ }
112
+ end
113
+ end
114
+ else
115
+ if map.has_key?(:default)
116
+ map[:default][args[:short_name].to_sym] = args[:resource]
117
+ else
118
+ map[:default] = {
119
+ args[:short_name].to_sym => args[:resource]
120
+ }
121
+ end
122
+ end
123
+ end
124
+
125
+ def get(short_name, platform=nil, version=nil)
126
+ resource_klass = platform_resource(short_name, platform, version) ||
127
+ resource_matching_short_name(short_name)
128
+
129
+ raise NameError, "Cannot find a resource for #{short_name} on #{platform} version #{version}" if resource_klass.nil?
130
+
131
+ resource_klass
132
+ end
133
+
134
+ private
135
+
136
+ def platform_resource(short_name, platform, version)
137
+ pmap = filter(platform, version)
138
+ rtkey = short_name.kind_of?(Chef::Resource) ? short_name.resource_name.to_sym : short_name
139
+ pmap.has_key?(rtkey) ? pmap[rtkey] : nil
140
+ end
141
+
142
+ def resource_matching_short_name(short_name)
143
+ begin
144
+ rname = convert_to_class_name(short_name.to_s)
145
+ Chef::Resource.const_get(rname)
146
+ rescue NameError
147
+ nil
148
+ end
149
+ end
150
+
151
+ end
152
+ end
153
+ end
@@ -20,6 +20,7 @@ require 'chef/resource/apt_package'
20
20
  require 'chef/resource/bash'
21
21
  require 'chef/resource/breakpoint'
22
22
  require 'chef/resource/cookbook_file'
23
+ require 'chef/resource/chef_gem'
23
24
  require 'chef/resource/cron'
24
25
  require 'chef/resource/csh'
25
26
  require 'chef/resource/deploy'
@@ -58,6 +59,7 @@ require 'chef/resource/scm'
58
59
  require 'chef/resource/script'
59
60
  require 'chef/resource/service'
60
61
  require 'chef/resource/subversion'
62
+ require 'chef/resource/smartos_package'
61
63
  require 'chef/resource/template'
62
64
  require 'chef/resource/timestamped_deploy'
63
65
  require 'chef/resource/user'
@@ -20,6 +20,7 @@
20
20
  # limitations under the License.
21
21
  #
22
22
 
23
+ require 'zlib'
23
24
  require 'net/https'
24
25
  require 'uri'
25
26
  require 'chef/json_compat'
@@ -27,15 +28,28 @@ require 'tempfile'
27
28
  require 'chef/rest/auth_credentials'
28
29
  require 'chef/rest/rest_request'
29
30
  require 'chef/monkey_patches/string'
31
+ require 'chef/config'
30
32
 
31
33
  class Chef
32
34
  # == Chef::REST
33
35
  # Chef's custom REST client with built-in JSON support and RSA signed header
34
36
  # authentication.
35
37
  class REST
38
+
39
+ class NoopInflater
40
+ def inflate(chunk)
41
+ chunk
42
+ end
43
+ end
44
+
36
45
  attr_reader :auth_credentials
37
46
  attr_accessor :url, :cookies, :sign_on_redirect, :redirect_limit
38
47
 
48
+ CONTENT_ENCODING = "content-encoding".freeze
49
+ GZIP = "gzip".freeze
50
+ DEFLATE = "deflate".freeze
51
+ IDENTITY = "identity".freeze
52
+
39
53
  # Create a REST client object. The supplied +url+ is used as the base for
40
54
  # all subsequent requests. For example, when initialized with a base url
41
55
  # http://localhost:4000, a call to +get_rest+ with 'nodes' will make an
@@ -173,7 +187,7 @@ class Chef
173
187
  json_body.force_encoding(Encoding::BINARY) if json_body.respond_to?(:force_encoding)
174
188
  headers = build_headers(method, url, headers, json_body, raw)
175
189
 
176
- tf = nil
190
+ tf, response_body = nil, nil
177
191
 
178
192
  retriable_rest_request(method, url, json_body, headers) do |rest_request|
179
193
 
@@ -181,13 +195,12 @@ class Chef
181
195
  if raw
182
196
  tf = stream_to_tempfile(url, response)
183
197
  else
184
- response.read_body
198
+ response_body = decompress_body(response)
185
199
  end
186
200
  end
187
201
 
188
202
  if res.kind_of?(Net::HTTPSuccess)
189
203
  if res['content-type'] =~ /json/
190
- response_body = res.body.chomp
191
204
  Chef::JSONCompat.from_json(response_body)
192
205
  else
193
206
  if method == :HEAD
@@ -195,7 +208,7 @@ class Chef
195
208
  elsif raw
196
209
  tf
197
210
  else
198
- res.body
211
+ response_body
199
212
  end
200
213
  end
201
214
  elsif res.kind_of?(Net::HTTPFound) or res.kind_of?(Net::HTTPMovedPermanently)
@@ -204,7 +217,7 @@ class Chef
204
217
  false
205
218
  else
206
219
  if res['content-type'] =~ /json/
207
- exception = Chef::JSONCompat.from_json(res.body)
220
+ exception = Chef::JSONCompat.from_json(response_body)
208
221
  msg = "HTTP Request Returned #{res.code} #{res.message}: "
209
222
  msg << (exception["error"].respond_to?(:join) ? exception["error"].join(", ") : exception["error"].to_s)
210
223
  Chef::Log.warn(msg)
@@ -226,18 +239,23 @@ class Chef
226
239
  retriable_rest_request(method, url, json_body, headers) do |rest_request|
227
240
  response = rest_request.call {|r| r.read_body}
228
241
 
242
+ response_body = decompress_body(response)
243
+
229
244
  if response.kind_of?(Net::HTTPSuccess)
230
245
  if response['content-type'] =~ /json/
231
- Chef::JSONCompat.from_json(response.body.chomp)
246
+ Chef::JSONCompat.from_json(response_body.chomp)
232
247
  else
233
248
  Chef::Log.warn("Expected JSON response, but got content-type '#{response['content-type']}'")
234
- response.body
249
+ response_body
235
250
  end
236
251
  elsif redirect_location = redirected_to(response)
237
252
  follow_redirect {api_request(:GET, create_url(redirect_location))}
238
253
  else
254
+ # have to decompress the body before making an exception for it. But the body could be nil.
255
+ response.body.replace(decompress_body(response)) if response.body.respond_to?(:replace)
256
+
239
257
  if response['content-type'] =~ /json/
240
- exception = Chef::JSONCompat.from_json(response.body)
258
+ exception = Chef::JSONCompat.from_json(response_body)
241
259
  msg = "HTTP Request Returned #{response.code} #{response.message}: "
242
260
  msg << (exception["error"].respond_to?(:join) ? exception["error"].join(", ") : exception["error"].to_s)
243
261
  Chef::Log.info(msg)
@@ -247,6 +265,19 @@ class Chef
247
265
  end
248
266
  end
249
267
 
268
+ def decompress_body(response)
269
+ case response[CONTENT_ENCODING]
270
+ when GZIP
271
+ Chef::Log.debug "decompressing gzip response"
272
+ Zlib::Inflate.new(Zlib::MAX_WBITS + 16).inflate(response.body)
273
+ when DEFLATE
274
+ Chef::Log.debug "decompressing deflate response"
275
+ Zlib::Inflate.inflate(response.body)
276
+ else
277
+ response.body
278
+ end
279
+ end
280
+
250
281
  # Makes a streaming download request. <b>Doesn't speak JSON.</b>
251
282
  # Streams the response body to a tempfile. If a block is given, it's
252
283
  # passed to Tempfile.open(), which means that the tempfile will automatically
@@ -368,9 +399,11 @@ class Chef
368
399
 
369
400
  def build_headers(method, url, headers={}, json_body=false, raw=false)
370
401
  headers = @default_headers.merge(headers)
402
+ #headers['Accept'] = "application/json" unless raw
371
403
  headers['Accept'] = "application/json" unless raw
372
404
  headers["Content-Type"] = 'application/json' if json_body
373
405
  headers['Content-Length'] = json_body.bytesize.to_s if json_body
406
+ headers[RESTRequest::ACCEPT_ENCODING] = RESTRequest::ENCODING_GZIP_DEFLATE
374
407
  headers.merge!(authentication_headers(method, url, json_body)) if sign_requests?
375
408
  headers.merge!(Chef::Config[:custom_http_headers]) if Chef::Config[:custom_http_headers]
376
409
  headers
@@ -378,15 +411,27 @@ class Chef
378
411
 
379
412
  def stream_to_tempfile(url, response)
380
413
  tf = Tempfile.open("chef-rest")
381
- if RUBY_PLATFORM =~ /mswin|mingw32|windows/
414
+ if Chef::Platform.windows?
382
415
  tf.binmode #required for binary files on Windows platforms
383
416
  end
384
417
  Chef::Log.debug("Streaming download from #{url.to_s} to tempfile #{tf.path}")
385
418
  # Stolen from http://www.ruby-forum.com/topic/166423
386
419
  # Kudos to _why!
387
420
  size, total = 0, response.header['Content-Length'].to_i
421
+
422
+ inflater = case response[CONTENT_ENCODING]
423
+ when GZIP
424
+ Chef::Log.debug "decompressing gzip stream"
425
+ Zlib::Inflate.new(Zlib::MAX_WBITS + 16)
426
+ when DEFLATE
427
+ Chef::Log.debug "decompressing inflate stream"
428
+ Zlib::Inflate.new
429
+ else
430
+ NoopInflater.new
431
+ end
432
+
388
433
  response.read_body do |chunk|
389
- tf.write(chunk)
434
+ tf.write(inflater.inflate(chunk))
390
435
  size += chunk.size
391
436
  end
392
437
  tf.close