From 1f9c305ff5333e16dc2c5401dbbb85d1101dd0fa Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Tue, 16 Mar 2010 06:30:33 -0500 Subject: specified exceotion when trying to change type. checked for unmatched attributes. --- lib/puppet/provider/sudoers/parsed.rb | 16 ++++++++------ lib/puppet/type/sudoers.rb | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/puppet/provider/sudoers/parsed.rb b/lib/puppet/provider/sudoers/parsed.rb index cdcab19..e18b220 100644 --- a/lib/puppet/provider/sudoers/parsed.rb +++ b/lib/puppet/provider/sudoers/parsed.rb @@ -9,7 +9,6 @@ Puppet::Type.type(:sudoers).provide( :parsed, :parent => Puppet::Provider::ParsedFile, :default_target => '/etc/sudoers', - # what the heck does this mean? :filetype => :flat ) do @@ -102,6 +101,11 @@ Puppet::Type.type(:sudoers).provide( hash[:parameters] = parameters.gsub(/\s/, '').split(',') end + # can I override this? + def type=(value) + raise Puppet::Error, 'not supporting switching NAMEVAR between record types' + 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 @@ -137,8 +141,8 @@ Puppet::Type.type(:sudoers).provide( # overriding how lines are written to the file def self.to_line(hash) -# puts "\nEntering self.to_line for #{hash[:name]}" - #puts "\n#{hash.to_yaml}\n" + 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] if(hash[:record_type] == :blank || hash[:record_type] == :comment) hash[:line] @@ -209,9 +213,9 @@ Puppet::Type.type(:sudoers).provide( # flush seems to be called more than one time? def self.flush_target(target) Puppet.info("We are flushing #{target}") - # a little pre-flush hot visudo action -#puts File.read(target) - visudo("-cf", target) unless (File.zero?(target) or !File.exists?(target)) + # a little pre-flush hot visudo action + #puts File.read(target) + visudo("-cf", target) unless (File.zero?(target) or !File.exists?(target)) super(target) end end diff --git a/lib/puppet/type/sudoers.rb b/lib/puppet/type/sudoers.rb index 85593a2..64d66e0 100644 --- a/lib/puppet/type/sudoers.rb +++ b/lib/puppet/type/sudoers.rb @@ -74,6 +74,14 @@ Defaults@host x=y,one=1,two=2 newparam(:name) do desc "Either the name of the alias, default, or arbitrary unique string for user specifications" isnamevar + munge do |value| + #puts "params \n#{resource.original_parameters.to_yaml}\n" + value + end + end + + newproperty(:type) do + desc "optional parameter used to determine what the record type is" end newproperty(:sudo_alias) do @@ -123,5 +131,37 @@ Defaults@host x=y,one=1,two=2 desc "default parameters" end + # make sure that we only have attributes for either default, alias, or user_spec + SUDOERS_DEFAULT = [:parameters] + SUDOERS_ALIAS = [:sudo_alias, :items] + SUDOERS_SPEC = [:users, :hosts, :commands] + validate do + if self[:sudo_alias] + self[:type] = 'alias' + checkprops(SUDOERS_DEFAULT, SUDOERS_SPEC) + elsif self[:parameters] + checkprops(SUDOERS_ALIAS, SUDOERS_SPEC) + elsif self[:users] + self[:type] = 'user_spec' + checkprops(SUDOERS_ALIAS, SUDOERS_DEFAULT) + else + # these are parsed records, do nothing + end + #puts self.should('sudo_alias') + #puts self.to_yaml + #puts self.eachproperty do |x| puts x end + end + + private + + # check that we dont have any conflicting attributes + def checkprops(array_one, array_two) + combined = Array.new.concat(array_one).concat(array_two) + combined.each do |item| + if self[item.to_sym] + raise Puppet::Error, "Unexpected attribute #{item} for sudo record type #{self[:type]}" + end + end + end end -- cgit v1.2.3