summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Bode <dan@bodepd.com>2010-05-23 18:42:53 -0500
committerDan Bode <dan@bodepd.com>2010-05-23 18:42:53 -0500
commit37099d6d140f073522f9f9b37ba2a9b429433f25 (patch)
tree695f54b5a7c855f3983300cf72fafa7b9731b941 /lib
parent3ef36b6948bd39c91f62fd9d33eae3f1dfe3234c (diff)
fixes for:
- fake namevar for unmanaged user specs. - checking ensure in type, to differentiate self.instances type calls. - changed add line message from info to debug
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/sudoers/parsed.rb17
-rw-r--r--lib/puppet/type/sudoers.rb50
2 files changed, 45 insertions, 22 deletions
diff --git a/lib/puppet/provider/sudoers/parsed.rb b/lib/puppet/provider/sudoers/parsed.rb
index d146fe5..8d901ff 100644
--- a/lib/puppet/provider/sudoers/parsed.rb
+++ b/lib/puppet/provider/sudoers/parsed.rb
@@ -82,7 +82,7 @@ Puppet::Type.type(:sudoers).provide(
if element =~ /^\s*(\S+)\s+(\S+)\s*$/
user, host = $1, $2
if currentsymbol == :hosts
- raise Exception, 'found more than one whitespace delim in users_hosts'
+ raise Puppet::Error, 'found more than one whitespace delim in users_hosts'
end
# sweet we found the delim between user and host
hash[currentsymbol] << user.gsub(/\s/, '')
@@ -92,7 +92,7 @@ Puppet::Type.type(:sudoers).provide(
elsif element =~ /\s*\S+\s*/
hash[currentsymbol] << element.gsub(/\s/, '')
else
- raise Exception, "Malformed user spec line lhs: #{lhs}"
+ raise Puppet::Error, "Malformed user spec line lhs: #{lhs}"
end
end
end
@@ -118,7 +118,8 @@ Puppet::Type.type(:sudoers).provide(
def self.prefetch_hook(records)
# store comment name vars when we find them
name,comment=nil
- results = records.each do |record|
+ results = records.each_index do |index|
+ record = records[index]
if(record[:record_type] == :comment)
# if we are a namevar comment
#puts "found a comment: #{record.to_yaml}"
@@ -140,7 +141,9 @@ Puppet::Type.type(:sudoers).provide(
record[:name] = name
name = nil
else
- Puppet.info "spec record not created by puppet"
+ fake_namevar = "fake_namevar_#{index}"
+ Puppet.warning "user spec record not created by puppet, adding fake namevar #{fake_namevar}"
+ record[:name] = fake_namevar
# probably a pre-exting record not created by puppet
end
end
@@ -184,7 +187,7 @@ Puppet::Type.type(:sudoers).provide(
commands=self.array_convert(hash[:commands])
str = "#Puppet NAMEVAR #{hash[:name]}"
str << "\n#{users} #{hosts}=#{commands}"
- Puppet.notice "adding line: #{str}"
+ Puppet.debug "adding line: #{str}"
str
end
@@ -195,7 +198,7 @@ Puppet::Type.type(:sudoers).provide(
# since different attributes make sense based on ensure value (dir/file/symlink)
items=self.array_convert(hash[:items])
str = "#{hash[:sudo_alias]} #{hash[:name]}=#{items}"
- Puppet.notice "adding line: #{str}"
+ Puppet.debug "adding line: #{str}"
str
end
@@ -204,7 +207,7 @@ Puppet::Type.type(:sudoers).provide(
def self.default_to_line(hash)
parameters=self.array_convert(hash[:parameters])
str = "#{hash[:name]} #{parameters}"
- Puppet.notice "Adding line #{str}"
+ Puppet.debug "Adding line #{str}"
str
end
diff --git a/lib/puppet/type/sudoers.rb b/lib/puppet/type/sudoers.rb
index ac7e4ec..d62ae0d 100644
--- a/lib/puppet/type/sudoers.rb
+++ b/lib/puppet/type/sudoers.rb
@@ -82,6 +82,11 @@ Defaults@host x=y,one=1,two=2
#puts "params \n#{resource.original_parameters.to_yaml}\n"
value
end
+ validate do |name|
+ if name =~ /^fake_namevar_\d+/
+ raise Puppet::Error, "cannot use reserved namevar #{name}"
+ end
+ end
end
@@ -89,14 +94,15 @@ Defaults@host x=y,one=1,two=2
# I changed this to be required. this will allow me to
# do more param checking based on type.
#
- newparam(:type) do
+ newproperty(:type) do
desc "optional parameter used to determine what the record type is"
- isrequired
- validate do |type|
- unless type =~ /(default|alias|user_spec)/
- raise Puppet::Exception, "unexpected sudoers type #{type}"
+ # why isnt this working?
+ validate do |my_type|
+ unless my_type =~ /(default|alias|user_spec)/
+ raise Puppet::Error, "unexpected sudoers type #{my_type}"
end
end
+ isrequired
end
newproperty(:sudo_alias) do
@@ -164,16 +170,30 @@ Defaults@host x=y,one=1,two=2
SUDOERS_DEFAULT = [:parameters]
SUDOERS_ALIAS = [:sudo_alias, :items]
SUDOERS_SPEC = [:users, :hosts, :commands]
+#
+# this does not work both ways for some reason
+#
+#
validate do
- if self[:type] == 'default'
- checkprops(SUDOERS_DEFAULT)
- elsif self[:type] == 'alias'
- checkprops(SUDOERS_ALIAS)
- elsif self[:type] == 'user_spec'
- checkprops(SUDOERS_SPEC)
+ # this if ensure if a little hackish -
+ # balically, when initialize is called from self.instances
+ # none of the attributes are actually set (including type)
+ # the best way to tell if I was called by self.instances
+ # is to check if ensure has a value?
+ if self[:ensure]
+ if self.value(:type) == 'default'
+ checkprops(SUDOERS_DEFAULT)
+ elsif self.value(:type) == 'alias'
+ checkprops(SUDOERS_ALIAS)
+ elsif self.value(:type) == 'user_spec'
+ checkprops(SUDOERS_SPEC)
+ elsif ! self[:type]
+ # this is only during purging (self.instances)
+ raise Puppet::Error, 'attribute type must be set for sudoers type'
+ end
else
- # this should not be possible
- raise "Unknown type #{self[:type]}"
+ # this occurs with self.instances
+ # is there a better way?
end
end
@@ -181,8 +201,8 @@ Defaults@host x=y,one=1,two=2
def checkprops(props)
props.each do |prop|
- unless self[prop.to_symbol]
- raise Puppet::Exception, "missing attribute #{prop} for type #{type}"
+ unless self[prop.to_s]
+ raise Puppet::Error, "missing attribute #{prop} for type #{self[:type]}"
end
end
end