Skip to content

Commit

Permalink
Better support for 'deep' recursive acls
Browse files Browse the repository at this point in the history
  • Loading branch information
roidelapluie committed Sep 22, 2015
1 parent a8060be commit 303da85
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/puppet/type/acl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'set'

Puppet::Type.newtype(:acl) do
desc <<-EOT
Expand Down Expand Up @@ -210,11 +211,27 @@ def insync?(is)
defaultto :false
end

def self.pick_default_perms(perms)
non_default = perms.reject { |perm| perm =~ /^d/ }
default = perms.reject { |perm| perm !~ /^d/ }.map {
|perm| perm.split(':')[1..-1].join(':')
}
Set.new((non_default + default).map { |perm|
key = perm.split(':')[0..1].join(':')
matching_default = default.reject { |perm| perm !~ /^#{key}:/ }
if (matching_default.length > 0)
matching_default
else
perm
end
}).to_a.flatten
end

def newchild(path)
full_path = ::File.join(self[:path], path)
options = @original_parameters.merge(:name => full_path).reject { |param, value| value.nil? }
unless File.directory?(options[:name]) then
options[:permission].reject! { |acl| acl.split(':', -1).length == 4 } if options.include?(:permission)
options[:permission] = self.class.pick_default_perms(options[:permission]) if options.include?(:permission)
end
[:recursive, :recursemode, :path].each do |param|
options.delete(param) if options.include?(param)
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/puppet/type/acl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,16 @@
end
end

context 'when converting default parameters' do
basic_perms = ['user:foo:rwx', 'group:foo:rwx']
advanced_perms = ['user:foo:rwx', 'group:foo:rwx', 'default:user:foo:---']
advanced_perms_results = ['user:foo:---', 'group:foo:rwx']
it 'should not do anything with no defaults' do
expect(acl_type.pick_default_perms(basic_perms)).to eq(basic_perms)
end
it 'should override defaults' do
expect(acl_type.pick_default_perms(advanced_perms)).to eq(advanced_perms_results)
end
end

end

0 comments on commit 303da85

Please sign in to comment.