blob: 388fd631cec140ca5fb3c2f6b1dca8275604490b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
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)
# LAK:NOTE See http://snurl.com/21zf8 [groups_google_com]
# It's not sufficient to assign to an existing hash.
recipient = record[:recipient].split(/\s*,\s*/).collect { |d| d.gsub(/^['"]|['"]$/, '') }
record[:recipient] = recipient
record
end
def process(line)
ret = {}
records = line.split(':',2)
ret[:name] = records[0].strip
ret[:recipient] = records[1].strip
ret
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(",")
"#{record[:name]}: #{dest}"
end
end
end
|