summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Bode <dan@bodepd.com>2010-06-02 11:50:15 -0500
committerDan Bode <dan@bodepd.com>2010-06-02 11:50:15 -0500
commit969dd66a4de43818dcff5afdbf1d79d7c23f01e8 (patch)
treed313793ef3f3dae6d8ba1f4699091515898aa256 /lib
parent92f319f212e784aeb8d8706c4b1832287221d751 (diff)
Adding fake_namevars for unmanaged user spec lines. Fixed some issues with comments being written too many times.
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/sudoers/parsed.rb36
-rw-r--r--lib/puppet/type/sudoers.rb5
2 files changed, 32 insertions, 9 deletions
diff --git a/lib/puppet/provider/sudoers/parsed.rb b/lib/puppet/provider/sudoers/parsed.rb
index 8d901ff..77c0f1e 100644
--- a/lib/puppet/provider/sudoers/parsed.rb
+++ b/lib/puppet/provider/sudoers/parsed.rb
@@ -66,6 +66,7 @@ Puppet::Type.type(:sudoers).provide(
# parse existing user spec lines from sudoers
def self.parse_user_spec(users_hosts, commands, hash)
+#puts 'user spec'
hash[:type] = 'user_spec'
#hash[:name] = user
#hash[:hosts] = hosts.gsub(/\s/, '').split(',')
@@ -109,15 +110,26 @@ Puppet::Type.type(:sudoers).provide(
raise Puppet::Error, 'not supporting switching NAMEVAR between record types'
end
+ #
+ # set the record at the specified index as skipped.
+ # set
+
+ def self.skip_comment(records, comment_index)
+ if comment_index
+ records[comment_index][:skip] = true
+ end
+ end
+
# I could use prefetch_hook to support multi-line entries
# will use the prefetch_hook to determine if
# the line before us is a commented namevar line
# only used for user spec.
# Most of this code is shameless taken from provider crontab.rb
- # NAMEVAR comments leave me in need of a shower, but it seems to be the only way.
+ # NAMEVAR comments leave me in need of a shower, but it seems to be the only way. I am starting to like them.. is that bad?
+
def self.prefetch_hook(records)
# store comment name vars when we find them
- name,comment=nil
+ name,comment,comment_index=nil
results = records.each_index do |index|
record = records[index]
if(record[:record_type] == :comment)
@@ -128,13 +140,19 @@ Puppet::Type.type(:sudoers).provide(
name = record[:name]
record[:skip] = true
elsif record[:comment] != nil
+ # get rid of old comment
+ skip_comment(records, comment_index)
comment = record[:comment]
- record[:skip] = true
+ comment_index = index
end
elsif(record[:record_type] == :parsed)
- record[:comment] = comment
- comment = nil
+#
+# this associates the previous comment with a record.
+# I cant think of anyway to get around this.
# if we are a spec record, check the namevar
+ record[:comment] = comment
+ skip_comment(records, comment_index)
+ comment=nil
if record[:type] == 'user_spec'
if name
#puts "adding to a record"
@@ -142,11 +160,12 @@ Puppet::Type.type(:sudoers).provide(
name = nil
else
fake_namevar = "fake_namevar_#{index}"
- Puppet.warning "user spec record not created by puppet, adding fake namevar #{fake_namevar}"
+ Puppet.warning "user spec #{record[:line]} not created by puppet, adding fake namevar #{fake_namevar}"
record[:name] = fake_namevar
- # probably a pre-exting record not created by puppet
end
end
+ else
+ skip_comment(records, comment_index)
end
end.reject{|record| record[:skip]}
results
@@ -157,8 +176,9 @@ Puppet::Type.type(:sudoers).provide(
#puts "\nEntering self.to_line for #{hash[:name]}"
#puts "\n#{hash.to_yaml}\n"
# # dynamically call a function based on the value of hash[:type]
+#puts hash[:record_type]
if(hash[:record_type] == :blank || hash[:record_type] == :comment)
- hash[:line]
+ line = hash[:line]
elsif(hash[:type] == 'alias')
line = self.alias_to_line(hash)
elsif(hash[:type] == 'user_spec')
diff --git a/lib/puppet/type/sudoers.rb b/lib/puppet/type/sudoers.rb
index d62ae0d..8aa01db 100644
--- a/lib/puppet/type/sudoers.rb
+++ b/lib/puppet/type/sudoers.rb
@@ -82,9 +82,12 @@ Defaults@host x=y,one=1,two=2
#puts "params \n#{resource.original_parameters.to_yaml}\n"
value
end
+ # this fails for existing resources, just dont use fake_namevar stuff!
validate do |name|
if name =~ /^fake_namevar_\d+/
- raise Puppet::Error, "cannot use reserved namevar #{name}"
+ unless resource.original_parameters[:provider].get('record_type') == :parsed
+ raise Puppet::Error, "cannot use reserved namevar #{name}"
+ end
end
end
end