Skip to content

Commit

Permalink
Add recursemode parameter to chose to apply ACL's recursively
Browse files Browse the repository at this point in the history
This commit adds a Recursemode parameter to generate additional
resources for children files when recurse is set to true.

Depends on voxpupuli#11.
  • Loading branch information
roidelapluie committed Aug 10, 2015
1 parent c3e2208 commit 7a3b01b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/puppet/provider/acl/posixacl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def permission

def check_recursive
# Changed functionality to return boolean true or false
value = (@resource.value(:recursive) == :true)
value = (@resource.value(:recursive) == :true and resource.value(:recursemode) == :lazy)
end

def check_exact
Expand Down
32 changes: 32 additions & 0 deletions lib/puppet/type/acl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@
end
end

newparam(:recursemode) do
desc "Should Puppet apply the ACL recursively with the -R option or
apply it to individual files?
lazy means -R option
deep means apply to every file"

newvalues(:lazy, :deep)
defaultto :lazy
end

autorequire(:file) do
if self[:path]
[self[:path]]
Expand Down Expand Up @@ -199,6 +210,27 @@ def insync?(is)
defaultto :false
end

def newchild(path)
full_path = ::File.join(self[:path], path)
options = @original_parameters.merge(:name => full_path).reject { |param, value| value.nil? }
[:recursive, :recursemode, :path].each do |param|
options.delete(param) if options.include?(param)
end
self.class.new(options)
end

def generate
return [] unless self[:recursive] == :true and self[:recursemode] == :deep
return [] unless File.directory?(self[:path])
results = []
Dir.chdir(self[:path]) do
Dir['**/*'].each do |path|
results << newchild(path)
end
end
results
end

validate do
unless self[:permission]
raise(Puppet::Error, "permission is a required property.")
Expand Down
20 changes: 20 additions & 0 deletions spec/unit/puppet/type/acl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,31 @@
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:recursive]).to eq(:false)
end
it 'should get recursemode lazy by default' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx']
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:recursemode]).to eq(:lazy)
end
it 'should accept a recursemode deep' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :recursemode => 'deep'
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:recursemode]).to eq(:deep)
end
it 'should accept a recursemode lazy' do
resource = acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :recursemode => :lazy
expect(resource[:name]).to eq('/tmp/foo')
expect(resource[:recursemode]).to eq(:lazy)
end
it 'should fail with a wrong action' do
expect{
acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :action => :xset
}.to raise_error
end
it 'should fail with a wrong recurselimit' do
expect{
acl_type.new :name => '/tmp/foo', :permission => ['o::rwx'], :recurselimit => :a
}.to raise_error
end
it 'should fail with a wrong first argument' do
expect{
acl_type.new :name => '/tmp/foo', :permission => ['wrong::rwx']
Expand Down

0 comments on commit 7a3b01b

Please sign in to comment.