summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-12-04 11:33:55 -0800
committerdanielsdeleo <dan@opscode.com>2013-01-03 16:25:21 -0800
commitd3886b18c5407303dbeab9485b19422e700c780b (patch)
tree3e851f246beb5144c0c30db469a56af437e7297d
parent3360d96fdc690958dd0cc5ac9ef32d82e18a342b (diff)
downloadchef-d3886b18c5407303dbeab9485b19422e700c780b.tar.gz
[CHEF-3557] Factor out windows security resource attrs
Factor windows-specific file security code into modules so one can manually create a "windows-flavored" file resource for unit testing. There are better ways to do this (see comments), but this works for now.
-rw-r--r--lib/chef/mixin/securable.rb37
-rw-r--r--lib/chef/resource/remote_directory.rb11
2 files changed, 37 insertions, 11 deletions
diff --git a/lib/chef/mixin/securable.rb b/lib/chef/mixin/securable.rb
index 47c388b239..4ab343df8f 100644
--- a/lib/chef/mixin/securable.rb
+++ b/lib/chef/mixin/securable.rb
@@ -59,9 +59,17 @@ class Chef
)
end
- # TODO should this be separated into different files?
- if RUBY_PLATFORM =~ /mswin|mingw|windows/
+ #==WindowsMacros
+ # Defines methods for adding attributes to a chef resource to describe
+ # Windows file security metadata.
+ #
+ # This module is meant to be used to extend a class (instead of
+ # `include`-ing). A class is automatically extended with this module when
+ # it includes WindowsSecurableAttributes.
+ # --
+ # TODO should this be separated into different files?
+ module WindowsMacros
# === rights_attribute
# "meta-method" for dynamically creating rights attributes on resources.
#
@@ -99,7 +107,7 @@ class Chef
# * `:applies_to_self` (optional): Boolean
# * `:one_level_deep` (optional): Boolean
#
- def self.rights_attribute(name)
+ def rights_attribute(name)
# equivalent to something like:
# def rights(permissions=nil, principals=nil, args_hash=nil)
@@ -160,10 +168,24 @@ class Chef
)
end
end
+ end
- # create a default 'rights' attribute
- rights_attribute(:rights)
- rights_attribute(:deny_rights)
+ #==WindowsSecurableAttributes
+ # Defines methods #rights, #deny_rights, and #inherits to describe
+ # Windows file security ACLs on the including class. The including class
+ # is also extended with WindowsMacros, so more rights attributes may be
+ # defined.
+ module WindowsSecurableAttributes
+
+ # Callback that fires when included; will extend the including class
+ # with WindowsMacros and define #rights and #deny_rights on it.
+ def self.included(including_class)
+ including_class.extend(WindowsMacros)
+
+ # create a default 'rights' attribute
+ including_class.rights_attribute(:rights)
+ including_class.rights_attribute(:deny_rights)
+ end
def inherits(arg=nil)
set_or_return(
@@ -172,7 +194,10 @@ class Chef
:kind_of => [ TrueClass, FalseClass ]
)
end
+ end
+ if RUBY_PLATFORM =~ /mswin|mingw|windows/
+ include WindowsSecurableAttributes
end # Windows-specific
end
diff --git a/lib/chef/resource/remote_directory.rb b/lib/chef/resource/remote_directory.rb
index 490e3c6ba7..0f7e0eb5de 100644
--- a/lib/chef/resource/remote_directory.rb
+++ b/lib/chef/resource/remote_directory.rb
@@ -51,6 +51,12 @@ class Chef
@provider = Chef::Provider::RemoteDirectory
end
+ if Chef::Platform.windows?
+ # create a second instance of the 'rights' attribute
+ rights_attribute(:files_rights)
+ end
+
+
def source(args=nil)
set_or_return(
:source,
@@ -83,11 +89,6 @@ class Chef
)
end
- if Chef::Platform.windows?
- # create a second instance of the 'rights' attribute
- Chef::Mixin::Securable.rights_attribute(:files_rights)
- end
-
def files_mode(arg=nil)
set_or_return(
:files_mode,