Skip to content

Commit

Permalink
Fixes voxpupuli#37 - Logrotate rule ERB template should not take vari…
Browse files Browse the repository at this point in the history
…ables from the scope object
  • Loading branch information
imriz committed Aug 9, 2016
1 parent f80012c commit f8abe5a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions spec/defines/rule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1205,4 +1205,20 @@
end
end
end

context 'template should not inherit variables from other scopes' do
let(:title) { 'foo' }
let(:params) {
{:path => '/var/log/foo.log',:ifempty => true}
}
let(:facts) {
{
:osfamily => 'RedHat',
:operatingsystemmajrelease => 7
}
}
it do
should contain_file('/etc/logrotate.d/btmp').without_content(/ifempty/)
end
end
end
8 changes: 4 additions & 4 deletions templates/etc/logrotate.d/rule.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
rpath = @path
end

if scope.to_hash.has_key?('sane_create')
if has_variable?('@sane_create')
if @sane_create == 'create'
opts << [@sane_create, @create_mode, @create_owner, @create_group].reject { |r|
r == 'UNDEFINED'
Expand All @@ -20,7 +20,7 @@
end
end

if scope.to_hash.has_key?('sane_su')
if has_variable?('@sane_su')
if @sane_su == 'su'
opts << [@sane_su, @su_owner, @su_group].reject { |r|
r == 'UNDEFINED'
Expand All @@ -33,15 +33,15 @@
'mail', 'missingok', 'olddir', 'sharedscripts', 'ifempty', 'maillast',
'mailfirst', 'shred', 'rotate_every'
].each do |bool|
opts << scope.to_hash["sane_#{bool}"] if scope.to_hash.has_key?("sane_#{bool}")
opts << instance_variable_get("@sane_#{bool}") if has_variable?("@sane_#{bool}")
end

[
'compresscmd', 'compressext', 'compressoptions', 'dateformat', 'extension',
'maxage', 'minsize', 'maxsize', 'rotate', 'size', 'shredcycles', 'start',
'uncompresscmd'
].each do |key|
value = scope.to_hash[key]
value = instance_variable_get("@#{key}")
opts << "#{key} #{value}" if value != 'UNDEFINED'
end
-%>
Expand Down

0 comments on commit f8abe5a

Please sign in to comment.