diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-10 23:24:34 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-10 23:24:34 +0000 |
| commit | 2d3c920e0fdef4ca38e14677a4a670f0890ff994 (patch) | |
| tree | 01dfd2f3106dd6605cd9055c306493e29fd7029c /lib/puppet | |
| parent | fdfe0a387d95045d442b945d54a6b757b9581e2e (diff) | |
Adding support for a "mailalias" type, with /etc/aliases support initially. I have not yet figured out how to best rebuild the aliases file when necessary.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2676 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
| -rw-r--r-- | lib/puppet/metatype/attributes.rb | 20 | ||||
| -rwxr-xr-x | lib/puppet/provider/mailalias/aliases.rb | 31 | ||||
| -rwxr-xr-x | lib/puppet/type/mailalias.rb | 50 |
3 files changed, 88 insertions, 13 deletions
diff --git a/lib/puppet/metatype/attributes.rb b/lib/puppet/metatype/attributes.rb index 4ba3588a1..189768090 100644 --- a/lib/puppet/metatype/attributes.rb +++ b/lib/puppet/metatype/attributes.rb @@ -295,13 +295,16 @@ class Puppet::Type [self.name, name] end + if parent = options[:parent] + options.delete(:parent) + else + parent = Puppet::Property + end + # We have to create our own, new block here because we want to define # an initial :retrieve method, if told to, and then eval the passed # block if available. - prop = genclass(name, - :parent => options[:parent] || Puppet::Property, - :hash => @validproperties - ) do + prop = genclass(name, :parent => parent, :hash => @validproperties, :attributes => options) do # If they've passed a retrieve method, then override the retrieve # method on the class. if options[:retrieve] @@ -322,15 +325,6 @@ class Puppet::Type @properties << prop end - if options[:event] - prop.event = options[:event] - end - - # Grr. - if options[:required_features] - prop.required_features = options[:required_features] - end - # define_method(name) do # @parameters[name].should # end diff --git a/lib/puppet/provider/mailalias/aliases.rb b/lib/puppet/provider/mailalias/aliases.rb new file mode 100755 index 000000000..e3bf2c59f --- /dev/null +++ b/lib/puppet/provider/mailalias/aliases.rb @@ -0,0 +1,31 @@ +require 'puppet/provider/parsedfile' + +Puppet::Type.type(:mailalias).provide(:aliases, + :parent => Puppet::Provider::ParsedFile, + :default_target => "/etc/aliases", + :filetype => :flat +) do + text_line :comment, :match => /^#/ + text_line :blank, :match => /^\s*$/ + + record_line :aliases, :fields => %w{name recipient}, :separator => /\s*:\s*/, :block_eval => :instance do + def post_parse(record) + record[:recipient] = record[:recipient].split(/\s*,\s*/).collect { |d| d.gsub(/^['"]|['"]$/, '') } + record + end + + def to_line(record) + dest = record[:recipient].collect do |d| + # Quote aliases that have non-alpha chars + if d =~ /[^-\w@.]/ + '"%s"' % d + else + d + end + end.join(",") + return "%s: %s" % [record[:name], dest] + end + end +end + +# $Id$ diff --git a/lib/puppet/type/mailalias.rb b/lib/puppet/type/mailalias.rb new file mode 100755 index 000000000..79dfe42cc --- /dev/null +++ b/lib/puppet/type/mailalias.rb @@ -0,0 +1,50 @@ +module Puppet + newtype(:mailalias) do + @doc = "Creates an email alias in the local alias database." + + ensurable + + newparam(:name, :namevar => true) do + desc "The alias name." + end + + newproperty(:recipient, :array_matching => :all) do + desc "Where email should should be sent. Multiple values + should be specified as an array." + + def is_to_s(value) + if value.include?(:absent) + super + else + value.join(",") + end + end + + def should + @should + end + + def should_to_s(value) + if value.include?(:absent) + super + else + value.join(",") + end + end + end + + newproperty(:target) do + desc "The file in which to store the aliases. Only used by + those providers that write to disk (i.e., not NetInfo)." + + defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) + @resource.class.defaultprovider.default_target + else + nil + end + } + end + end +end + +# $Id$ |
