Module: Chef::Mixin::Securable
- Included in:
- Resource::CookbookFile, Resource::Directory, Resource::File, Resource::Link, Resource::RemoteDirectory, Resource::RemoteFile, Resource::Template
- Defined in:
- lib/chef/mixin/securable.rb
Class Method Summary collapse
-
.rights_attribute(name) ⇒ Object
supports params like this:.
Instance Method Summary collapse
- #group(arg = nil) ⇒ Object
- #inherits(arg = nil) ⇒ Object
- #mode(arg = nil) ⇒ Object
- #owner(arg = nil) ⇒ Object (also: #user)
Class Method Details
.rights_attribute(name) ⇒ Object
supports params like this:
rights :read, ["Administrators","Everyone"]
rights :deny, "Pinky"
rights :full_control, "Users", :applies_to_children => true
rights :write, "John Keiser", :applies_to_children => :containers_only, :applies_to_self => false, :one_level_deep => true
should also also allow multiple right declarations in a single resource block as the data will be merged into a single internal hash
This method ‘creates’ rights attributes..this allows us to have multiple instances of the attribute with separate runtime states. See Chef::Resource::RemoteDirectory for example usage (rights and files_rights)
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/chef/mixin/securable.rb', line 79 def self.rights_attribute(name) define_method(name) do |*args| # Ruby 1.8 compat: default the arguments = args.length >= 1 ? args[0] : nil principals = args.length >= 2 ? args[1] : nil args_hash = args.length >= 3 ? args[2] : nil raise ArgumentError.new("wrong number of arguments (#{args.length} for 3)") if args.length >= 4 rights = self.instance_variable_get("@#{name.to_s}".to_sym) unless == nil input = { :permissions => , :principals => principals } input.merge!(args_hash) if args_hash != nil validations = {:permissions => { :required => true }, :principals => { :required => true, :kind_of => [String, Array] }, :applies_to_children => { :equal_to => [ true, false, :containers_only, :objects_only ]}, :applies_to_self => { :kind_of => [ TrueClass, FalseClass ] }, :one_level_deep => { :kind_of => [ TrueClass, FalseClass ] } } validate(input, validations) [ ].flatten.each do || if .is_a?(Integer) if < 0 || > 1<<32 raise ArgumentError, "permissions flags must be positive and <= 32 bits (#{permission})" end elsif !([:full_control, :modify, :read_execute, :read, :write].include?(.to_sym)) raise ArgumentError, "permissions parameter must be :full_control, :modify, :read_execute, :read, :write or an integer representing Windows permission flags" end end [ principals ].flatten.each do |principal| if !principal.is_a?(String) raise ArgumentError, "principals parameter must be a string or array of strings representing usernames" end end if input[:applies_to_children] == false if input[:applies_to_self] == false raise ArgumentError, "'rights' attribute must specify either :applies_to_children or :applies_to_self." end if input[:one_level_deep] == true raise ArgumentError, "'rights' attribute specified :one_level_deep without specifying :applies_to_children." end end rights ||= [] rights << input end set_or_return( name, rights, {} ) end end |
Instance Method Details
#group(arg = nil) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/chef/mixin/securable.rb', line 33 def group(arg=nil) set_or_return( :group, arg, :regex => Chef::Config[:group_valid_regex] ) end |
#inherits(arg = nil) ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/chef/mixin/securable.rb', line 142 def inherits(arg=nil) set_or_return( :inherits, arg, :kind_of => [ TrueClass, FalseClass ] ) end |
#mode(arg = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chef/mixin/securable.rb', line 41 def mode(arg=nil) set_or_return( :mode, arg, :callbacks => { "not in valid numeric range" => lambda { |m| if m.kind_of?(String) m =~ /^0/ || m="0#{m}" end # Windows does not support the sticky or setuid bits if Chef::Platform.windows? Integer(m)<=0777 && Integer(m)>=0 else Integer(m)<=07777 && Integer(m)>=0 end }, } ) end |
#owner(arg = nil) ⇒ Object Also known as: user
23 24 25 26 27 28 29 |
# File 'lib/chef/mixin/securable.rb', line 23 def owner(arg=nil) set_or_return( :owner, arg, :regex => Chef::Config[:user_valid_regex] ) end |