public
Description: Server automation framework and application
Homepage: http://reductivelabs.com/trac/puppet/
Clone URL: git://github.com/lak/puppet.git
Click here to lend your support to: puppet and make a donation at www.pledgie.com !
100644 50 lines (43 sloc) 1.501 kb
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
45
46
47
48
49
50
require 'puppet/provider/parsedfile'
 
Puppet::Type.type(:ssh_authorized_key).provide(:parsed,
    :parent => Puppet::Provider::ParsedFile,
    :filetype => :flat,
    :default_target => ''
) do
    desc "Parse and generate authorized_keys files for SSH."
 
    text_line :comment, :match => /^#/
    text_line :blank, :match => /^\s+/
 
    record_line :parsed,
        :fields => %w{options type key name},
        :optional => %w{options},
        :rts => /^\s+/,
        :match => /^(?:([^ ]+) )?(ssh-dss|ssh-rsa) ([^ ]+)(?: (.+))?$/,
        :post_parse => proc { |record|
            if record[:options].nil?
                record[:options] = [:absent]
            else
                record[:options] = record[:options].split(',')
            end
        },
        :pre_gen => proc { |record|
            if record[:options].include?(:absent)
                record[:options] = ""
            else
                record[:options] = record[:options].join(',')
            end
        }
 
    def prefetch
        if not @resource.should(:target)
            #
            # Set default target when user is given
            if val = @resource.should(:user)
                target = File.expand_path("~%s/.ssh/authorized_keys" % val)
                Puppet::debug("Setting target to %s" % target)
                @resource[:target] = target
            else
                raise Puppet::Error, "Missing attribute 'user' or 'target'"
            end
        end
 
        super
    end
end