Sha256: 89907062018f76cac9560fc06654a2a7c8e7da37efa63e42269e533184418af3

Contents?: true

Size: 1.19 KB

Versions: 233

Compression:

Stored size: 1.19 KB

Contents

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)
      if record[:recipient]
	record[:recipient] = record[:recipient].split(/\s*,\s*/).collect { |d| d.gsub(/^['"]|['"]$/, '') }
      end
      record
    end

    def process(line)
      ret = {}
      records = line.split(':',4)
      ret[:name] = records[0].strip
      if records.length == 4 and records[2].strip == 'include'
	ret[:file] = records[3].strip
      else
	records = line.split(':',2)
	ret[:recipient] = records[1].strip
      end
      ret
    end

    def to_line(record)
      if record[:recipient]
	dest = record[:recipient].collect do |d|
	  # Quote aliases that have non-alpha chars
	  if d =~ /[^-+\w@.]/
	    '"%s"' % d
	  else
	    d
	  end
	end.join(",")
	"#{record[:name]}: #{dest}"
      elsif record[:file]
	"#{record[:name]}: :include: #{record[:file]}"
      end
    end
  end
end

Version data entries

233 entries across 233 versions & 3 rubygems

Version Path
puppet-5.5.18 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.18-x86-mingw32 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.18-x64-mingw32 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.18-universal-darwin lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.17-x86-mingw32 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.17 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.17-x64-mingw32 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.17-universal-darwin lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.16 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.16-x86-mingw32 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.16-x64-mingw32 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.16-universal-darwin lib/puppet/provider/mailalias/aliases.rb
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/provider/mailalias/aliases.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.14 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.14-x86-mingw32 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.14-x64-mingw32 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.14-universal-darwin lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.13 lib/puppet/provider/mailalias/aliases.rb
puppet-5.5.13-x86-mingw32 lib/puppet/provider/mailalias/aliases.rb