Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do Not Merge] Modify in_position? method to fix inconsistencies #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions lib/puppet/provider/pam/augeas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,23 @@ def in_position?
unless resource[:position].nil?
path, before = self.class.position_path(resource[:position], resource[:type])

if before == 'before'
mpath = "#{resource_path}[following-sibling::#{path}]"
else
mpath = "#{resource_path}[preceding-sibling::#{path}]"
# Would someone ever have an xpath for positioning that would include more than one [last()] ?
# This section banks on there only ever being one [last()]...
# We are unable to use [last()] inside the preceding-sibling block as it would always result in [1] so we do an
# extra call to augeas to find the amount of matches and subtract 1 to match the proper lookup/emulate last()
if path.include?('[last()]')
last_value = augopen.match(path.sub('[last()]','')).count
return true if last_value <= 1
last_value = last_value - 1
path.sub!('[last()]', "[#{last_value}]")
end
mpath = "#{resource_path}[preceding-sibling::#{path}]"

augmatch = false
augopen do |aug|
!aug.match(mpath).empty?
augmatch = aug.match(mpath).empty?
# Since we use preceding-sibling for everything, we invert on the result if 'after' instead as it's more consistent
before == 'before' ? augmatch : !augmatch
end
end
end
Expand Down