summaryrefslogtreecommitdiffstats
path: root/lib/puppet/type/sshkey.rb
blob: c9e8f3d8b8b929b6e47198dea4a2cad874077449 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module Puppet
    newtype(:sshkey) do
        @doc = "Installs and manages ssh host keys.  At this point, this type
            only knows how to install keys into /etc/ssh/ssh_known_hosts, and
            it cannot manage user authorized keys yet."

        ensurable

        newproperty(:type) do
            desc "The encryption type used.  Probably ssh-dss or ssh-rsa."

            newvalue("ssh-dss")
            newvalue("ssh-rsa")
            aliasvalue(:dsa, "ssh-dss")
            aliasvalue(:rsa, "ssh-rsa")
        end

        newproperty(:key) do
            desc "The key itself; generally a long string of hex digits."
        end

        # FIXME This should automagically check for aliases to the hosts, just
        # to see if we can automatically glean any aliases.
        newproperty(:alias) do
            desc "Any alias the host might have.  Multiple values must be
                specified as an array.  Note that this parameter has the same name
                as one of the metaparams; using this parameter to set aliases will
                make those aliases available in your Puppet scripts."

            attr_accessor :meta

            def insync?(is)
                is == @should
            end
            # We actually want to return the whole array here, not just the first
            # value.
            def should
                if defined? @should
                    return @should
                else
                    return nil
                end
            end

            validate do |value|
                if value =~ /\s/
                    raise Puppet::Error, "Aliases cannot include whitespace"
                end
                if value =~ /,/
                    raise Puppet::Error, "Aliases cannot include whitespace"
                end
            end
        end

        newparam(:name) do
            desc "The host name that the key is associated with."

            isnamevar
        end

        newproperty(:target) do
            desc "The file in which to store the ssh key.  Only used by
                the ``parsed`` provider."

            defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
                    @resource.class.defaultprovider.default_target
                else
                    nil
                end
            }
        end
    end
end