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.
- data/distro/arch/etc/rc.d/chef-client +15 -1
- data/distro/common/html/chef-client.8.html +4 -4
- data/distro/common/html/chef-expander.8.html +4 -4
- data/distro/common/html/chef-expanderctl.8.html +4 -4
- data/distro/common/html/chef-server-webui.8.html +4 -4
- data/distro/common/html/chef-server.8.html +4 -4
- data/distro/common/html/chef-solo.8.html +4 -4
- data/distro/common/html/chef-solr.8.html +4 -4
- data/distro/common/html/knife-bootstrap.1.html +6 -10
- data/distro/common/html/knife-client.1.html +4 -4
- data/distro/common/html/knife-configure.1.html +4 -4
- data/distro/common/html/knife-cookbook-site.1.html +6 -6
- data/distro/common/html/knife-cookbook.1.html +4 -4
- data/distro/common/html/knife-data-bag.1.html +4 -4
- data/distro/common/html/knife-environment.1.html +4 -4
- data/distro/common/html/knife-exec.1.html +4 -4
- data/distro/common/html/knife-index.1.html +4 -4
- data/distro/common/html/knife-node.1.html +5 -5
- data/distro/common/html/knife-role.1.html +4 -4
- data/distro/common/html/knife-search.1.html +4 -4
- data/distro/common/html/knife-ssh.1.html +5 -6
- data/distro/common/html/knife-status.1.html +4 -4
- data/distro/common/html/knife-tag.1.html +4 -4
- data/distro/common/html/knife.1.html +7 -8
- data/distro/common/html/shef.1.html +4 -4
- data/distro/common/man/man1/knife-bootstrap.1 +4 -4
- data/distro/common/man/man1/knife-client.1 +1 -1
- data/distro/common/man/man1/knife-configure.1 +1 -1
- data/distro/common/man/man1/knife-cookbook-site.1 +4 -4
- data/distro/common/man/man1/knife-cookbook.1 +1 -1
- data/distro/common/man/man1/knife-data-bag.1 +1 -1
- data/distro/common/man/man1/knife-environment.1 +1 -1
- data/distro/common/man/man1/knife-exec.1 +1 -1
- data/distro/common/man/man1/knife-index.1 +1 -1
- data/distro/common/man/man1/knife-node.1 +2 -2
- data/distro/common/man/man1/knife-role.1 +1 -1
- data/distro/common/man/man1/knife-search.1 +1 -1
- data/distro/common/man/man1/knife-ssh.1 +3 -7
- data/distro/common/man/man1/knife-status.1 +1 -1
- data/distro/common/man/man1/knife-tag.1 +1 -1
- data/distro/common/man/man1/knife.1 +5 -9
- data/distro/common/man/man1/shef.1 +1 -1
- data/distro/common/man/man8/chef-client.8 +1 -1
- data/distro/common/man/man8/chef-expander.8 +1 -1
- data/distro/common/man/man8/chef-expanderctl.8 +1 -1
- data/distro/common/man/man8/chef-server-webui.8 +1 -1
- data/distro/common/man/man8/chef-server.8 +1 -1
- data/distro/common/man/man8/chef-solo.8 +1 -1
- data/distro/common/man/man8/chef-solr.8 +1 -1
- data/distro/common/markdown/man1/knife-bootstrap.mkd +3 -7
- data/distro/common/markdown/man1/knife-cookbook-site.mkd +3 -3
- data/distro/common/markdown/man1/knife-node.mkd +2 -2
- data/distro/common/markdown/man1/knife-ssh.mkd +2 -5
- data/distro/common/markdown/man1/knife.mkd +7 -9
- data/distro/debian/etc/init.d/chef-client +22 -1
- data/distro/redhat/etc/init.d/chef-client +12 -1
- data/distro/windows/service_manager.rb +164 -0
- data/lib/chef/application.rb +12 -6
- data/lib/chef/application/client.rb +4 -3
- data/lib/chef/application/knife.rb +7 -12
- data/lib/chef/application/solo.rb +2 -1
- data/lib/chef/application/windows_service.rb +224 -0
- data/lib/chef/checksum_cache.rb +1 -0
- data/lib/chef/client.rb +3 -16
- data/lib/chef/config.rb +42 -13
- data/lib/chef/cookbook/metadata.rb +1 -1
- data/lib/chef/cookbook/syntax_check.rb +2 -2
- data/lib/chef/cookbook_version.rb +5 -0
- data/lib/chef/daemon.rb +1 -1
- data/lib/chef/exceptions.rb +7 -1
- data/lib/chef/file_access_control.rb +13 -87
- data/lib/chef/file_access_control/unix.rb +119 -0
- data/lib/chef/file_access_control/windows.rb +257 -0
- data/lib/chef/handler/json_file.rb +7 -1
- data/lib/chef/knife.rb +10 -16
- data/lib/chef/knife/bootstrap.rb +15 -8
- data/lib/chef/knife/bootstrap/centos5-gems.erb +1 -1
- data/lib/chef/knife/bootstrap/chef-full.erb +59 -0
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +1 -0
- data/lib/chef/knife/configure.rb +2 -2
- data/lib/chef/knife/cookbook_site_download.rb +60 -21
- data/lib/chef/knife/cookbook_site_install.rb +16 -21
- data/lib/chef/knife/cookbook_upload.rb +77 -48
- data/lib/chef/knife/core/bootstrap_context.rb +3 -1
- data/lib/chef/knife/core/cookbook_scm_repo.rb +1 -1
- data/lib/chef/knife/core/node_editor.rb +1 -1
- data/lib/chef/knife/core/subcommand_loader.rb +1 -1
- data/lib/chef/knife/core/ui.rb +3 -2
- data/lib/chef/knife/help_topics.rb +1 -1
- data/lib/chef/knife/node_run_list_add.rb +14 -6
- data/lib/chef/knife/node_run_list_remove.rb +3 -3
- data/lib/chef/knife/ssh.rb +32 -13
- data/lib/chef/mash.rb +14 -0
- data/lib/chef/mixin/command.rb +1 -0
- data/lib/chef/mixin/command/unix.rb +5 -0
- data/lib/chef/mixin/convert_to_class_name.rb +2 -0
- data/lib/chef/mixin/deep_merge.rb +40 -18
- data/lib/chef/mixin/enforce_ownership_and_permissions.rb +39 -0
- data/lib/chef/mixin/language.rb +89 -3
- data/lib/chef/mixin/language_include_recipe.rb +8 -4
- data/lib/chef/mixin/path_sanity.rb +67 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +19 -11
- data/lib/chef/mixin/securable.rb +152 -0
- data/lib/chef/mixin/shell_out.rb +1 -1
- data/lib/chef/mixin/template.rb +8 -3
- data/lib/chef/mixins.rb +3 -0
- data/lib/chef/monkey_patches/moneta.rb +50 -0
- data/lib/chef/monkey_patches/string.rb +1 -1
- data/lib/chef/node.rb +2 -1
- data/lib/chef/platform.rb +34 -0
- data/lib/chef/provider.rb +23 -21
- data/lib/chef/provider/cron.rb +17 -12
- data/lib/chef/provider/cron/solaris.rb +6 -18
- data/lib/chef/provider/deploy.rb +14 -15
- data/lib/chef/provider/deploy/timestamped.rb +0 -1
- data/lib/chef/provider/directory.rb +1 -3
- data/lib/chef/provider/execute.rb +2 -2
- data/lib/chef/provider/file.rb +1 -75
- data/lib/chef/provider/git.rb +11 -9
- data/lib/chef/provider/group/gpasswd.rb +14 -9
- data/lib/chef/provider/link.rb +28 -59
- data/lib/chef/provider/mdadm.rb +2 -2
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/package.rb +10 -6
- data/lib/chef/provider/package/apt.rb +3 -1
- data/lib/chef/provider/package/dpkg.rb +1 -1
- data/lib/chef/provider/package/portage.rb +6 -3
- data/lib/chef/provider/package/rubygems.rb +75 -6
- data/lib/chef/provider/package/smartos.rb +84 -0
- data/lib/chef/provider/package/yum-dump.py +3 -2
- data/lib/chef/provider/package/yum.rb +51 -10
- data/lib/chef/provider/remote_directory.rb +24 -3
- data/lib/chef/provider/remote_file.rb +0 -6
- data/lib/chef/provider/route.rb +3 -3
- data/lib/chef/provider/service/debian.rb +2 -2
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/macosx.rb +125 -0
- data/lib/chef/provider/service/windows.rb +5 -1
- data/lib/chef/provider/subversion.rb +10 -7
- data/lib/chef/providers.rb +3 -0
- data/lib/chef/resource.rb +181 -87
- data/lib/chef/resource/apt_package.rb +10 -1
- data/lib/chef/resource/chef_gem.rb +53 -0
- data/lib/chef/resource/conditional.rb +3 -0
- data/lib/chef/resource/cookbook_file.rb +12 -6
- data/lib/chef/resource/cron.rb +9 -0
- data/lib/chef/resource/directory.rb +14 -31
- data/lib/chef/resource/execute.rb +11 -9
- data/lib/chef/resource/file.rb +9 -33
- data/lib/chef/resource/link.rb +13 -8
- data/lib/chef/resource/mdadm.rb +10 -1
- data/lib/chef/resource/remote_directory.rb +13 -2
- data/lib/chef/resource/remote_file.rb +14 -7
- data/lib/chef/resource/smartos_package.rb +36 -0
- data/lib/chef/resource/template.rb +12 -5
- data/lib/chef/resource_platform_map.rb +153 -0
- data/lib/chef/resources.rb +2 -0
- data/lib/chef/rest.rb +55 -10
- data/lib/chef/rest/auth_credentials.rb +1 -0
- data/lib/chef/rest/rest_request.rb +24 -8
- data/lib/chef/role.rb +8 -2
- data/lib/chef/run_list.rb +1 -1
- data/lib/chef/run_list/run_list_expansion.rb +2 -2
- data/lib/chef/run_list/run_list_item.rb +7 -0
- data/lib/chef/runner.rb +4 -0
- data/lib/chef/shef.rb +2 -2
- data/lib/chef/shef/shef_session.rb +4 -5
- data/lib/chef/shell_out.rb +2 -245
- data/lib/chef/util/file_edit.rb +99 -89
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api.rb +349 -0
- data/lib/chef/win32/api/error.rb +921 -0
- data/lib/chef/win32/api/file.rb +289 -0
- data/lib/chef/win32/api/memory.rb +105 -0
- data/lib/chef/win32/api/process.rb +40 -0
- data/lib/chef/win32/api/psapi.rb +51 -0
- data/lib/chef/win32/api/security.rb +341 -0
- data/lib/chef/win32/api/system.rb +192 -0
- data/lib/chef/win32/api/unicode.rb +178 -0
- data/lib/chef/win32/error.rb +73 -0
- data/lib/chef/win32/file.rb +117 -0
- data/lib/chef/win32/file/info.rb +100 -0
- data/lib/chef/win32/handle.rb +48 -0
- data/lib/chef/win32/memory.rb +101 -0
- data/lib/chef/win32/process.rb +84 -0
- data/lib/chef/win32/security.rb +489 -0
- data/lib/chef/win32/security/ace.rb +125 -0
- data/lib/chef/win32/security/acl.rb +101 -0
- data/lib/chef/win32/security/securable_object.rb +109 -0
- data/lib/chef/win32/security/security_descriptor.rb +93 -0
- data/lib/chef/win32/security/sid.rb +199 -0
- data/lib/chef/win32/security/token.rb +64 -0
- data/lib/chef/win32/unicode.rb +43 -0
- data/lib/chef/win32/version.rb +119 -0
- metadata +104 -158
- data/lib/chef/shell_out/unix.rb +0 -223
- data/lib/chef/shell_out/windows.rb +0 -588
data/lib/chef/mixin/language.rb
CHANGED
@@ -93,6 +93,8 @@ class Chef
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
|
97
|
+
|
96
98
|
# Given a hash similar to the one we use for Platforms, select a value from the hash. Supports
|
97
99
|
# per platform defaults, along with a single base default. Arrays may be passed as hash keys and
|
98
100
|
# will be expanded.
|
@@ -104,13 +106,13 @@ class Chef
|
|
104
106
|
# value:: Whatever the most specific value of the hash is.
|
105
107
|
def value_for_platform(platform_hash)
|
106
108
|
PlatformDependentValue.new(platform_hash).value_for_node(node)
|
107
|
-
end
|
109
|
+
end
|
108
110
|
|
109
111
|
# Given a list of platforms, returns true if the current recipe is being run on a node with
|
110
112
|
# that platform, false otherwise.
|
111
113
|
#
|
112
114
|
# === Parameters
|
113
|
-
# args:: A list of platforms
|
115
|
+
# args:: A list of platforms. Each platform can be in string or symbol format.
|
114
116
|
#
|
115
117
|
# === Returns
|
116
118
|
# true:: If the current platform is in the list
|
@@ -119,12 +121,96 @@ class Chef
|
|
119
121
|
has_platform = false
|
120
122
|
|
121
123
|
args.flatten.each do |platform|
|
122
|
-
has_platform = true if platform == node[:platform]
|
124
|
+
has_platform = true if platform.to_s == node[:platform]
|
123
125
|
end
|
124
126
|
|
125
127
|
has_platform
|
126
128
|
end
|
127
129
|
|
130
|
+
|
131
|
+
|
132
|
+
# Implementation class for determining platform family dependent values
|
133
|
+
class PlatformFamilyDependentValue
|
134
|
+
|
135
|
+
# Create a platform family dependent value object.
|
136
|
+
# === Arguments
|
137
|
+
# platform_family_hash (Hash) a map of platform families to values.
|
138
|
+
# like this:
|
139
|
+
# {
|
140
|
+
# :rhel => "value for all EL variants"
|
141
|
+
# :fedora => "value for fedora variants fedora and amazon" ,
|
142
|
+
# [:fedora, :rhel] => "value for all known redhat variants"
|
143
|
+
# :debian => "value for debian variants including debian, ubuntu, mint" ,
|
144
|
+
# :default => "the default when nothing else matches"
|
145
|
+
# }
|
146
|
+
# * platform families can be specified as Symbols or Strings
|
147
|
+
# * multiple platform families can be grouped by using an Array as the key
|
148
|
+
# * values for platform families can be any object, with no restrictions. Some examples:
|
149
|
+
# - [:stop, :start]
|
150
|
+
# - "mysql-devel"
|
151
|
+
# - { :key => "value" }
|
152
|
+
def initialize(platform_family_hash)
|
153
|
+
@values = {}
|
154
|
+
@values["default"] = nil
|
155
|
+
platform_family_hash.each { |platform_families, value| set(platform_families, value)}
|
156
|
+
end
|
157
|
+
|
158
|
+
def value_for_node(node)
|
159
|
+
if node.key?(:platform_family)
|
160
|
+
platform_family = node[:platform_family].to_s
|
161
|
+
if @values.key?(platform_family)
|
162
|
+
@values[platform_family]
|
163
|
+
else
|
164
|
+
@values["default"]
|
165
|
+
end
|
166
|
+
else
|
167
|
+
@values["default"]
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
|
173
|
+
def set(platform_family, value)
|
174
|
+
if platform_family.to_s == 'default'
|
175
|
+
@values["default"] = value
|
176
|
+
else
|
177
|
+
Array(platform_family).each { |family| @values[family.to_s] = value }
|
178
|
+
value
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
|
184
|
+
# Given a hash mapping platform families to values, select a value from the hash. Supports a single
|
185
|
+
# base default if platform family is not in the map. Arrays may be passed as hash keys and will be
|
186
|
+
# expanded.
|
187
|
+
#
|
188
|
+
# === Parameters
|
189
|
+
# platform_family_hash:: A hash in the form { platform_family_name => value }
|
190
|
+
#
|
191
|
+
# === Returns
|
192
|
+
# value:: Whatever the most specific value of the hash is.
|
193
|
+
def value_for_platform_family(platform_family_hash)
|
194
|
+
PlatformFamilyDependentValue.new(platform_family_hash).value_for_node(node)
|
195
|
+
end
|
196
|
+
|
197
|
+
# Given a list of platform families, returns true if the current recipe is being run on a
|
198
|
+
# node within that platform family, false otherwise.
|
199
|
+
#
|
200
|
+
# === Parameters
|
201
|
+
# args:: A list of platform families. Each platform family can be in string or symbol format.
|
202
|
+
#
|
203
|
+
# === Returns
|
204
|
+
# true:: if the current node platform family is in the list.
|
205
|
+
# false:: if the current node platform family is not in the list.
|
206
|
+
def platform_family?(*args)
|
207
|
+
has_pf = false
|
208
|
+
args.flatten.each do |platform_family|
|
209
|
+
has_pf = true if platform_family.to_s == node[:platform_family]
|
210
|
+
end
|
211
|
+
has_pf
|
212
|
+
end
|
213
|
+
|
128
214
|
def search(*args, &block)
|
129
215
|
# If you pass a block, or have at least the start argument, do raw result parsing
|
130
216
|
#
|
@@ -25,11 +25,17 @@ class Chef
|
|
25
25
|
def include_recipe(*recipe_names)
|
26
26
|
result_recipes = Array.new
|
27
27
|
recipe_names.flatten.each do |recipe_name|
|
28
|
-
if node.run_state[:seen_recipes].has_key?(recipe_name)
|
28
|
+
if node.run_state[:seen_recipes].has_key?(recipe_name) or node.run_state[:seen_recipes].has_key?(recipe_name + "::default")
|
29
29
|
Chef::Log.debug("I am not loading #{recipe_name}, because I have already seen it.")
|
30
30
|
next
|
31
31
|
end
|
32
32
|
|
33
|
+
result_recipes << load_recipe(recipe_name)
|
34
|
+
end
|
35
|
+
result_recipes
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_recipe(recipe_name)
|
33
39
|
Chef::Log.debug("Loading Recipe #{recipe_name} via include_recipe")
|
34
40
|
node.run_state[:seen_recipes][recipe_name] = true
|
35
41
|
|
@@ -37,9 +43,7 @@ class Chef
|
|
37
43
|
|
38
44
|
run_context = self.is_a?(Chef::RunContext) ? self : self.run_context
|
39
45
|
cookbook = run_context.cookbook_collection[cookbook_name]
|
40
|
-
|
41
|
-
end
|
42
|
-
result_recipes
|
46
|
+
cookbook.load_recipe(recipe_short_name, run_context)
|
43
47
|
end
|
44
48
|
|
45
49
|
def require_recipe(*args)
|
@@ -0,0 +1,67 @@
|
|
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
|
+
class Chef
|
20
|
+
module Mixin
|
21
|
+
module PathSanity
|
22
|
+
|
23
|
+
def enforce_path_sanity(env=ENV)
|
24
|
+
if Chef::Config[:enforce_path_sanity]
|
25
|
+
path_separator = Chef::Platform.windows? ? ';' : ':'
|
26
|
+
existing_paths = env["PATH"].split(path_separator)
|
27
|
+
# ensure the Ruby and Gem bindirs are included
|
28
|
+
# mainly for 'full-stack' Chef installs
|
29
|
+
paths_to_add = []
|
30
|
+
paths_to_add << ruby_bindir unless sane_paths.include?(ruby_bindir)
|
31
|
+
paths_to_add << gem_bindir unless sane_paths.include?(gem_bindir)
|
32
|
+
paths_to_add << sane_paths if sane_paths
|
33
|
+
paths_to_add.flatten!.compact!
|
34
|
+
paths_to_add.each do |sane_path|
|
35
|
+
unless existing_paths.include?(sane_path)
|
36
|
+
env_path = env["PATH"].dup
|
37
|
+
env_path << path_separator unless env["PATH"].empty?
|
38
|
+
env_path << sane_path
|
39
|
+
env["PATH"] = env_path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def sane_paths
|
48
|
+
@sane_paths ||= begin
|
49
|
+
if Chef::Platform.windows?
|
50
|
+
%w[]
|
51
|
+
else
|
52
|
+
%w[/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def ruby_bindir
|
58
|
+
RbConfig::CONFIG['bindir']
|
59
|
+
end
|
60
|
+
|
61
|
+
def gem_bindir
|
62
|
+
Gem.bindir
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -7,9 +7,9 @@
|
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
# you may not use this file except in compliance with the License.
|
9
9
|
# You may obtain a copy of the License at
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# Unless required by applicable law or agreed to in writing, software
|
14
14
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
15
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -18,6 +18,7 @@
|
|
18
18
|
#
|
19
19
|
|
20
20
|
require 'chef/resource'
|
21
|
+
require 'chef/resource_platform_map'
|
21
22
|
require 'chef/mixin/convert_to_class_name'
|
22
23
|
require 'chef/mixin/language'
|
23
24
|
|
@@ -29,14 +30,14 @@ require 'chef/mixin/language'
|
|
29
30
|
class Chef
|
30
31
|
module Mixin
|
31
32
|
module RecipeDefinitionDSLCore
|
32
|
-
|
33
|
+
|
33
34
|
include Chef::Mixin::ConvertToClassName
|
34
35
|
include Chef::Mixin::Language
|
35
|
-
|
36
|
+
|
36
37
|
def method_missing(method_symbol, *args, &block)
|
37
38
|
# If we have a definition that matches, we want to use that instead. This should
|
38
39
|
# let you do some really crazy over-riding of "native" types, if you really want
|
39
|
-
# to.
|
40
|
+
# to.
|
40
41
|
if run_context.definitions.has_key?(method_symbol)
|
41
42
|
# This dupes the high level object, but we still need to dup the params
|
42
43
|
new_def = run_context.definitions[method_symbol].dup
|
@@ -50,15 +51,18 @@ class Chef
|
|
50
51
|
new_recipe.instance_eval(&new_def.recipe)
|
51
52
|
else
|
52
53
|
# Otherwise, we're rocking the regular resource call route.
|
53
|
-
method_name = method_symbol.to_s
|
54
|
-
rname = convert_to_class_name(method_name)
|
55
54
|
|
56
|
-
|
57
|
-
|
55
|
+
# Checks the new platform => short_name => resource mapping initially
|
56
|
+
# then fall back to the older approach (Chef::Resource.const_get) for
|
57
|
+
# backward compatibility
|
58
|
+
resource_class = Chef::Resource.resource_for_node(method_symbol, run_context.node)
|
59
|
+
|
60
|
+
super unless resource_class
|
61
|
+
raise ArgumentError, "You must supply a name when declaring a #{method_symbol} resource" unless args.size > 0
|
58
62
|
|
59
63
|
# If we have a resource like this one, we want to steal its state
|
60
64
|
args << run_context
|
61
|
-
resource =
|
65
|
+
resource = resource_class.new(*args)
|
62
66
|
resource.load_prior_resource
|
63
67
|
resource.cookbook_name = cookbook_name
|
64
68
|
resource.recipe_name = @recipe_name
|
@@ -66,13 +70,17 @@ class Chef
|
|
66
70
|
resource.source_line = caller[0]
|
67
71
|
# Determine whether this resource is being created in the context of an enclosing Provider
|
68
72
|
resource.enclosing_provider = self.is_a?(Chef::Provider) ? self : nil
|
73
|
+
# Evaluate resource attribute DSL
|
69
74
|
resource.instance_eval(&block) if block
|
70
75
|
|
76
|
+
# Run optional resource hook
|
77
|
+
resource.after_created
|
78
|
+
|
71
79
|
run_context.resource_collection.insert(resource)
|
72
80
|
resource
|
73
81
|
end
|
74
82
|
end
|
75
|
-
|
83
|
+
|
76
84
|
end
|
77
85
|
end
|
78
86
|
end
|
@@ -0,0 +1,152 @@
|
|
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
|
+
class Chef
|
20
|
+
module Mixin
|
21
|
+
module Securable
|
22
|
+
|
23
|
+
def owner(arg=nil)
|
24
|
+
set_or_return(
|
25
|
+
:owner,
|
26
|
+
arg,
|
27
|
+
:regex => Chef::Config[:user_valid_regex]
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
alias :user :owner
|
32
|
+
|
33
|
+
def group(arg=nil)
|
34
|
+
set_or_return(
|
35
|
+
:group,
|
36
|
+
arg,
|
37
|
+
:regex => Chef::Config[:group_valid_regex]
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def mode(arg=nil)
|
42
|
+
set_or_return(
|
43
|
+
:mode,
|
44
|
+
arg,
|
45
|
+
:callbacks => {
|
46
|
+
"not in valid numeric range" => lambda { |m|
|
47
|
+
if m.kind_of?(String)
|
48
|
+
m =~ /^0/ || m="0#{m}"
|
49
|
+
end
|
50
|
+
|
51
|
+
# Windows does not support the sticky or setuid bits
|
52
|
+
if Chef::Platform.windows?
|
53
|
+
Integer(m)<=0777 && Integer(m)>=0
|
54
|
+
else
|
55
|
+
Integer(m)<=07777 && Integer(m)>=0
|
56
|
+
end
|
57
|
+
},
|
58
|
+
}
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
62
|
+
# TODO should this be separated into different files?
|
63
|
+
if RUBY_PLATFORM =~ /mswin|mingw|windows/
|
64
|
+
|
65
|
+
# supports params like this:
|
66
|
+
#
|
67
|
+
# rights :read, ["Administrators","Everyone"]
|
68
|
+
# rights :deny, "Pinky"
|
69
|
+
# rights :full_control, "Users", :applies_to_children => true
|
70
|
+
# rights :write, "John Keiser", :applies_to_children => :containers_only, :applies_to_self => false, :one_level_deep => true
|
71
|
+
#
|
72
|
+
# should also also allow multiple right declarations
|
73
|
+
# in a single resource block as the data will be merged
|
74
|
+
# into a single internal hash
|
75
|
+
#
|
76
|
+
# This method 'creates' rights attributes..this allows us to have
|
77
|
+
# multiple instances of the attribute with separate runtime states.
|
78
|
+
# See +Chef::Resource::RemoteDirectory+ for example usage (rights and files_rights)
|
79
|
+
def self.rights_attribute(name)
|
80
|
+
define_method(name) do |*args|
|
81
|
+
# Ruby 1.8 compat: default the arguments
|
82
|
+
permissions = args.length >= 1 ? args[0] : nil
|
83
|
+
principals = args.length >= 2 ? args[1] : nil
|
84
|
+
args_hash = args.length >= 3 ? args[2] : nil
|
85
|
+
raise ArgumentError.new("wrong number of arguments (#{args.length} for 3)") if args.length >= 4
|
86
|
+
|
87
|
+
rights = self.instance_variable_get("@#{name.to_s}".to_sym)
|
88
|
+
unless permissions == nil
|
89
|
+
input = {
|
90
|
+
:permissions => permissions,
|
91
|
+
:principals => principals
|
92
|
+
}
|
93
|
+
input.merge!(args_hash) if args_hash != nil
|
94
|
+
|
95
|
+
validations = {:permissions => { :required => true },
|
96
|
+
:principals => { :required => true, :kind_of => [String, Array] },
|
97
|
+
:applies_to_children => { :equal_to => [ true, false, :containers_only, :objects_only ]},
|
98
|
+
:applies_to_self => { :kind_of => [ TrueClass, FalseClass ] },
|
99
|
+
:one_level_deep => { :kind_of => [ TrueClass, FalseClass ] }
|
100
|
+
}
|
101
|
+
validate(input, validations)
|
102
|
+
|
103
|
+
[ permissions ].flatten.each do |permission|
|
104
|
+
if permission.is_a?(Integer)
|
105
|
+
if permission < 0 || permission > 1<<32
|
106
|
+
raise ArgumentError, "permissions flags must be positive and <= 32 bits (#{permission})"
|
107
|
+
end
|
108
|
+
elsif !([:full_control, :modify, :read_execute, :read, :write].include?(permission.to_sym))
|
109
|
+
raise ArgumentError, "permissions parameter must be :full_control, :modify, :read_execute, :read, :write or an integer representing Windows permission flags"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
[ principals ].flatten.each do |principal|
|
114
|
+
if !principal.is_a?(String)
|
115
|
+
raise ArgumentError, "principals parameter must be a string or array of strings representing usernames"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
if input[:applies_to_children] == false
|
120
|
+
if input[:applies_to_self] == false
|
121
|
+
raise ArgumentError, "'rights' attribute must specify either :applies_to_children or :applies_to_self."
|
122
|
+
end
|
123
|
+
if input[:one_level_deep] == true
|
124
|
+
raise ArgumentError, "'rights' attribute specified :one_level_deep without specifying :applies_to_children."
|
125
|
+
end
|
126
|
+
end
|
127
|
+
rights ||= []
|
128
|
+
rights << input
|
129
|
+
end
|
130
|
+
set_or_return(
|
131
|
+
name,
|
132
|
+
rights,
|
133
|
+
{}
|
134
|
+
)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# create a default 'rights' attribute
|
139
|
+
rights_attribute(:rights)
|
140
|
+
rights_attribute(:deny_rights)
|
141
|
+
|
142
|
+
def inherits(arg=nil)
|
143
|
+
set_or_return(
|
144
|
+
:inherits,
|
145
|
+
arg,
|
146
|
+
:kind_of => [ TrueClass, FalseClass ]
|
147
|
+
)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|